From 33b8128b186539d3e8cf461b6ec8da5336112063 Mon Sep 17 00:00:00 2001 From: Erwan MAS Date: Fri, 30 May 2025 13:40:33 -0400 Subject: [PATCH] - fix build issues on Linux/Hurd 386 - unit test tests/mlmmj:smtp was incorrect because write_dot send 2 lines --- src/mlmmj-list.c | 8 ++++++++ src/mlmmj-maintd.c | 4 ++-- src/mlmmj-send.c | 2 +- src/mlmmj.c | 2 +- src/send_list.c | 2 +- src/subscriberfuncs.c | 6 +++--- tests/mlmmj.c | 5 ++++- 7 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/mlmmj-list.c b/src/mlmmj-list.c index e2a76845..eca2ec9e 100644 --- a/src/mlmmj-list.c +++ b/src/mlmmj-list.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "mlmmj.h" #include "chomp.h" @@ -54,11 +55,18 @@ dumpcount(int fd, size_t *count) FILE *f; char *line = NULL; size_t linecap = 0; + struct stat fst; f = fdopen(fd, "r"); if (f == NULL) return (-1); + if (fstat(fd, &fst) == 0) { + if (S_ISDIR(fst.st_mode)) { + return(-1); + } + } + while (getline(&line, &linecap, f) > 0) { chomp(line); if (count) diff --git a/src/mlmmj-maintd.c b/src/mlmmj-maintd.c index 96d14693..62317a0b 100644 --- a/src/mlmmj-maintd.c +++ b/src/mlmmj-maintd.c @@ -50,7 +50,7 @@ #define log(...) dprintf(logfd, __VA_ARGS__); #define opendirat(_dirfd, _fd, _dirent, _path) \ do { \ - _fd = openat(_dirfd, _path, O_DIRECTORY|O_CLOEXEC); \ + _fd = openat(_dirfd, _path, O_DIRECTORY|O_CLOEXEC|O_RDONLY); \ if (_fd == -1 || (_dirent = fdopendir(_fd)) == NULL) { \ log(" - Could not open '%s': %s\n", _path, \ strerror(errno)); \ @@ -792,7 +792,7 @@ int main(int argc, char **argv) goto mainsleep; } - int dfd = open(dirlists, O_DIRECTORY); + int dfd = open(dirlists, O_DIRECTORY|O_RDONLY); if (dfd == -1 || (dirp = fdopendir(dfd)) == NULL) { log_err("Could not open the directory containing " "mailing lists (%s): %s", dirlists, diff --git a/src/mlmmj-send.c b/src/mlmmj-send.c index e8a1007b..3aa4ccf8 100644 --- a/src/mlmmj-send.c +++ b/src/mlmmj-send.c @@ -485,7 +485,7 @@ int main(int argc, char **argv) } else { subddirname = "digesters.d"; } - subdirfd = openat(ml.fd, subddirname, O_DIRECTORY|O_CLOEXEC); + subdirfd = openat(ml.fd, subddirname, O_DIRECTORY|O_CLOEXEC|O_RDONLY); if (subdirfd == -1 || (subddir = fdopendir(subdirfd)) == NULL) { log_error(LOG_ARGS, "Could not opendir(%s/%s)", ml.dir, subddirname); diff --git a/src/mlmmj.c b/src/mlmmj.c index aa2cc275..eb158c60 100644 --- a/src/mlmmj.c +++ b/src/mlmmj.c @@ -272,7 +272,7 @@ open_subscriber_directory(int listfd, enum subtype typesub, const char **subdir) *subdir = dir; if (dir == NULL) return (-1); - return (openat(listfd, dir, O_DIRECTORY|O_CLOEXEC)); + return (openat(listfd, dir, O_DIRECTORY|O_CLOEXEC|O_RDONLY)); } bool diff --git a/src/send_list.c b/src/send_list.c index 6b39f0ea..ababcd86 100644 --- a/src/send_list.c +++ b/src/send_list.c @@ -68,7 +68,7 @@ void rewind_subs_list(void *state) struct subs_list_state *s = (struct subs_list_state *)state; if (s == NULL) return; if (s->dirp != NULL) closedir(s->dirp); - s->dfd = openat(s->listfd, s->dirname, O_DIRECTORY|O_CLOEXEC); + s->dfd = openat(s->listfd, s->dirname, O_DIRECTORY|O_CLOEXEC|O_RDONLY); if (s->dfd == -1 || (s->dirp = fdopendir(s->dfd)) == NULL) log_error(LOG_ARGS, "Could not opendir(%s);\n", s->dirname); s->used = true; diff --git a/src/subscriberfuncs.c b/src/subscriberfuncs.c index 60b9cd6d..8b9072ae 100644 --- a/src/subscriberfuncs.c +++ b/src/subscriberfuncs.c @@ -136,19 +136,19 @@ is_subbed(int listfd, const char *address, bool both) enum subtype typesub = SUB_NONE; int fd; - fd = openat(listfd, "subscribers.d", O_DIRECTORY); + fd = openat(listfd, "subscribers.d", O_DIRECTORY|O_RDONLY); if (fd != -1 && is_subbed_in(fd, "subscribers.d", address)) { if (!both) return SUB_NORMAL; typesub = SUB_NORMAL; } - fd = openat(listfd, "digesters.d", O_DIRECTORY); + fd = openat(listfd, "digesters.d", O_DIRECTORY|O_RDONLY); if (fd != -1 && is_subbed_in(fd, "digesters.d", address)) { if (typesub == SUB_NORMAL) return SUB_BOTH; return SUB_DIGEST; } - fd = openat(listfd, "nomailsubs.d", O_DIRECTORY); + fd = openat(listfd, "nomailsubs.d", O_DIRECTORY|O_RDONLY); if (fd != -1 && is_subbed_in(fd, "nomailsubs.d", address)) return SUB_NOMAIL; diff --git a/tests/mlmmj.c b/tests/mlmmj.c index 0444f2f5..1cb59bf0 100644 --- a/tests/mlmmj.c +++ b/tests/mlmmj.c @@ -956,6 +956,7 @@ ATF_TC_BODY(smtp, tc) "250 2.1.0 Ok\n", /* MAIL FROM */ "250 2.1.0 Ok\n", /* RCPT TO */ "354 Send message content; end with .\n", /* DATA */ + NULL, /* BEFORE DOT */ "250 2.1.0 Ok\n", /* DATA */ "221 2.0.0 Bye\n", /* QUIT */ "250 2.0.0 Ok\n", /* RSET */ @@ -963,7 +964,9 @@ ATF_TC_BODY(smtp, tc) dprintf(smtppipe[0], "220 me fake smtp\n"); for (uint8_t i = 0; i < NELEM(replies); i++) { atf_utils_readline(smtppipe[0]); - dprintf(smtppipe[0], "%s", replies[i]); + if ( replies[i] != NULL ) { + dprintf(smtppipe[0], "%s", replies[i]); + } } exit (0); } -- 2.47.2