#ifndef GETLISTADDR_H
#define GETLISTADDR_H
-char *getlistaddr(const char *listdir);
-char *fgetlistaddr(int fd);
+char *getlistaddr(int fd);
#endif /* GETLISTADDR_H */
#ifndef GETLISTDELIM_H
#define GETLISTDELIM_H
-char *getlistdelim(const char *listdir);
-char *fgetlistdelim(int ctrlfd);
+char *getlistdelim(int ctrlfd);
#endif /* GETLISTDELIM_H */
#define SEND_HELP_H
void send_help(const char *listdir, const char *queuefilename,
- const char *emailaddr, const char *mlmmjsend);
+ const char *emailaddr, const char *mlmmjsend, int ctrlfd);
#endif
int initsmtp(int *sockfd, const char *relayhost, unsigned short port, const char *heloname);
int endsmtp(int *sockfd);
-int send_mail(int sockfd, struct mail *mail, int listfd, bool bounce);
-int do_bouncemail(int listfd, const char *from);
+int send_mail(int sockfd, struct mail *mail, int listfd, int ctrlfd, bool bounce);
+int do_bouncemail(int listfd, int ctrlfd, const char *from);
#include <errno.h>
#include "getlistaddr.h"
-#include "chomp.h"
#include "log_error.h"
-#include "mygetline.h"
-#include "strgen.h"
+#include "ctrlvalue.h"
char *
-fgetlistaddr(int fd)
+getlistaddr(int fd)
{
- char *tmpstr;
- int listnamefd;
-
- if ((listnamefd = openat(fd, "listaddress", O_RDONLY|O_CLOEXEC)) < 0) {
- log_error(LOG_ARGS, "Could not open 'control/listaddress'");
- exit(EXIT_FAILURE);
- }
- tmpstr = mygetline(listnamefd);
- if (tmpstr == NULL) {
+ char *listaddr = ctrlvalue(fd, "listaddress");
+ if (listaddr == NULL) {
log_error(LOG_ARGS, "FATAL. Could not get listaddress "
"in control/listaddress");
exit(EXIT_FAILURE);
}
- if (strchr(tmpstr, '@') == NULL) {
+ if (strchr(listaddr, '@') == NULL) {
log_error(LOG_ARGS, "FATAL. No @ sign in listaddress");
exit(EXIT_FAILURE);
}
- chomp(tmpstr);
- close(listnamefd);
-
- return (tmpstr);
-}
-
-char *getlistaddr(const char *listdir)
-{
- char *tmpstr;
- int listnamefd;
-
- tmpstr = concatstr(2, listdir, "/control/listaddress");;
- if((listnamefd = open(tmpstr, O_RDONLY)) < 0) {
- log_error(LOG_ARGS, "Could not open '%s'", tmpstr);
- exit(EXIT_FAILURE);
- }
- free(tmpstr);
-
- tmpstr = mygetline(listnamefd);
-
- if(tmpstr == NULL){
- log_error(LOG_ARGS, "FATAL. Could not get listaddress "
- "in %s/control/listaddress", listdir);
- exit(EXIT_FAILURE);
- }
-
- if(strchr(tmpstr, '@') == NULL) {
- log_error(LOG_ARGS, "FATAL. No @ sign in listaddress");
- exit(EXIT_FAILURE);
- }
-
- chomp(tmpstr);
- close(listnamefd);
-
- return tmpstr;
+ return (listaddr);
}
#include "log_error.h"
#include "mygetline.h"
#include "strgen.h"
+#include "ctrlvalue.h"
-char *fgetlistdelim(int ctrlfd)
+char *getlistdelim(int ctrlfd)
{
char *delimstr;
- int delimfd;
- delimfd = openat(ctrlfd, "delimiter", O_RDONLY|O_CLOEXEC);
- if (delimfd == -1)
+ delimstr = ctrlvalue(ctrlfd, "delimiter");
+ if (delimstr == NULL)
return (xstrdup(DEFAULT_RECIPDELIM));
- delimstr = mygetline(delimfd);
- close(delimfd);
-
- if(NULL == delimstr){
- log_error(LOG_ARGS, "FATAL. Could not get list delimiter from "
- "control/delimiter");
- exit(EXIT_FAILURE);
- }
- chomp(delimstr);
-
- if(0 == strlen(delimstr)){
- log_error(LOG_ARGS, "FATAL. Zero-length delimiter found from "
- "control/delimiter");
- exit(EXIT_FAILURE);
- }
-
return (delimstr);
}
-
-char *getlistdelim(const char *listdir)
-{
- char *delimfn, *delimstr;
- int delimfd;
-
- delimfn = concatstr(2, listdir, "/control/delimiter");
- if(-1 != (delimfd = open(delimfn, O_RDONLY))){
- delimstr = mygetline(delimfd);
- close(delimfd);
-
- if(NULL == delimstr){
- log_error(LOG_ARGS,
- "FATAL. Could not get list delimiter from %s",
- delimfn);
- free(delimfn);
- exit(EXIT_FAILURE);
- }
-
- chomp(delimstr);
-
- if(0 == strlen(delimstr)){
- log_error(LOG_ARGS,
- "FATAL. Zero-length delimiter found from %s",
- delimfn);
- free(delimfn);
- exit(EXIT_FAILURE);
- }
- } else
- delimstr = xstrdup(DEFAULT_RECIPDELIM);
-
- free(delimfn);
-
- return delimstr;
-}
MY_ASSERT(queuefilename);
close_text(txt);
send_help(listdir, queuefilename,
- fromemails->emaillist[0], mlmmjsend);
+ fromemails->emaillist[0], mlmmjsend, ctrlfd);
return -1;
}
log_oper(listdir, OPLOGFNAME, "mlmmj-sub: request for digest"
MY_ASSERT(queuefilename);
close_text(txt);
send_help(listdir, queuefilename,
- fromemails->emaillist[0], mlmmjsend);
+ fromemails->emaillist[0], mlmmjsend, ctrlfd);
return -1;
}
log_oper(listdir, OPLOGFNAME, "mlmmj-sub: request for nomail"
MY_ASSERT(queuefilename);
close_text(txt);
send_help(listdir, queuefilename,
- fromemails->emaillist[0], mlmmjsend);
+ fromemails->emaillist[0], mlmmjsend, ctrlfd);
return -1;
}
log_oper(listdir, OPLOGFNAME, "mlmmj-sub: request for both"
MY_ASSERT(queuefilename);
close_text(txt);
send_help(listdir, queuefilename,
- fromemails->emaillist[0], mlmmjsend);
+ fromemails->emaillist[0], mlmmjsend, ctrlfd);
break;
/* listname+faq@domain.tld */
MY_ASSERT(queuefilename);
close_text(txt);
send_help(listdir, queuefilename,
- fromemails->emaillist[0], mlmmjsend);
+ fromemails->emaillist[0], mlmmjsend, ctrlfd);
break;
/* listname+get-INDEX@domain.tld */
text *txt;
file_lines_state *fls;
char *myaddr, *from, *a, *queuefilename, *listaddr;
- char *listfqdn, *listname, *probefile, *listdelim=getlistdelim(listdir);
+ char *listfqdn, *listname, *probefile, *listdelim = getlistdelim(ctrlfd);
int fd;
time_t t;
myaddr = xstrdup(addr);
- listaddr = getlistaddr(listdir);
+ listaddr = getlistaddr(ctrlfd);
listname = genlistname(listaddr);
listfqdn = genlistfqdn(listaddr);
enum modreason modreason, int ctrlfd)
{
char *from, *listfqdn, *listname, *moderators = NULL;
- char *replyto, *listaddr = getlistaddr(listdir), *listdelim;
+ char *replyto, *listaddr = getlistaddr(ctrlfd), *listdelim;
text *txt;
memory_lines_state *mls;
char *queuefilename = NULL;
free(moderators);
- listdelim = getlistdelim(listdir);
+ listdelim = getlistdelim(ctrlfd);
replyto = concatstr(6, listname, listdelim, "release-", mailbasename,
"@", listfqdn);
reject = concatstr(6, listname, listdelim, "reject-", mailbasename,
recipextra = xstrdup(envstr);
} else if((envstr = getenv("LOCAL_PART_SUFFIX")) != NULL) {
/* exim */
- listdelim = getlistdelim(listdir);
+ listdelim = getlistdelim(ctrlfd);
if (strncmp(envstr, listdelim, strlen(listdelim)) == 0) {
recipextra = xstrdup(envstr + strlen(listdelim));
} else {
addrtocc = !statctrl(ctrlfd, "tocc");
if (findaddress) {
- listdelim = getlistdelim(listdir);
+ listdelim = getlistdelim(ctrlfd);
}
if(addrtocc || findaddress) {
listaddrs = ctrlvalues(listdir, "listaddress");
return EXIT_SUCCESS;
}
- listaddr = getlistaddr(listdir);
+ listaddr = getlistaddr(ctrlfd);
/* checking incoming mail's size */
maxmailsize = ctrlsizet(ctrlfd, "maxmailsize", 0);
exit(EXIT_SUCCESS);
}
- listdelim = getlistdelim(listdir);
+ listdelim = getlistdelim(ctrlfd);
listname = genlistname(listaddr);
listfqdn = genlistfqdn(listaddr);
fromaddr = concatstr(4, listname, listdelim,
free(donemailname);
exit(EXIT_SUCCESS);
}
- listdelim = getlistdelim(listdir);
+ listdelim = getlistdelim(ctrlfd);
listname = genlistname(listaddr);
listfqdn = genlistfqdn(listaddr);
fromaddr = concatstr(4, listname, listdelim, "bounces-help@",
free(donemailname);
exit(EXIT_SUCCESS);
}
- listdelim = getlistdelim(listdir);
+ listdelim = getlistdelim(ctrlfd);
listname = genlistname(listaddr);
listfqdn = genlistfqdn(listaddr);
fromaddr = concatstr(4, listname, listdelim,
free(donemailname);
exit(EXIT_SUCCESS);
}
- listdelim = getlistdelim(listdir);
+ listdelim = getlistdelim(ctrlfd);
listname = genlistname(listaddr);
listfqdn = genlistfqdn(listaddr);
fromaddr = concatstr(4, listname, listdelim,
archivefilename, ctrlfd);
mail->from = bounceaddr;
}
- res = send_mail(sockfd, mail, listfd, bounceaddr != NULL);
+ res = send_mail(sockfd, mail, listfd, ctrlfd, bounceaddr != NULL);
free(bounceaddr);
if(res && listaddr && archivefilename) {
/* we failed, so save the addresses and bail */
stl.count = 0;
if(listdir && listctrl != '5')
- listaddr = fgetlistaddr(listfd);
+ listaddr = getlistaddr(ctrlfd);
/* initialize file with mail to send */
}
if(listdir)
- listdelim = fgetlistdelim(listfd);
+ listdelim = getlistdelim(ctrlfd);
switch(listctrl) {
case '1': /* A single mail is to be sent, do nothing */
case '6':
initsmtp(&sockfd, relayhost, smtpport, smtphelo);
mail.from = bounceaddr;
- if(send_mail(sockfd, &mail,listfd, false)) {
+ if(send_mail(sockfd, &mail,listfd, ctrlfd, false)) {
close(sockfd);
sockfd = -1;
/* error, so keep it in the queue */
case '5': /* bounceprobe - handle relayhost local users bouncing*/
initsmtp(&sockfd, relayhost, smtpport, smtphelo);
mail.from = bounceaddr;
- if(send_mail(sockfd, &mail, listfd, false)) {
+ if(send_mail(sockfd, &mail, listfd, ctrlfd, false)) {
close(sockfd);
sockfd = -1;
/* error, so remove the probefile */
exit(EXIT_FAILURE);
}
- listdelim = getlistdelim(listdir);
+ listdelim = getlistdelim(ctrlfd);
listname = genlistname(listaddr);
listfqdn = genlistfqdn(listaddr);
xasprintf(&verpfrom, "%s%sbounces-%d@%s", listname, listdelim,
address = lowercase(address);
/* get the list address */
- listaddr = fgetlistaddr(ctrlfd);
+ listaddr = getlistaddr(ctrlfd);
if(strncasecmp(listaddr, address, strlen(listaddr)) == 0)
errx(EXIT_FAILURE, "Cannot subscribe the list address to the list");
}
}
- listdelim = fgetlistdelim(ctrlfd);
+ listdelim = getlistdelim(ctrlfd);
if(subbed == SUB_NONE && subconfirm)
generate_subconfirm(listdir, listaddr, listdelim,
/* Make the address lowercase */
address = lowercase(address);
- listaddr = fgetlistaddr(ctrlfd);
- listdelim = fgetlistdelim(ctrlfd);
+ listaddr = getlistaddr(ctrlfd);
+ listdelim = getlistdelim(ctrlfd);
if(changeuid) {
uid = getuid();
char *str;
char *headers[10] = { NULL }; /* relies on NULL to flag end */
- listaddr = getlistaddr(listdir);
- listdelim = getlistdelim(listdir);
+ listaddr = getlistaddr(ctrlfd);
+ listdelim = getlistdelim(ctrlfd);
listfqdn = genlistfqdn(listaddr);
do {
boundary = random_str();
- listaddr = getlistaddr(listdir);
+ listaddr = getlistaddr(ctrlfd);
listname = genlistname(listaddr);
listfqdn = genlistfqdn(listaddr);
- listdelim = getlistdelim(listdir);
+ listdelim = getlistdelim(ctrlfd);
txt = open_text_file(listdir, "digest");
if (txt == NULL) {
#include "utils.h"
void send_help(const char *listdir, const char *queuefilename,
- const char *emailaddr, const char *mlmmjsend)
+ const char *emailaddr, const char *mlmmjsend, int ctrlfd)
{
char *listaddr, *listdelim, *listname, *listfqdn;
char *fromaddr;
- listaddr = getlistaddr(listdir);
- listdelim = getlistdelim(listdir);
+ listaddr = getlistaddr(ctrlfd);
+ listdelim = getlistdelim(ctrlfd);
listname = genlistname(listaddr);
listfqdn = genlistfqdn(listaddr);
char *fromaddr, *subdir, *nomaildir, *digestdir;
int fd;
- listaddr = getlistaddr(listdir);
- listdelim = getlistdelim(listdir);
+ listaddr = getlistaddr(ctrlfd);
+ listdelim = getlistdelim(ctrlfd);
listname = genlistname(listaddr);
listfqdn = genlistfqdn(listaddr);
return retval;
}
-int do_bouncemail(int listfd, const char *from)
+int do_bouncemail(int listfd, int ctrlfd, const char *from)
{
/* expected format for the from: "something+anything-<number>-anything@anything" */
char *tofree;
char *myfrom = xstrdup(from);
- char *listdelim = fgetlistdelim(listfd);
+ char *listdelim = getlistdelim(ctrlfd);
char *addr, *num, *c;
tofree = myfrom;
}
int
-send_mail(int sockfd, struct mail *mail, int listfd, bool bounce)
+send_mail(int sockfd, struct mail *mail, int listfd, int ctrlfd, bool bounce)
{
int retval = 0;
char *reply, *reply2;
if(bounce && ((reply[0] == '4') || (reply[0] == '5'))
&& (reply[1] == '5')) {
free(reply);
- return do_bouncemail(listfd, mail->from);
+ return do_bouncemail(listfd, ctrlfd, mail->from);
} else {
log_error(LOG_ARGS, "Error in RCPT TO. Reply = [%s]",
reply);
{
init_ml(true);
int lfd = open("list", O_DIRECTORY);
+ int ctrlfd = openat(lfd, "control", O_DIRECTORY);
/* malformed */
- ATF_REQUIRE_EQ(do_bouncemail(lfd, "plop"), 0);
+ ATF_REQUIRE_EQ(do_bouncemail(lfd, ctrlfd, "plop"), 0);
/* malformed, missing number */
- ATF_REQUIRE_EQ(do_bouncemail(lfd, "plop@meh"), 0);
+ ATF_REQUIRE_EQ(do_bouncemail(lfd, ctrlfd, "plop@meh"), 0);
/* malformed, empty numbr */
- ATF_REQUIRE_EQ(do_bouncemail(lfd, "plop-@meh"), 0);
+ ATF_REQUIRE_EQ(do_bouncemail(lfd, ctrlfd, "plop-@meh"), 0);
/* no listdelim */
- ATF_REQUIRE_EQ(do_bouncemail(lfd, "plop-0@meh"), 0);
+ ATF_REQUIRE_EQ(do_bouncemail(lfd, ctrlfd, "plop-0@meh"), 0);
/* listdelim before */
- ATF_REQUIRE_EQ(do_bouncemail(lfd, "plop+-0@meh"), 0);
+ ATF_REQUIRE_EQ(do_bouncemail(lfd, ctrlfd, "plop+-0@meh"), 0);
/* listdelim before */
- ATF_REQUIRE_EQ(do_bouncemail(lfd, "plop-0+@meh"), 0);
+ ATF_REQUIRE_EQ(do_bouncemail(lfd, ctrlfd, "plop-0+@meh"), 0);
/* 2 ticks */
- ATF_REQUIRE_EQ(do_bouncemail(lfd, "plop+--bla@meh"), 1);
+ ATF_REQUIRE_EQ(do_bouncemail(lfd, ctrlfd, "plop+--bla@meh"), 1);
close(lfd);
+ close(ctrlfd);
}
ATF_TC_BODY(send_mail_0, tc)
{
int smtppipe[2];
struct mail mail = {};
- ATF_REQUIRE_EQ(send_mail(-1, NULL, -1, false), EBADF);
+ ATF_REQUIRE_EQ(send_mail(-1, NULL, -1, -1, false), EBADF);
ATF_REQUIRE(pipe(smtppipe) >= 0);
pid_t p = atf_utils_fork();
if (p == 0) {
exit(0);
}
close(smtppipe[0]);
- ATF_REQUIRE_EQ(send_mail(smtppipe[1], &mail, -1, false), 0);
+ ATF_REQUIRE_EQ(send_mail(smtppipe[1], &mail, -1, -1, false), 0);
mail.to = "plop@meh";
- ATF_REQUIRE_EQ(send_mail(smtppipe[1], &mail, -1, false), 0);
+ ATF_REQUIRE_EQ(send_mail(smtppipe[1], &mail, -1, -1, false), 0);
mail.from = "test@meh";
mail.inmem = true;
- ATF_REQUIRE_EQ(send_mail(smtppipe[1], &mail, -1, false), 0);
+ ATF_REQUIRE_EQ(send_mail(smtppipe[1], &mail, -1, -1, false), 0);
mail.hdrs = "plop";
- ATF_REQUIRE_EQ(send_mail(smtppipe[1], &mail, -1, false), 0);
+ ATF_REQUIRE_EQ(send_mail(smtppipe[1], &mail, -1, -1, false), 0);
mail.hdrs = NULL;
mail.body = "body";
- ATF_REQUIRE_EQ(send_mail(smtppipe[1], &mail, -1, false), 0);
+ ATF_REQUIRE_EQ(send_mail(smtppipe[1], &mail, -1, -1, false), 0);
mail.inmem = false;
- ATF_REQUIRE_EQ(send_mail(smtppipe[1], &mail, -1, false), 0);
+ ATF_REQUIRE_EQ(send_mail(smtppipe[1], &mail, -1, -1, false), 0);
mail.size = 1;
- ATF_REQUIRE_EQ(send_mail(smtppipe[1], &mail, -1, false), 0);
+ ATF_REQUIRE_EQ(send_mail(smtppipe[1], &mail, -1, -1, false), 0);
mail.size = 0;
mail.map = "bla";
- ATF_REQUIRE_EQ(send_mail(smtppipe[1], &mail, -1, false), 0);
+ ATF_REQUIRE_EQ(send_mail(smtppipe[1], &mail, -1, -1, false), 0);
mail.inmem = true;
mail.hdrs = "headers";
- ATF_REQUIRE_EQ(send_mail(smtppipe[1], &mail, -1, false), MLMMJ_FROM);
+ ATF_REQUIRE_EQ(send_mail(smtppipe[1], &mail, -1, -1, false), MLMMJ_FROM);
atf_utils_wait(p, 0, "MAIL FROM:<test@meh>\r\nRSET\r\n", "");
}
mail.inmem = true;
mail.hdrs = "headers";
mail.body = "body";
- ATF_REQUIRE_EQ(send_mail(smtppipe[1], &mail, -1, false), MLMMJ_RCPTTO);
+ ATF_REQUIRE_EQ(send_mail(smtppipe[1], &mail, -1, -1, false), MLMMJ_RCPTTO);
atf_utils_wait(p, 0, "MAIL FROM:<test@meh>\r\nRCPT TO:<plop@meh>\r\n", "");
}
mail.inmem = true;
mail.hdrs = "headers";
mail.body = "body";
- ATF_REQUIRE_EQ(send_mail(smtppipe[1], &mail, -1, false), MLMMJ_DATA);
+ ATF_REQUIRE_EQ(send_mail(smtppipe[1], &mail, -1, -1, false), MLMMJ_DATA);
atf_utils_wait(p, 0, "MAIL FROM:<test@meh>\r\nRCPT TO:<plop@meh>\r\nDATA\r\n", "");
}
mail.inmem = true;
mail.hdrs = "headers";
mail.body = "body";
- ATF_REQUIRE_EQ(send_mail(smtppipe[1], &mail, -1, false), MLMMJ_DATA);
+ ATF_REQUIRE_EQ(send_mail(smtppipe[1], &mail, -1, -1, false), MLMMJ_DATA);
atf_utils_wait(p, 0, "MAIL FROM:<test@meh>\r\nRCPT TO:<plop@meh>\r\nDATA\r\n", "");
}
mail.inmem = true;
mail.hdrs = "headers";
mail.body = "body";
- ATF_REQUIRE_EQ(send_mail(smtppipe[1], &mail, -1, false), MLMMJ_DATA);
+ ATF_REQUIRE_EQ(send_mail(smtppipe[1], &mail, -1, -1, false), MLMMJ_DATA);
atf_utils_wait(p, 0, "MAIL FROM:<test@meh>\r\nRCPT TO:<plop@meh>\r\nDATA\r\n", "");
}
mail.inmem = true;
mail.hdrs = "headers\n";
mail.body = "body\n";
- ATF_REQUIRE_EQ(send_mail(smtppipe[1], &mail, -1, false), MLMMJ_DOT);
+ ATF_REQUIRE_EQ(send_mail(smtppipe[1], &mail, -1, -1, false), MLMMJ_DOT);
atf_utils_wait(p, 0, "MAIL FROM:<test@meh>\r\nRCPT TO:<plop@meh>\r\nDATA\r\nheaders\nbody\n\r\n.\r\n", "");
}
mail.hdrs = "headers\n";
mail.body = "body\n";
mail.replyto= "yeah@meh";
- ATF_REQUIRE_EQ(send_mail(smtppipe[1], &mail, -1, false), 0);
+ ATF_REQUIRE_EQ(send_mail(smtppipe[1], &mail, -1, -1, false), 0);
atf_utils_wait(p, 0, "MAIL FROM:<test@meh>\r\nRCPT TO:<plop@meh>\r\nDATA\r\nReply-To: yeah@meh\r\nheaders\nbody\n\r\n.\r\n", "");
}
mail.hdrs = "headers\n";
mail.body = "body\n";
mail.addtohdr = true;
- ATF_REQUIRE_EQ(send_mail(smtppipe[1], &mail, -1, false), 0);
+ ATF_REQUIRE_EQ(send_mail(smtppipe[1], &mail, -1, -1, false), 0);
atf_utils_wait(p, 0, "MAIL FROM:<test@meh>\r\nRCPT TO:<plop@meh>\r\nDATA\r\nheaders\nTo: plop@meh\r\nbody\n\r\n.\r\n", "");
}
mail.size = st.st_size;
mail.map = mmap(0, mail.size, PROT_READ, MAP_SHARED, fd, 0);
mail.addtohdr = true;
- ATF_REQUIRE_EQ(send_mail(smtppipe[1], &mail, -1, false), 0);
+ ATF_REQUIRE_EQ(send_mail(smtppipe[1], &mail, -1, -1, false), 0);
atf_utils_wait(p, 0, "MAIL FROM:<test@meh>\r\nRCPT TO:<plop@meh>\r\nDATA\r\nheaders\r\nTo: plop@meh\r\n\r\nbody\r\n\r\n.\r\n", "");
}