diff options
Diffstat (limited to 'src/qmail-smtpd.c')
-rw-r--r-- | src/qmail-smtpd.c | 163 |
1 files changed, 96 insertions, 67 deletions
diff --git a/src/qmail-smtpd.c b/src/qmail-smtpd.c index 5e1497a..557649e 100644 --- a/src/qmail-smtpd.c +++ b/src/qmail-smtpd.c @@ -8,6 +8,7 @@ #include "cdbread.h" #include "close.h" #include "constmap.h" +#include "dnsresolv.h" #include "env.h" #include "exit.h" #include "fd.h" @@ -44,8 +45,10 @@ #include "auto_qmail.h" #endif -/** @file qmail-smtpd.c -- authenticating ESMTP/ESMTPS server - @brief requires sslserver or tcpserver */ +/** + * @file qmail-smtpd.c -- authenticating ESMTP/ESMTPS server + * @brief requires sslserver or tcpserver + */ #define PAM111421 #define AUTHSLEEP 5 @@ -64,7 +67,7 @@ unsigned long databytes = 0; long timeout = 1200; -int modssl_info(); +static int modssl_info(void); ssize_t safewrite(int fd, char *buf, int len) { @@ -74,7 +77,15 @@ ssize_t safewrite(int fd, char *buf, int len) return r; } -ssize_t saferead(int fd, char *buf, int len) +char outbuf[BUFFER_SIZE / 2]; +buffer bo = BUFFER_INIT(safewrite, FDOUT, outbuf, sizeof(outbuf)); + +void flush() +{ + buffer_flush(&bo); +} // this triggers writing to STDIO + +static ssize_t saferead(int fd, char *buf, int len) { int r; flush(); @@ -88,17 +99,9 @@ ssize_t saferead(int fd, char *buf, int len) char inbuf[BUFFER_SIZE]; buffer bi = BUFFER_INIT(saferead, FDIN, inbuf, sizeof(inbuf)); -char outbuf[BUFFER_SIZE / 2]; -buffer bo = BUFFER_INIT(safewrite, FDOUT, outbuf, sizeof(outbuf)); - char logbuf[256]; buffer bl = BUFFER_INIT(write, FDLOG, logbuf, sizeof(logbuf)); -void flush() -{ - buffer_flush(&bo); -} // this triggers writing to STDIO - void out(char *s) { buffer_puts(&bo, s); @@ -111,7 +114,7 @@ int bhelocheck(void); /* this file is too long -------------------------------------- DNS helper */ -int dnsq(char *arg, char type) +static int dnsq(char *arg, char type) { unsigned int random; int at; @@ -152,18 +155,18 @@ int dnsq(char *arg, char type) static stralloc greeting = {0}; -void smtp_greet(char *code) +static void smtp_greet(char *code) { buffer_puts(&bo, code); buffer_put(&bo, greeting.s, greeting.len); } -void smtp_help() +static void smtp_help() { out("214 s/qmail home page: https://www.fehcom.de/sqmail.html\r\n"); } -void smtp_quit() +static void smtp_quit() { smtp_greet("221 "); out("\r\n"); @@ -192,7 +195,7 @@ int seenhelo = 0; char *badmailcond; char *badhelocond; -void dohelo(char *helo) +static void dohelo(char *helo) { if (!stralloc_copys(&helohost, helo)) die_nomem(); if (!stralloc_0(&helohost)) die_nomem(); @@ -339,7 +342,7 @@ char *rblsmtpd; int flagspf = 0; static stralloc spfbounce = {0}; -void setup() +static void setup() { char *x; unsigned long u; @@ -547,7 +550,7 @@ void setup() fakehelo = 0; } -void auth_info(char *method) +static void auth_info(char *method) { if (!env_put("AUTHPROTOCOL", method)) die_nomem(); if (!env_put("AUTHUSER", remoteinfo)) die_nomem(); @@ -559,7 +562,7 @@ void auth_info(char *method) if (!stralloc_append(&protocol, "A")) die_nomem(); } -int modssl_info() +static int modssl_info() { tlsversion = env_get("SSL_PROTOCOL"); if (!tlsversion) return 0; @@ -623,7 +626,7 @@ int flagdnsmf = 0; int flagsize; int rcptcount = 0; -int addrparse(char *arg) +static int addrparse(char *arg) { int i; char ch; @@ -648,7 +651,7 @@ int addrparse(char *arg) if (!stralloc_copys(&addr, "")) die_nomem(); flagesc = 0; flagquoted = 0; - for (i = 0; ch = arg[i]; ++i) { /* copy arg to addr, stripping quotes */ + for (i = 0; (ch = arg[i]); ++i) { /* copy arg to addr, stripping quotes */ if (flagesc) { if (!stralloc_append(&addr, &ch)) die_nomem(); flagesc = 0; @@ -718,7 +721,7 @@ int bhelocheck() return 0; } -int bmfcheck() +static int bmfcheck() { int i = 0; int j = 0; @@ -808,7 +811,7 @@ int bmfcheck() return 0; } -int brtcheck() +static int brtcheck() { int i; int j = 0; @@ -846,7 +849,7 @@ int brtcheck() return 0; } -int addrallowed(char *arg) +static int addrallowed(char *arg) { int r; r = rcpthosts(arg, str_len(arg)); @@ -854,7 +857,7 @@ int addrallowed(char *arg) return r; } -int rcptallowed() +static int rcptallowed() { int r; r = recipients(addr.s, str_len(addr.s)); @@ -867,7 +870,7 @@ int rcptallowed() return r; } -int localaddr(char *mf) +static int localaddr(char *mf) { int at; int mflen; @@ -896,7 +899,7 @@ int localaddr(char *mf) } } -int spf_check(int flag6) +static int spf_check(int flag6) { int r; @@ -961,7 +964,7 @@ int spf_check(int flag6) /* this file is too long --------------------------------- MF parser */ -int mailfrom_size(char *arg) +static int mailfrom_size(char *arg) { unsigned long r; unsigned long sizebytes = 0; @@ -973,7 +976,7 @@ int mailfrom_size(char *arg) return 0; } -void mailfrom_auth(char *arg, int len) +static void mailfrom_auth(char *arg, int len) { if (!stralloc_copys(&fuser, "")) die_nomem(); if (case_starts(arg, "<>")) { @@ -1009,7 +1012,7 @@ void mailfrom_auth(char *arg, int len) } } -void mailfrom_parms(char *arg) +static void mailfrom_parms(char *arg) { int len; @@ -1037,7 +1040,7 @@ void mailfrom_parms(char *arg) /* this file is too long --------------------------------- SMTP dialog */ -void smtp_helo(char *arg) +static void smtp_helo(char *arg) { smtp_greet("250 "); out("\r\n"); @@ -1048,7 +1051,7 @@ void smtp_helo(char *arg) dohelo(arg); } -void smtp_ehlo(char *arg) +static void smtp_ehlo(char *arg) { char size[FMT_ULONG]; @@ -1078,8 +1081,10 @@ void smtp_ehlo(char *arg) dohelo(arg); } -void smtp_rset(void) +static void smtp_rset(char *x) { + (void)x; + seenmail = 0; rcptcount = 0; /* RFC 5321: seenauth + seentls stay */ @@ -1088,7 +1093,7 @@ void smtp_rset(void) out("250 flushed\r\n"); } -void smtp_starttls() +static void smtp_starttls() { if (starttls == 0) err_starttls(); @@ -1114,7 +1119,7 @@ void smtp_starttls() if (seenauth == 1) seenauth = 0; /* Otherwise Auth by client Cert */ } -void smtp_mail(char *arg) +static void smtp_mail(char *arg) { if (flagutf8) if (!stralloc_cats(&protocol, "UTF8")) die_nomem(); @@ -1156,7 +1161,7 @@ void smtp_mail(char *arg) /* this file is too long --------------------------------- Greylisting */ -int postgrey_scanner() +static int postgrey_scanner() { int child; int wstat; @@ -1178,7 +1183,7 @@ int postgrey_scanner() } } -void smtp_rcpt(char *arg) +static void smtp_rcpt(char *arg) { char *rcptok = 0; if (!seenmail) { @@ -1535,7 +1540,7 @@ static void queue_put(char *ch) qmail_put(&qqt, ch, 1); } -void blast(int *hops) +static void blast(int *hops) { char ch; int state; @@ -1640,7 +1645,7 @@ void blast(int *hops) char accept_buf[FMT_ULONG]; -void acceptmessage(unsigned long qp) +static void acceptmessage(unsigned long qp) { datetime_sec when; when = now(); @@ -1653,7 +1658,7 @@ void acceptmessage(unsigned long qp) out("\r\n"); } -void smtp_data() +static void smtp_data() { int hops; unsigned long qp; @@ -1822,7 +1827,7 @@ char **childargs; char authbuf[512]; buffer ba = BUFFER_INIT(safewrite, FDAUTH, authbuf, sizeof(authbuf)); -int authgetl(void) +static int authgetl() { int i; @@ -1843,7 +1848,7 @@ int authgetl(void) return authin.len; } -int authenticate(void) +static int authenticate() { int child; int wstat; @@ -1882,11 +1887,11 @@ int authenticate(void) if (wait_exitcode(wstat)) { sleep(AUTHSLEEP); return 1; - } /* no */ + } /* no */ return 0; /* yes */ } -int auth_login(char *arg) +static int auth_login(char *arg) { int r; if (smtpauth == 2 || smtpauth == 12) return 1; /* only login/plain */ @@ -1912,7 +1917,7 @@ int auth_login(char *arg) return authenticate(); } -int auth_plain(char *arg) +static int auth_plain(char *arg) { int r, id = 0; if (smtpauth == 2 || smtpauth == 12) return 1; /* only login/plain */ @@ -1937,7 +1942,7 @@ int auth_plain(char *arg) return authenticate(); } -int auth_cram() +static int auth_cram() { int i, r; char *s; @@ -1976,17 +1981,23 @@ int auth_cram() return authenticate(); } +static int err_noauth_handler(char *s) +{ + (void)s; + return err_noauth(); +} + struct authcmd { char *text; - int (*fun)(); + int (*fun)(char *); } authcmds[] = { - { "login", auth_login}, - { "plain", auth_plain}, - {"cram-md5", auth_cram}, - { 0, err_noauth} + { "login", auth_login}, + { "plain", auth_plain}, + {"cram-md5", auth_cram}, + { 0, err_noauth_handler} }; -void smtp_auth(char *arg) +static void smtp_auth(char *arg) { int i; char *cmd = arg; @@ -2067,20 +2078,38 @@ void smtp_auth(char *arg) /* this file is too long --------------------------------- GO ON */ +static void err_noop_handler(char *s) +{ + (void)s; + err_noop(); +} + +static void err_vrfy_handler(char *s) +{ + (void)s; + err_vrfy(); +} + +static void err_unimpl_handler(char *s) +{ + (void)s; + err_unimpl(); +} + struct commands smtpcommands[] = { - { "rcpt", smtp_rcpt, 0}, - { "mail", smtp_mail, 0}, - { "data", smtp_data, flush}, - { "auth", smtp_auth, flush}, - { "quit", smtp_quit, flush}, - { "helo", smtp_helo, flush}, - { "ehlo", smtp_ehlo, flush}, - { "rset", smtp_rset, flush}, - { "help", smtp_help, flush}, - { "noop", err_noop, flush}, - { "vrfy", err_vrfy, flush}, - {"starttls", smtp_starttls, flush}, - { 0, err_unimpl, flush} + { "rcpt", smtp_rcpt, 0}, + { "mail", smtp_mail, 0}, + { "data", smtp_data, flush}, + { "auth", smtp_auth, flush}, + { "quit", smtp_quit, flush}, + { "helo", smtp_helo, flush}, + { "ehlo", smtp_ehlo, flush}, + { "rset", smtp_rset, flush}, + { "help", smtp_help, flush}, + { "noop", err_noop_handler, flush}, + { "vrfy", err_vrfy_handler, flush}, + {"starttls", smtp_starttls, flush}, + { 0, err_unimpl_handler, flush} }; int main(int argc, char **argv) @@ -2094,7 +2123,7 @@ int main(int argc, char **argv) smtp_greet("220 "); out(" ESMTP\r\n"); flush(); - if (commands(&bi, &smtpcommands) == 0) die_read(); + if (commands(&bi, smtpcommands) == 0) die_read(); die_nomem(); return 0; |