From: Baptiste Daroussin Date: Tue, 27 Dec 2022 09:13:58 +0000 (+0100) Subject: add is_subbedat which deals with file descriptors X-Git-Tag: RELEASE_1_4_0_a2~65 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=afb8eeeb47e8a3da65dc5dbe73daa605ad57ccd2;p=thirdparty%2Fmlmmj.git add is_subbedat which deals with file descriptors --- diff --git a/include/subscriberfuncs.h b/include/subscriberfuncs.h index 36a1331c..4e925080 100644 --- a/include/subscriberfuncs.h +++ b/include/subscriberfuncs.h @@ -28,6 +28,7 @@ off_t find_subscriber(int fd, const char *address); int is_subbed_in(int fd, const char *subddirname, const char *address); +enum subtype is_subbedat(int fd, const char *address, bool both); enum subtype is_subbed(const char *listdir, const char *address, bool both); #endif /* SUBSCRIBERFUNC_H */ diff --git a/src/subscriberfuncs.c b/src/subscriberfuncs.c index 8b2499ca..a6651de9 100644 --- a/src/subscriberfuncs.c +++ b/src/subscriberfuncs.c @@ -150,31 +150,39 @@ is_subbed_in(int dirfd, const char *subdirname, const char *address) } enum subtype -is_subbed(const char *listdir, const char *address, bool both) +is_subbedat(int listfd, const char *address, bool both) { enum subtype typesub = SUB_NONE; - int fd, dirfd; + int fd; - dirfd = open(listdir, O_DIRECTORY); - if (dirfd == -1) { - log_error(LOG_ARGS, "Could not opendir()"); - exit(EXIT_FAILURE); - } - fd = openat(dirfd, "subscribers.d", O_DIRECTORY); + fd = openat(listfd, "subscribers.d", O_DIRECTORY); if (fd != -1 && is_subbed_in(fd, "subscribers.d", address)) { if (!both) return SUB_NORMAL; typesub = SUB_NORMAL; } - fd = openat(dirfd, "digesters.d", O_DIRECTORY); + fd = openat(listfd, "digesters.d", O_DIRECTORY); if (fd != -1 && is_subbed_in(fd, "digesters.d", address)) { if (typesub == SUB_NORMAL) return SUB_BOTH; return SUB_DIGEST; } - fd = openat(dirfd, "nomailsubs.d", O_DIRECTORY); + fd = openat(listfd, "nomailsubs.d", O_DIRECTORY); if (fd != -1 && is_subbed_in(fd, "nomailsubs.d", address)) return SUB_NOMAIL; - return typesub; + return (typesub); +} + +enum subtype +is_subbed(const char *listdir, const char *address, bool both) +{ + int dirfd; + + dirfd = open(listdir, O_DIRECTORY); + if (dirfd == -1) { + log_error(LOG_ARGS, "Could not opendir()"); + exit(EXIT_FAILURE); + } + return (is_subbedat(dirfd, address, both)); }