]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
add is_subbedat which deals with file descriptors
authorBaptiste Daroussin <bapt@FreeBSD.org>
Tue, 27 Dec 2022 09:13:58 +0000 (10:13 +0100)
committerBaptiste Daroussin <bapt@FreeBSD.org>
Tue, 27 Dec 2022 09:13:58 +0000 (10:13 +0100)
include/subscriberfuncs.h
src/subscriberfuncs.c

index 36a1331c7a0c8bfc09631097ff541e5d7841e6e4..4e925080c77ad6430415e688d62ee7c9c6302b24 100644 (file)
@@ -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 */
index 8b2499ca46a0351a9d7eb7ee8cf72804af8448aa..a6651de9308e9fa674bab2f62f6b780ac4c723cb 100644 (file)
@@ -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));
 }