Hello all,
I've ported John M. Simpson's qmail greetdelay patch to qmail-ldap.
here is the README file:
---------- snip ----------
This patch is a port of the qmail greetdelay patch by
John M. Simpson <[EMAIL PROTECTED]>.
The code can be enabled at compile time specifying the -DGREETDELAY flag
on the LDAPFLAGS.
The code checks for the existence of the GRTDELAY env var, which should be
set to the amount of seconds that qmail-smtpd should wait until sending out
the SMTP greeting message. If GRTDELAY is set but no value is specified (eg,
GRTDELAY="" or > /var/qmail/boot/qmail-smtpd/env/GRTDELAY), the default
value
of zero will be used.
In addition to GRTDELAY, the env var DROP_PRE_GREET can also be set to "1".
In that case, no only qmail-smtpd will delay the SMTP greeting, but will
also
make qmail-smtpd enforce the SMTP rfc, exiting with an SMTP protocol
violation
error if any data is sent to the server before the greeting message is
presented.
Regards,
Hugo Monteiro <[EMAIL PROTECTED]>
---------- snip ----------
Coments are welcomed!
Regards,
Hugo Monteiro.
--
ci.fct.unl.pt:~# cat .signature
Hugo Monteiro
Email : [EMAIL PROTECTED]
Telefone : +351 212948300 Ext.15307
Centro de Informática
Faculdade de Ciências e Tecnologia da
Universidade Nova de Lisboa
Quinta da Torre 2829-516 Caparica Portugal
Telefone: +351 212948596 Fax: +351 212948548
www.ci.fct.unl.pt [EMAIL PROTECTED]
ci.fct.unl.pt:~# _
diff -u -N -r qmail-ldap-1.03-20060201/FILES qmail-ldap-1.03-20060201-greetdelay-0.3/FILES
--- qmail-ldap-1.03-20060201/FILES 2007-01-30 18:46:06.000000000 +0000
+++ qmail-ldap-1.03-20060201-greetdelay-0.3/FILES 2007-02-01 12:13:27.955562216 +0000
@@ -3,6 +3,7 @@
BLURB3
BLURB4
README
+README.GREETDELAY
FAQ
INSTALL
INSTALL.alias
diff -u -N -r qmail-ldap-1.03-20060201/hier.c qmail-ldap-1.03-20060201-greetdelay-0.3/hier.c
--- qmail-ldap-1.03-20060201/hier.c 2007-01-30 18:46:07.000000000 +0000
+++ qmail-ldap-1.03-20060201-greetdelay-0.3/hier.c 2007-02-01 12:15:15.871156552 +0000
@@ -182,6 +182,9 @@
c(auto_qmail,"doc","QLDAPPICTURE",auto_uido,auto_gidq,0644);
c(auto_qmail,"doc","EXTTODO",auto_uido,auto_gidq,0644);
c(auto_qmail,"doc","POPBEFORESMTP",auto_uido,auto_gidq,0644);
+#ifdef GREETDELAY
+ c(auto_qmail,"doc","README.GREETDELAY",auto_uido,auto_gidq,0644);
+#endif
c(auto_qmail,"bin","qmail-queue",auto_uidq,auto_gidq,04711);
c(auto_qmail,"bin","qmail-lspawn",auto_uido,auto_gidq,0700);
diff -u -N -r qmail-ldap-1.03-20060201/install-big.c qmail-ldap-1.03-20060201-greetdelay-0.3/install-big.c
--- qmail-ldap-1.03-20060201/install-big.c 2007-01-30 18:46:07.000000000 +0000
+++ qmail-ldap-1.03-20060201-greetdelay-0.3/install-big.c 2007-02-01 12:15:39.232605072 +0000
@@ -182,6 +182,9 @@
c(auto_qmail,"doc","QLDAPPICTURE",auto_uido,auto_gidq,0644);
c(auto_qmail,"doc","EXTTODO",auto_uido,auto_gidq,0644);
c(auto_qmail,"doc","POPBEFORESMTP",auto_uido,auto_gidq,0644);
+#ifdef GREETDELAY
+ c(auto_qmail,"doc","README.GREETDELAY",auto_uido,auto_gidq,0644);
+#endif
c(auto_qmail,"bin","qmail-queue",auto_uidq,auto_gidq,04711);
c(auto_qmail,"bin","qmail-lspawn",auto_uido,auto_gidq,0700);
diff -u -N -r qmail-ldap-1.03-20060201/Makefile qmail-ldap-1.03-20060201-greetdelay-0.3/Makefile
--- qmail-ldap-1.03-20060201/Makefile 2007-01-30 18:46:06.000000000 +0000
+++ qmail-ldap-1.03-20060201-greetdelay-0.3/Makefile 2007-02-01 12:16:49.405937104 +0000
@@ -18,6 +18,7 @@
# -DQLDAP_CLUSTER for enabling cluster support
# -DQMQP_COMPRESS to use the QMQP on the fly compression (for clusters)
# -DQUOTATRASH to include the Trash in the quota calculation (normaly it is not)
+# -DGREETDELAY to enable greeting delay and enforce greeting rfc compliance
# -DSMTPEXECCHECK to enable smtp DOS/Windows executable detection
#LDAPFLAGS=-DQLDAP_CLUSTER -DEXTERNAL_TODO -DDASH_EXT -DDATA_COMPRESS -DQMQP_COMPRESS -DSMTPEXECCHECK
@@ -2061,13 +2062,13 @@
timeoutwrite.o ip.o ipme.o ipalloc.o control.o constmap.o received.o \
date822fmt.o now.o qmail.o execcheck.o cdb.a smtpcall.o coe.o fd.a \
seek.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 auto_break.o \
+alloc.a strerr.a substdio.a error.a str.a fs.a auto_qmail.o auto_break.o \
dns.lib socket.lib
./load qmail-smtpd rcpthosts.o commands.o timeoutread.o rbl.o \
timeoutwrite.o ip.o ipme.o ipalloc.o control.o constmap.o \
received.o date822fmt.o now.o qmail.o execcheck.o cdb.a \
smtpcall.o coe.o fd.a seek.a wait.a datetime.a getln.a \
- open.a sig.a case.a env.a stralloc.a alloc.a substdio.a \
+ open.a sig.a case.a env.a stralloc.a alloc.a strerr.a substdio.a \
error.a fs.a auto_qmail.o dns.o str.a auto_break.o \
`cat dns.lib` `cat socket.lib` $(TLSLIBS) $(ZLIB)
@@ -2340,7 +2341,7 @@
FILES BLURB BLURB2 BLURB3 BLURB4 README FAQ INSTALL INSTALL.alias \
INSTALL.ctl INSTALL.ids INSTALL.maildir INSTALL.mbox INSTALL.vsm \
REMOVE.sendmail REMOVE.binmail TEST.deliver TEST.receive UPGRADE \
-THOUGHTS TODO THANKS CHANGES SECURITY INTERNALS SENDMAIL \
+THOUGHTS TODO THANKS CHANGES SECURITY INTERNALS SENDMAIL README.GREETDELAY\
PIC.local2alias PIC.local2ext PIC.local2local PIC.local2rem \
PIC.local2virt PIC.nullclient PIC.relaybad PIC.relaygood \
PIC.rem2local FILES VERSION SYSDEPS TARGETS Makefile BIN.README \
diff -u -N -r qmail-ldap-1.03-20060201/qmail-smtpd.c qmail-ldap-1.03-20060201-greetdelay-0.3/qmail-smtpd.c
--- qmail-ldap-1.03-20060201/qmail-smtpd.c 2007-01-30 18:46:07.000000000 +0000
+++ qmail-ldap-1.03-20060201-greetdelay-0.3/qmail-smtpd.c 2007-02-01 11:17:51.711748368 +0000
@@ -4,6 +4,9 @@
#include "stralloc.h"
#include "substdio.h"
#include "subfd.h"
+#ifdef GREETDELAY
+ #include "strerr.h"
+#endif
#include "alloc.h"
#include "auto_qmail.h"
#include "auto_break.h"
@@ -46,6 +49,10 @@
#define MAXHOPS 100
#define MAXLINELEN 10000
unsigned long databytes = 0;
+#ifdef GREETDELAY
+unsigned int greetdelay = 0;
+unsigned int drop_pre_greet = 0;
+#endif
int timeout = 1200;
#ifdef TLS_SMTPD
@@ -161,6 +168,9 @@
void die_control(void) { out("421 unable to read controls (#4.3.0)\r\n"); logline(1,"unable to read controls, closing connection"); flush(); _exit(1); }
void die_ipme(void) { out("421 unable to figure out my IP addresses (#4.3.0)\r\n"); logline(1,"unable to figure out my IP address, closing connection"); flush(); _exit(1); }
void straynewline(void) { out("451 See http://pobox.com/~djb/docs/smtplf.html.\r\n"); logline(1,"stray new line detected, closing connection"); flush(); _exit(1); }
+#ifdef GREETDELAY
+void die_pre_greet() { out("554 SMTP protocol violation\r\n"); flush(); _exit(1); }
+#endif
void oversizedline(void) { out("500 Text line too long."); logline(1,"Oversized line in data part, closing connection"); flush(); _exit(1); }
void err_qqt(void) { out("451 qqt failure (#4.3.0)\r\n"); }
void err_dns(void) { out("421 DNS temporary failure at return MX check, try again later (#4.3.0)\r\n"); }
@@ -412,6 +422,13 @@
x = env_get("DATABYTES");
if (x) scan_ulong(x,&databytes);
if (!(databytes + 1)) --databytes; /* poor man overflow detection */
+
+#ifdef GREETDELAY
+ x = env_get("GRTDELAY");
+ if(x) { scan_ulong(x,&u); greetdelay = u; }
+ x = env_get("DROP_PRE_GREET");
+ if(x) { scan_ulong(x,&u); drop_pre_greet = u; }
+#endif
remoteip = env_get("TCPREMOTEIP");
if (!remoteip) remoteip = "unknown";
@@ -1735,10 +1752,27 @@
#ifdef TLS_SMTPD
sig_alarmcatch(sigalrm);
#endif
+#ifdef GREETDELAY
+ int x;
+#endif
sig_pipeignore();
if (chdir(auto_qmail) == -1) die_control();
setup();
if (ipme_init() != 1) die_ipme();
+#ifdef GREETDELAY
+ if (greetdelay||drop_pre_greet) {
+ x = timeoutread(greetdelay?greetdelay:0,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();
+ }
+ }
+#endif
if (greeting550 || greeting421) {
if (!stralloc_copys(&greeting,greeting550 ? greeting550 : greeting421))
die_nomem();
diff -u -N -r qmail-ldap-1.03-20060201/README.GREETDELAY qmail-ldap-1.03-20060201-greetdelay-0.3/README.GREETDELAY
--- qmail-ldap-1.03-20060201/README.GREETDELAY 1970-01-01 01:00:00.000000000 +0100
+++ qmail-ldap-1.03-20060201-greetdelay-0.3/README.GREETDELAY 2007-02-01 12:13:02.428442928 +0000
@@ -0,0 +1,21 @@
+This patch is a port of the qmail greetdelay patch by
+John M. Simpson <[EMAIL PROTECTED]>.
+
+The code can be enabled at compile time specifying the -DGREETDELAY flag
+on the LDAPFLAGS.
+
+The code checks for the existence of the GRTDELAY env var, which should be
+set to the amount of seconds that qmail-smtpd should wait until sending out
+the SMTP greeting message. If GRTDELAY is set but no value is specified (eg,
+GRTDELAY="" or > /var/qmail/boot/qmail-smtpd/env/GRTDELAY), the default value
+of zero will be used.
+
+In addition to GRTDELAY, the env var DROP_PRE_GREET can also be set to "1".
+In that case, no only qmail-smtpd will delay the SMTP greeting, but will also
+make qmail-smtpd enforce the SMTP rfc, exiting with an SMTP protocol violation
+error if any data is sent to the server before the greeting message is presented.
+
+Regards,
+
+Hugo Monteiro <[EMAIL PROTECTED]>
+