From 2b9d328bdb940511fd49caae839579835b18d8bc Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 5 Feb 2013 18:24:50 +0100 Subject: [PATCH] Adding SPP framework for qmail-smtpd qmail-1.03-r17-spp --- qmail-smtpd.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'qmail-smtpd.c') diff --git a/qmail-smtpd.c b/qmail-smtpd.c index 25f821c..4553b42 100644 --- a/qmail-smtpd.c +++ b/qmail-smtpd.c @@ -27,6 +27,9 @@ #include "qregex.h" #include "strerr.h" #include "cdb.h" +#include "qmail-spp.h" + +int spp_val; #define BMCHECK_BMF 0 #define BMCHECK_BMFNR 1 @@ -219,6 +222,7 @@ void setup() if (control_readint(&timeout,"control/timeoutsmtpd") == -1) die_control(); if (timeout <= 0) timeout = 1; if (rcpthosts_init() == -1) die_control(); + if (spp_init() == -1) die_control(); bmfok = control_readfile(&bmf,"control/badmailfrom",0); if (bmfok == -1) die_control(); @@ -439,6 +443,7 @@ int flagbarfbmf; /* defined if seenmail */ int flagbarfbmt; int flagbrt; /* defined if any bad rcpts */ int flagbarfbhelo; +int allowed; int flagsize; stralloc mailfrom = {0}; stralloc rcptto = {0}; @@ -507,6 +512,7 @@ void mailfrom_parms(arg) char *arg; void smtp_helo(arg) char *arg; { + if(!spp_helo(arg)) return; smtp_greet("250 "); out("\r\n"); seenmail = 0; dohelo(arg); if (bhelook) flagbarfbhelo = bmcheck(BMCHECK_BHELO); @@ -526,6 +532,7 @@ void smtp_ehlo(arg) char *arg; #endif char size[FMT_ULONG]; size[fmt_ulong(size,(unsigned int) databytes)] = 0; + if(!spp_helo(arg)) return; smtp_greet("250-"); #ifdef TLS if (!ssl && (stat("control/servercert.pem",&st) == 0)) @@ -543,6 +550,7 @@ void smtp_ehlo(arg) char *arg; } void smtp_rset() { + spp_rset(); seenmail = 0; out("250 flushed\r\n"); } @@ -557,6 +565,7 @@ void smtp_mail(arg) char *arg; if ((!flagbarfbmf) && (bmfnrok) && (addr.len != 1) && (!relayclient)) { flagbarfbmf = bmcheck(BMCHECK_BMFNR); } + if (!(spp_val = spp_mail())) return; seenmail = 1; if (!stralloc_copys(&rcptto,"")) die_nomem(); if (!stralloc_copys(&mailfrom,addr.s)) die_nomem(); @@ -599,17 +608,22 @@ void smtp_rcpt(arg) char *arg; { err_bmt(); return; } + if (!relayclient) allowed = addrallowed(); + else allowed = 1; if (relayclient) { --addr.len; if (!stralloc_cats(&addr,relayclient)) die_nomem(); if (!stralloc_0(&addr)) die_nomem(); } - else - if (!addrallowed()) { err_nogateway(); return; } if (!env_get("RELAYCLIENT") && brtcheck()) { flagbrt = 1; log_deny("BAD RCPT TO", mailfrom.s,addr.s); } + if (!(spp_val = spp_rcpt(allowed))) return; + if (!relayclient && spp_val == 1) { + if (!allowed) { err_nogateway(); return; } + } + spp_rcpt_accepted(); if (!stralloc_cats(&rcptto,"T")) die_nomem(); if (!stralloc_cats(&rcptto,addr.s)) die_nomem(); if (!stralloc_0(&rcptto)) die_nomem(); @@ -732,6 +746,7 @@ void smtp_data() { if (!rcptto.len) { err_wantrcpt(); return; } if (mailfrom.len == 1 && recipcount > 1) { err_badbounce(); return; } if (flagbrt) { err_brt(); return; } + if (!spp_data()) return; seenmail = 0; if (databytes) bytestooverflow = databytes + 1; if (qmail_open(&qqt) == -1) { err_qqt(); return; } @@ -739,6 +754,8 @@ void smtp_data() { out("354 go ahead\r\n"); received(&qqt,protocol,local,remoteip,remotehost,remoteinfo,fakehelo); + qmail_put(&qqt,sppheaders.s,sppheaders.len); /* set in qmail-spp.c */ + spp_rset(); blast(&hops); hops = (hops >= MAXHOPS); if (hops) qmail_fail(&qqt); @@ -972,6 +989,7 @@ char *arg; switch (authcmds[i].fun(arg)) { case 0: + if (!spp_auth(authcmds[i].text, user.s)) return; flagauth = 1; protocol = "ESMTPA"; relayclient = ""; @@ -1250,8 +1268,10 @@ char **argv; if (chdir(auto_qmail) == -1) die_control(); setup(); if (ipme_init() != 1) die_ipme(); + if (spp_connect()) { smtp_greet("220 "); out(" ESMTP\r\n"); + } if (commands(&ssin,&smtpcommands) == 0) die_read(); die_nomem(); } -- cgit v1.2.3