#include <dirent.h>
#include <string.h>
#include <err.h>
+#include <sys/stat.h>
#include "mlmmj.h"
#include "chomp.h"
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)
#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)); \
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,
} 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);
*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
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;
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;
"250 2.1.0 Ok\n", /* MAIL FROM */
"250 2.1.0 Ok\n", /* RCPT TO */
"354 Send message content; end with <CRLF>.<CRLF>\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 */
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);
}