#ifndef SUBSCRIBERFUNC_H
#define SUBSCRIBERFUNC_H
+#include <stdbool.h>
+#include "mlmmj.h"
+
off_t find_subscriber(int fd, const char *address);
-int is_subbed_in(const char *subddirname, const char *address);
-enum subtype is_subbed(const char *listdir, const char *address, int both);
+bool is_subbed_in(int fd, const char *address);
+enum subtype is_subbed(struct mlmmj_list *list, const char *address, int both);
int open_subscriber_directory(struct mlmmj_list *list, enum subtype typesub, const char **subdir);
#endif /* SUBSCRIBERFUNC_H */
}
subonlyget = statctrl(list, "subonlyget");
if(subonlyget) {
- if(is_subbed(list->dir, fromemails->emaillist[0], 0) ==
+ if(is_subbed(list, fromemails->emaillist[0], 0) ==
SUB_NONE) {
errno = 0;
log_error(LOG_ARGS, "A get request was sent"
/* Copyright (C) 2004 Morten K. Poulsen <morten at afdelingp.dk>
-/* Copyright (C) 2021 Baptiste Daroussin <bapt@FreeBSD.org>
+ * Copyright (C) 2021 Baptiste Daroussin <bapt@FreeBSD.org>
*
* $Id$
*
*a = '@';
/* make sure it's a subscribed address */
- if(is_subbed(list.dir, address, 0) == SUB_NONE) {
+ if(is_subbed(&list, address, 0) == SUB_NONE) {
log_error(LOG_ARGS, "%s is bouncing but not subscribed?",
address);
if(mailname)
exit(EXIT_SUCCESS);
}
if(subonlypost) {
- foundaddr = (is_subbed(list.dir, posteraddr, 0) !=
+ foundaddr = (is_subbed(&list, posteraddr, 0) !=
SUB_NONE);
} else if (modonlypost) {
foundaddr = is_moderator(list.dir, posteraddr, NULL);
}
}
- subbed = is_subbed(list.dir, address, 1);
+ subbed = is_subbed(&list, address, 1);
if(subbed == typesub) {
if(!nogensubscribed)
int status;
char *address = NULL;
struct mlmmj_list list;
- char *mlmmjsend, *bindir, *subdir, *subddirname;
+ char *mlmmjsend, *bindir;
char *lowcaseaddr;
enum subtype typesub = SUB_ALL;
enum subreason reasonsub = SUB_ADMIN;
}
if (typesub == SUB_ALL) {
- subbed = is_subbed(list.dir, address, 0) != SUB_NONE;
+ subbed = is_subbed(&list, address, 0) != SUB_NONE;
} else {
- switch(typesub) {
- default:
- case SUB_NORMAL:
- subdir = "/subscribers.d/";
- break;
- case SUB_DIGEST:
- subdir = "/digesters.d/";
- break;
- case SUB_NOMAIL:
- subdir = "/nomailsubs.d/";
- break;
- }
- myasprintf(&subddirname, "%s%s", list.dir, subdir);
- subbed = is_subbed_in(subddirname, address);
- myfree(subddirname);
+ subbed = is_subbed_in(
+ open_subscriber_directory(&list, typesub, NULL), address);
}
if(!subbed) {
return (off_t)-1;
}
-int is_subbed_in(const char *subddirname, const char *address)
+bool
+is_subbed_in(int fd, const char *address)
{
int retval = 0, subread;
- char *subreadname;
off_t suboff;
DIR *subddir;
struct dirent *dp;
- if((subddir = opendir(subddirname)) == NULL) {
- log_error(LOG_ARGS, "Could not opendir(%s)", subddirname);
+ if (fd == -1)
+ return (false);
+
+ if((subddir = fdopendir(fd)) == NULL) {
+ log_error(LOG_ARGS, "Could not opendir()");
exit(EXIT_FAILURE);
}
if(!strcmp(dp->d_name, ".."))
continue;
- subreadname = concatstr(2, subddirname, dp->d_name);
- subread = open(subreadname, O_RDONLY);
+ subread = openat(fd, dp->d_name, O_RDONLY);
if(subread < 0) {
- log_error(LOG_ARGS, "Could not open %s", subreadname);
- myfree(subreadname);
+ log_error(LOG_ARGS, "Could not open %s", dp->d_name);
continue;
}
suboff = find_subscriber(subread, address);
close(subread);
- myfree(subreadname);
if(suboff == -1) {
continue;
return retval;
}
-enum subtype is_subbed(const char *listdir, const char *address, int both)
+enum subtype is_subbed(struct mlmmj_list *list, const char *address, int both)
{
- int retval;
- char *subddirname;
+ int fd;
enum subtype typesub = SUB_NONE;
-
- subddirname = concatstr(2, listdir, "/subscribers.d/");
- retval = is_subbed_in(subddirname, address);
- myfree(subddirname);
- if (retval) {
+
+ fd = openat(list->fd, "subscribers.d", O_DIRECTORY|O_CLOEXEC);
+ if(is_subbed_in(fd, address)) {
if (!both) return SUB_NORMAL;
typesub = SUB_NORMAL;
}
- subddirname = concatstr(2, listdir, "/digesters.d/");
- retval = is_subbed_in(subddirname, address);
- myfree(subddirname);
- if (retval) {
+ fd = openat(list->fd, "digesters.d", O_DIRECTORY|O_CLOEXEC);
+ if (is_subbed_in(fd, address)) {
if (typesub == SUB_NORMAL) return SUB_BOTH;
return SUB_DIGEST;
}
- subddirname = concatstr(2, listdir, "/nomailsubs.d/");
- retval = is_subbed_in(subddirname, address);
- myfree(subddirname);
- if (retval) return SUB_NOMAIL;
+ fd = openat(list->fd, "nomailsubs.d", O_DIRECTORY|O_CLOEXEC);
+ if (is_subbed_in(fd, address))
+ return SUB_NOMAIL;
return typesub;
}