diff -ruN qmail-1.03-factory/Makefile qmail-1.03-greetdelay3/Makefile --- qmail-1.03-factory/Makefile 1998-06-15 06:53:16.000000000 -0400 +++ qmail-1.03-greetdelay3/Makefile 2006-12-24 23:07:17.000000000 -0500 @@ -1535,14 +1535,14 @@ load qmail-smtpd.o rcpthosts.o commands.o timeoutread.o \ timeoutwrite.o ip.o ipme.o ipalloc.o control.o constmap.o received.o \ date822fmt.o now.o qmail.o cdb.a fd.a wait.a datetime.a getln.a \ -open.a sig.a case.a env.a stralloc.a alloc.a substdio.a error.a str.a \ -fs.a auto_qmail.o socket.lib +open.a sig.a case.a env.a stralloc.a alloc.a strerr.a substdio.a \ +error.a str.a fs.a auto_qmail.o socket.lib ./load qmail-smtpd rcpthosts.o commands.o timeoutread.o \ timeoutwrite.o ip.o ipme.o ipalloc.o control.o constmap.o \ received.o date822fmt.o now.o qmail.o cdb.a fd.a wait.a \ datetime.a getln.a open.a sig.a case.a env.a stralloc.a \ - alloc.a substdio.a error.a str.a fs.a auto_qmail.o `cat \ - socket.lib` + alloc.a strerr.a substdio.a error.a str.a fs.a auto_qmail.o \ + `cat socket.lib` qmail-smtpd.0: \ qmail-smtpd.8 diff -ruN qmail-1.03-factory/qmail-smtpd.c qmail-1.03-greetdelay3/qmail-smtpd.c --- qmail-1.03-factory/qmail-smtpd.c 1998-06-15 06:53:16.000000000 -0400 +++ qmail-1.03-greetdelay3/qmail-smtpd.c 2006-12-24 22:53:11.000000000 -0500 @@ -23,9 +23,13 @@ #include "timeoutread.h" #include "timeoutwrite.h" #include "commands.h" +#include "strerr.h" +#include "subfd.h" #define MAXHOPS 100 unsigned int databytes = 0; +unsigned int greetdelay = 0; +unsigned int drop_pre_greet = 0; int timeout = 1200; int safewrite(fd,buf,len) int fd; char *buf; int len; @@ -48,6 +52,7 @@ void die_control() { out("421 unable to read controls (#4.3.0)\r\n"); flush(); _exit(1); } void die_ipme() { out("421 unable to figure out my IP addresses (#4.3.0)\r\n"); flush(); _exit(1); } void straynewline() { out("451 See http://pobox.com/~djb/docs/smtplf.html.\r\n"); flush(); _exit(1); } +void die_pre_greet() { out("554 SMTP protocol violation\r\n"); flush(); _exit(1); } void err_bmf() { out("553 sorry, your envelope sender is in my badmailfrom list (#5.7.1)\r\n"); } void err_nogateway() { out("553 sorry, that domain isn't in my list of allowed rcpthosts (#5.7.1)\r\n"); } @@ -122,6 +127,12 @@ if (x) { scan_ulong(x,&u); databytes = u; } if (!(databytes + 1)) --databytes; + x = env_get("GREETDELAY"); + if(x) { scan_ulong(x,&u); greetdelay = u; } + + x = env_get("DROP_PRE_GREET"); + if(x) { scan_ulong(x,&u); drop_pre_greet = u; } + remoteip = env_get("TCPREMOTEIP"); if (!remoteip) remoteip = "unknown"; local = env_get("TCPLOCALHOST"); @@ -410,10 +421,23 @@ void main() { + int x; sig_pipeignore(); if (chdir(auto_qmail) == -1) die_control(); setup(); if (ipme_init() != 1) die_ipme(); + if (greetdelay||drop_pre_greet) { + x = timeoutread(greetdelay?greetdelay:1,0,ssinbuf,sizeof ssinbuf); + if(-1 == x) { + if(errno != error_timeout) + strerr_die1sys(1,"qmail-smtpd: before greeting: "); + } else if ( 0 == x ) { + strerr_die1x(1,"qmail-smtpd: before greeting: client disconnected"); + } else if ( drop_pre_greet ) { + strerr_warn1("qmail-smtpd: before greeting: client sent data",0); + die_pre_greet(); + } + } smtp_greet("220 "); out(" ESMTP\r\n"); if (commands(&ssin,&smtpcommands) == 0) die_read();