strlist *denymime;
char* boundary=NULL;
int deny = 0;
- int result;
+ int result, ctrlfd;
off_t unwantedmime_hdr_pos = 0;
+ char *dir;
+
+ xasprintf(&dir, "%s/control", listdir);
+ ctrlfd = open(dir, O_RDONLY|O_CLOEXEC);
/* get list control values */
- delmime = ctrlvalues(listdir, "mimestrip");
- denymime = ctrlvalues(listdir, "mimedeny");
+ delmime = ctrlvalues(ctrlfd, "mimestrip");
+ denymime = ctrlvalues(ctrlfd, "mimedeny");
/* read mail header */
result = read_hdrs(infd, &hdrs,delmime,denymime,&deny,&boundary);
-/* Copyright (C) 2004 Mads Martin Joergensen <mmj at mmj.dk>
- *
- * $Id$
+/*
+ * Copyright (C) 2004 Mads Martin Joergensen <mmj at mmj.dk>
+ * Copyright (C) 2023 Baptiste Daroussin <bapt@FreeBSD.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
#include "mlmmj.h"
-strlist *ctrlvalues(const char *listdir, const char *ctrlstr);
+strlist *ctrlvalues(int ctrlfd, const char *ctrlstr);
#endif /* CTRLVALUES_H */
-/* Copyright (C) 2004 Mads Martin Joergensen <mmj at mmj.dk>
- *
- * $Id$
+/*
+ * Copyright (C) 2004 Mads Martin Joergensen <mmj at mmj.dk>
+ * Copyright (C) 2023 Baptiste Daroussin <bapt@FreeBSD.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* IN THE SOFTWARE.
*/
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdlib.h>
#include <fcntl.h>
-#include <unistd.h>
#include "xmalloc.h"
-#include "strgen.h"
#include "ctrlvalues.h"
-#include "mygetline.h"
#include "chomp.h"
#include "mlmmj.h"
-strlist *ctrlvalues(const char *listdir, const char *ctrlstr)
+strlist *ctrlvalues(int ctrlfd, const char *ctrlstr)
{
- char *filename = concatstr(3, listdir, "/control/", ctrlstr);
- char *value;
- int ctrlfd;
+ char *line = NULL;
+ size_t linecap = 0;
+ FILE *f;
+ int fd;
strlist *ret;
- ctrlfd = open(filename, O_RDONLY);
- free(filename);
+ fd = openat(ctrlfd, ctrlstr, O_RDONLY|O_CLOEXEC);
+ if (fd == -1 || (f = fdopen(fd, "r")) == NULL)
+ return (NULL);
- if(ctrlfd < 0)
- return NULL;
-
ret = xcalloc(1, sizeof(*ret));
- while((value = mygetline(ctrlfd)) != NULL) {
- chomp(value);
+ while (getline(&line, &linecap, f) > 0) {
+ chomp(line);
/* Ignore empty lines */
- if (*value == '\0')
+ if (*line == '\0')
continue;
- tll_push_back(*ret, value);
+ tll_push_back(*ret, xstrdup(line));
}
-
- close(ctrlfd);
+ free(line);
+ fclose(f);
return ret;
}
if(statctrl(ctrlfd, "nolistsubsemail"))
return -1;
const char *owner = NULL;
- owners = ctrlvalues(listdir, "owner");
+ owners = ctrlvalues(ctrlfd, "owner");
if (owners != NULL) {
tll_foreach(*owners, it) {
if(strcasecmp(tll_front(*fromemails),
footfd = open(footerfilename, O_RDONLY);
free(footerfilename);
- delheaders = ctrlvalues(listdir, "delheaders");
+ delheaders = ctrlvalues(ctrlfd, "delheaders");
if(delheaders == NULL)
delheaders = xcalloc(1, sizeof(*delheaders));
listdelim = getlistdelim(ctrlfd);
}
if(addrtocc || findaddress) {
- listaddrs = ctrlvalues(listdir, "listaddress");
+ listaddrs = ctrlvalues(ctrlfd, "listaddress");
tll_foreach(dtemails, it) {
tll_foreach(*listaddrs, la) {
if(addrmatch(la->item, it->item,
posteraddr, "-F", fromaddr, "-m", queuefilename, NULL);
}
- access_rules = ctrlvalues(listdir, "access");
+ access_rules = ctrlvalues(ctrlfd, "access");
if (access_rules != NULL) {
enum action accret;
/* Don't send a mail about denial to the list, but silently
}
}
- list_rules = ctrlvalues(listdir, "send");
+ list_rules = ctrlvalues(ctrlfd, "send");
if (list_rules != NULL) {
tll_foreach(*list_rules, lr) {
if (strcasecmp(posteraddr, lr->item) == 0) {
free(str);
- submods = ctrlvalues(listdir, "submod");
+ submods = ctrlvalues(ctrlfd, "submod");
mods = concatstr(2, listdir, "/control/submod");
/* check to see if there's adresses in the submod control file */
tll_foreach(*submods, it)
/* free the submods struct from above */
tll_free_and_free(*submods, free);
free(submods);
- submods = ctrlvalues(listdir, "owner");
+ submods = ctrlvalues(ctrlfd, "owner");
free(mods);
mods = concatstr(2, listdir, "/control/owner");
}