Re: Qmail-LDAP License
Hugo Monteiro <[email protected]>
| Newsgroups | gmane.mail.qmail.ldap |
|---|---|
| Message-ID | <[email protected]> |
On 03/24/2010 04:54 PM, Claudio Jeker wrote: > On Wed, Mar 24, 2010 at 03:38:52PM +0000, Hugo Monteiro wrote: > >> On 03/24/2010 02:59 PM, Claudio Jeker wrote: >> >>> On Wed, Mar 24, 2010 at 09:29:42AM -0300, Andre Gerhard wrote: >>> >>>> Claudio, >>>> >>>> Is there a roadmap or plans for future developments of qmail-ldap ? >>>> >>>> Or we can assume that the software will not be updated anymore >>>> (or at least not in the near future) ? >>>> >>>> >>> I have more or less a release ready which will include minor fixes and a >>> dovecot authentication module. Maybe I can summon Andre so that we can >>> make it offical. >>> >> >> That would be terrific Claudio. I'm sure that everyone in the list >> is eager to see what has changed. >> >> >> >>> Future roadmap does not realy exist. I'm quite happy with the patch and >>> see no need to add lot of new stuff to it. I'm more in maintenance mode >>> and will add ideas from others if I think their useful. >>> >>> >> >> Can i suggest a few? =) >> >> From the top of my head, i would love to have: >> >> - greeting delay >> > Done > > Cool =) >> - envelope scanning >> > No idea what that is. Shouldn't that be done by something behind > qmail-queue? > > No, that's done in qmail-smtpd. It will allow you to perform various checks, with the aid of an external program, prior to the DATA command. Actually the idea can be extended to also perform checks after the message is submitted. In possession of the remote ip address, remote helo string, envelope sender, recipient and advertised esmtp message size you can: - implement greylisting - implement helo/ehlo checking, including helo randomization - implement various black/whitelistings based on network address, dns name, sender, recipient - implement message throttling based on advertized size (i know it's not a trustful value, but you can do it and spare message submission at this point) these are the basic ones, but there are other possibilities.. Also, if the check is done in two stages, being the second after the DATA command, you can REALLY enforce message size throttling. You can establish a relation between the two calls using a unique session value to be calculated as soon as qmail-smtpd accepts the connection. You can partially see what i'm talking about by visiting the outdated howto in http://hmonteiro.net/howtos/qmail-ldap/qmail-ldap_envelope_scanning and checking the attached cumulative patch. The kind of envelope scanning i'm performing is with the aid of a small program i wrote called qenvscan-policyd, which tries to implement a postfix policyd validation service into qmail-ldap. (Have it working for 3 years now with only joys) Also another easy thing to add, is an extra SENDERCHECK mode to allow local users to send mail locally, from remote locations, only if they are authenticated with us. I'm writing all this without much detail because i'm on a deadline over here, but i'll be available in a couple of days, if by any chance things are not clear enough. Best Regards and eager to hear again from you. Hugo Monteiro. -- fct.unl.pt:~# cat .signature Hugo Monteiro Email : [email protected] Telefone : +351 212948300 Ext.15307 Web : http://hmonteiro.net Divisão 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.fct.unl.pt [email protected] fct.unl.pt:~# _
qmail-ldap-hmonteiro-cumulative_patch-1.03-20060201.patch
(text/x-diff, 25.4 KB)
diff -Naur qmail-ldap-1.03-20060201/FILES qmail-ldap-hmonteiro-cumulative_patch-1.03-20060201/FILES
--- qmail-ldap-1.03-20060201/FILES 2010-03-24 17:58:13.000000000 +0000
+++ qmail-ldap-hmonteiro-cumulative_patch-1.03-20060201/FILES 2009-03-20 19:35:20.000000000 +0000
@@ -3,6 +3,7 @@
BLURB3
BLURB4
README
+README.GREETDELAY
FAQ
INSTALL
INSTALL.alias
diff -Naur qmail-ldap-1.03-20060201/fmt_uint64.c qmail-ldap-hmonteiro-cumulative_patch-1.03-20060201/fmt_uint64.c
--- qmail-ldap-1.03-20060201/fmt_uint64.c 1970-01-01 01:00:00.000000000 +0100
+++ qmail-ldap-hmonteiro-cumulative_patch-1.03-20060201/fmt_uint64.c 2009-06-26 15:33:04.000000000 +0100
@@ -0,0 +1,14 @@
+#include "fmt.h"
+#include "uint64.h"
+
+unsigned int fmt_uint64(s,u) register char *s; register uint64 u;
+{
+ register unsigned int len; register uint64 q;
+ len = 1; q = u;
+ while (q > 9) { ++len; q /= 10; }
+ if (s) {
+ s += len;
+ do { *--s = '0' + (u % 10); u /= 10; } while(u); /* handles u == 0 */
+ }
+ return len;
+}
diff -Naur qmail-ldap-1.03-20060201/hier.c qmail-ldap-hmonteiro-cumulative_patch-1.03-20060201/hier.c
--- qmail-ldap-1.03-20060201/hier.c 2010-03-24 17:58:13.000000000 +0000
+++ qmail-ldap-hmonteiro-cumulative_patch-1.03-20060201/hier.c 2009-03-20 19:35:20.000000000 +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 -Naur qmail-ldap-1.03-20060201/install-big.c qmail-ldap-hmonteiro-cumulative_patch-1.03-20060201/install-big.c
--- qmail-ldap-1.03-20060201/install-big.c 2010-03-24 17:58:13.000000000 +0000
+++ qmail-ldap-hmonteiro-cumulative_patch-1.03-20060201/install-big.c 2009-03-20 19:35:20.000000000 +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 -Naur qmail-ldap-1.03-20060201/Makefile qmail-ldap-hmonteiro-cumulative_patch-1.03-20060201/Makefile
--- qmail-ldap-1.03-20060201/Makefile 2010-03-24 17:58:13.000000000 +0000
+++ qmail-ldap-hmonteiro-cumulative_patch-1.03-20060201/Makefile 2009-06-26 15:50:47.000000000 +0100
@@ -18,13 +18,16 @@
# -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
+# -DENVELOPE_SCAN to enable generic envelope scanning. MySQL, Postfix SMTPD Access
+# Policy Server or custom authorization.
+LDAPFLAGS=-DQLDAP_CLUSTER -DEXTERNAL_TODO -DDASH_EXT -DDATA_COMPRESS -DQMQP_COMPRESS -DSMTPEXECCHECK -DALTQUEUE -DQUOTATRASH -DGREETDELAY -DENVELOPE_SCAN
# Perhaps you have different ldap libraries, change them here
-LDAPLIBS=-L/usr/local/lib -lldap -llber
+LDAPLIBS=-L/usr/lib -lldap -llber
# and change the location of the include files here
-LDAPINCLUDES=-I/usr/local/include
+LDAPINCLUDES=-I/usr/include
# on Slowaris you need -lresolv and probably a LD_RUN_PATH added like this:
#LDAPLIBS=-L/opt/OpenLDAP/lib -lldap -llber -lresolv -R/opt/OpenLDAP/lib
# for example on my Linux box I use:
@@ -33,7 +36,7 @@
#LDAPINCLUDES=-I/opt/OpenLDAP/include
# ZLIB needed for -DDATA_COMPRESS and -DQMQP_COMPRESS
-#ZLIB=-lz
+ZLIB=-lz
# or you installed zlib in a different path you can use something like this
#ZLIB=-L/opt/zlib/lib -lz
#ZINCLUDES=-I/opt/zlib/include
@@ -43,13 +46,13 @@
# use -DTLS_REMOTE to enable tls support in qmail-remote
# use -DTLS_SMTPD to enable tls support in qmail-smtpd
# use -DTLSDEBUG to enable additional tls debug information in qmail-remote
-#TLS=-DTLS_REMOTE -DTLS_SMTPD
+TLS=-DTLS_REMOTE -DTLS_SMTPD
# Path to OpenSSL includes
-#TLSINCLUDES=-I/usr/local/include
+TLSINCLUDES=-I/usr/include
# Path to OpenSSL libraries
-#TLSLIBS=-L/usr/local/lib -lssl -lcrypto
+TLSLIBS=-L/usr/lib -lssl -lcrypto
# Path to OpenSSL binary
-#OPENSSLBIN=/usr/local/bin/openssl
+OPENSSLBIN=/usr/bin/openssl
#OPENSSLBIN=openssl
# to make the Netscape download progress bar work with qmail-pop3d
@@ -57,13 +60,13 @@
MNW=-DMAKE_NETSCAPE_WORK
# to enable the auto-maildir-make feature uncomment the next line
-#MDIRMAKE=-DAUTOMAILDIRMAKE
+MDIRMAKE=-DAUTOMAILDIRMAKE
# to enable the auto-homedir-make feature uncomment the next line
-#HDIRMAKE=-DAUTOHOMEDIRMAKE
+HDIRMAKE=-DAUTOHOMEDIRMAKE
# on most systems we need this to make auth_pop and auth_imap
-#SHADOWLIBS=-lcrypt
+SHADOWLIBS=-lcrypt
# OpenBSD and other Systems do not have libcrypt, so comment the line out
# if you get linking problems.
# To use shadow passwords under some Linux OS, uncomment the next two lines.
@@ -73,7 +76,7 @@
# to enable the possibility to log and debug imap and pop uncoment the
# next line
-#DEBUG=-DDEBUG
+DEBUG=-DDEBUG
# WARNING: you need a NONE DEBUG auth_* to run with inetd
# for profiling ...
@@ -272,6 +275,10 @@
compile auto_split.c
./compile auto_split.c
+session.o: \
+compile session.c uint64.h
+ ./compile session.c
+
auto_uids.c: \
auto-uid auto-gid conf-users conf-groups
( ./auto-uid auto_uida `head -1 conf-users` \
@@ -814,6 +821,10 @@
compile fmt_ulong.c fmt.h
./compile fmt_ulong.c
+fmt_uint64.o: \
+compile fmt_uint64.c fmt.h uint64.h
+ ./compile fmt_uint64.c
+
fmtqfn.o: \
compile fmtqfn.c fmtqfn.h fmt.h auto_split.h
./compile fmtqfn.c
@@ -2061,16 +2072,17 @@
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 \
-dns.lib socket.lib
+alloc.a strerr.a substdio.a error.a str.a fs.a auto_qmail.o auto_break.o \
+session.o fmt_uint64.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 \
- error.a fs.a auto_qmail.o dns.o str.a auto_break.o \
+ 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 session.o fmt_uint64.o \
`cat dns.lib` `cat socket.lib` $(TLSLIBS) $(ZLIB)
+
qmail-smtpd.0: \
qmail-smtpd.8
nroff -man qmail-smtpd.8 > qmail-smtpd.0
@@ -2274,7 +2286,7 @@
received.o: \
compile received.c fmt.h qmail.h substdio.h now.h datetime.h \
datetime.h date822fmt.h received.h
- ./compile received.c
+ ./compile $(LDAPFLAGS) received.c
remoteinfo.o: \
compile remoteinfo.c byte.h substdio.h ip.h fmt.h timeoutconn.h \
@@ -2340,7 +2352,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 \
@@ -2394,6 +2406,7 @@
exit.h timeoutconn.h timeoutconn.c timeoutread.h timeoutread.c \
timeoutwrite.h timeoutwrite.c remoteinfo.h remoteinfo.c uint32.h1 \
uint32.h2 tryulong32.c wait.3 wait.h wait_pid.c wait_nohang.c \
+uint64.h1 uint64.h2 \
trywaitp.c sig.h sig_alarm.c sig_block.c sig_catch.c sig_pause.c \
sig_pipe.c sig_child.c sig_term.c sig_hup.c sig_misc.c sig_bug.c \
trysgact.c trysgprm.c env.3 env.h env.c envread.c byte.h byte_chr.c \
@@ -2717,6 +2730,13 @@
&& cat uint32.h2 || cat uint32.h1 ) > uint32.h
rm -f tryulong32.o tryulong32
+uint64.h: \
+tryulong64.c compile load uint64.h1 uint64.h2
+ ( ( ./compile tryulong64.c && ./load tryulong64 && \
+ ./tryulong64 ) >/dev/null 2>&1 \
+ && cat uint64.h2 || cat uint64.h1 ) > uint64.h
+ rm -f tryulong64.o tryulong64
+
wait.a: \
makelib wait_pid.o wait_nohang.o
./makelib wait.a wait_pid.o wait_nohang.o
diff -Naur qmail-ldap-1.03-20060201/qmail.c qmail-ldap-hmonteiro-cumulative_patch-1.03-20060201/qmail.c
--- qmail-ldap-1.03-20060201/qmail.c 2010-03-24 17:58:13.000000000 +0000
+++ qmail-ldap-hmonteiro-cumulative_patch-1.03-20060201/qmail.c 2009-03-22 12:50:37.000000000 +0000
@@ -32,6 +32,7 @@
{
int pim[2];
int pie[2];
+ int pierr[2];
#ifdef ALTQUEUE
setup_qqargs();
@@ -39,17 +40,26 @@
if (pipe(pim) == -1) return -1;
if (pipe(pie) == -1) { close(pim[0]); close(pim[1]); return -1; }
+ if (pipe(pierr) == -1) {
+ close(pim[0]); close(pim[1]);
+ close(pie[0]); close(pie[1]);
+ close(pierr[0]); close(pierr[1]);
+ return -1;
+ }
switch(qq->pid = vfork()) {
case -1:
+ close(pierr[0]); close(pierr[1]);
close(pim[0]); close(pim[1]);
close(pie[0]); close(pie[1]);
return -1;
case 0:
close(pim[1]);
close(pie[1]);
+ close(pierr[0]); /* we want to receive data */
if (fd_move(0,pim[0]) == -1) _exit(120);
if (fd_move(1,pie[0]) == -1) _exit(120);
+ if (fd_move(4,pierr[1]) == -1) _exit(120);
if (chdir(auto_qmail) == -1) _exit(61);
execv(*binqqargs,binqqargs);
_exit(120);
@@ -57,6 +67,7 @@
qq->fdm = pim[1]; close(pim[0]);
qq->fde = pie[1]; close(pie[0]);
+ qq->fderr = pierr[0]; close(pierr[1]);
substdio_fdbuf(&qq->ss,subwrite,qq->fdm,qq->buf,sizeof(qq->buf));
qq->flagerr = 0;
return 0;
@@ -141,10 +152,22 @@
{
int wstat;
int exitcode;
+ int match;
+ char ch;
+ static char errstr[256];
+ int len = 0;
qmail_put(qq,"",1);
if (!qq->flagerr) if (substdio_flush(&qq->ss) == -1) qq->flagerr = 1;
close(qq->fde);
+ substdio_fdbuf(&qq->ss,read,qq->fderr,qq->buf,sizeof(qq->buf));
+ while( substdio_bget(&qq->ss,&ch,1) && len < 255){
+ errstr[len]=ch;
+ len++;
+ }
+ if (len > 0) errstr[len]='\0'; /* add str-term */
+
+ close(qq->fderr);
if ((unsigned long)wait_pid(&wstat,qq->pid) != qq->pid)
return "Zqq waitpid surprise (#4.3.0)";
@@ -177,8 +200,11 @@
case 81: return "Zqq internal bug (#4.3.0)";
case 120: return "Zunable to exec qq (#4.3.0)";
default:
+ if (exitcode == 82 && len > 2){
+ return errstr;
+ }
if ((exitcode >= 11) && (exitcode <= 40))
- return "Dqq permanent problem (#5.3.0)";
+ return "Dqq permanent problem (#5.3.0)";
return "Zqq temporary problem (#4.3.0)";
}
}
diff -Naur qmail-ldap-1.03-20060201/qmail.h qmail-ldap-hmonteiro-cumulative_patch-1.03-20060201/qmail.h
--- qmail-ldap-1.03-20060201/qmail.h 2010-03-24 17:58:13.000000000 +0000
+++ qmail-ldap-hmonteiro-cumulative_patch-1.03-20060201/qmail.h 2009-03-22 12:50:37.000000000 +0000
@@ -8,6 +8,7 @@
unsigned long pid;
int fdm;
int fde;
+ int fderr;
substdio ss;
char buf[1024];
} ;
diff -Naur qmail-ldap-1.03-20060201/qmail-smtpd.c qmail-ldap-hmonteiro-cumulative_patch-1.03-20060201/qmail-smtpd.c
--- qmail-ldap-1.03-20060201/qmail-smtpd.c 2010-03-24 17:58:13.000000000 +0000
+++ qmail-ldap-hmonteiro-cumulative_patch-1.03-20060201/qmail-smtpd.c 2009-06-27 21:04:06.000000000 +0100
@@ -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"
@@ -22,6 +25,10 @@
#include "env.h"
#include "now.h"
#include "exit.h"
+#ifdef ENVELOPE_SCAN
+ #include "fork.h"
+ #include "wait.h"
+#endif
#include "rcpthosts.h"
#include "rbl.h"
#include "timeoutread.h"
@@ -45,7 +52,15 @@
#define MAXHOPS 100
#define MAXLINELEN 10000
+#ifdef ENVELOPE_SCAN
+#define RCPTSTATE "RCPT"
+#define EOMSTATE "END-OF-MESSAGE"
+#endif
unsigned long databytes = 0;
+#ifdef GREETDELAY
+unsigned int greetdelay = 0;
+unsigned int drop_pre_greet = 0;
+#endif
int timeout = 1200;
#ifdef TLS_SMTPD
@@ -161,10 +176,17 @@
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"); }
void err_soft(char *s) { out("451 "); out(s); out("\r\n"); logline2(1,"temporary verify error: ", s); }
+#ifdef ENVELOPE_SCAN
+void err_tempfail() { out("421 temporary envelope failure (#4.3.0)\r\n"); }
+void err_permfail() { out("553 sorry, permanent envelope failure (#5.7.1)\r\n"); }
+#endif
void err_bmf(void) { out("553 sorry, your mail was administratively denied. (#5.7.1)\r\n"); }
void err_bmfunknown(void) { out("553 sorry, your mail from a host ["); out(remoteip); out("] without valid reverse DNS was administratively denied (#5.7.1)\r\n"); }
void err_maxrcpt(void) { out("553 sorry, too many recipients (#5.7.1)\r\n"); }
@@ -304,6 +326,12 @@
#endif
char *x, *l;
unsigned long u;
+#ifdef ENVELOPE_SCAN
+ char *remoteport;
+ char sessionid[FMT_ULONG];
+ unsigned long nremoteport;
+ unsigned long long nsessionid;
+#endif
l = env_get("LOGLEVEL");
if (l) { scan_ulong(l,&u); loglevel = u > 4 ? 4 : u; }
@@ -390,6 +418,7 @@
sendercheck = 1;
if (!case_diffs("LOOSE",env_get("SENDERCHECK"))) sendercheck = 2;
if (!case_diffs("STRICT",env_get("SENDERCHECK"))) sendercheck = 3;
+ if (!case_diffs("AUTH",env_get("SENDERCHECK"))) sendercheck = 4;
}
if (env_get("RCPTCHECK")) rcptcheck = 1;
if (env_get("LDAPSOFTOK")) ldapsoftok = 1;
@@ -412,6 +441,13 @@
x = env_get("DATABYTES");
if (x) scan_ulong(x,&databytes);
if (!(databytes + 1)) --databytes; /* poor man overflow detection */
+
+#ifdef GREETDELAY
+ x = env_get("GREETDELAY");
+ if((x) && !(relayok)) { 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";
@@ -419,6 +455,14 @@
if (!remotehost) remotehost = "unknown";
remoteinfo = env_get("TCPREMOTEINFO");
+#ifdef ENVELOPE_SCAN
+ remoteport = env_get("TCPREMOTEPORT");
+ scan_ulong(remoteport,&nremoteport);
+ nsessionid = hash64(remoteip,nremoteport);
+ sessionid[fmt_uint64(sessionid, nsessionid)] = 0;
+ if (!env_put2("SESSIONID",sessionid)) die_nomem();
+#endif
+
local = env_get("TCPLOCALHOST");
if (!local) local = env_get("TCPLOCALIP");
if (!local) local = "unknown";
@@ -453,6 +497,7 @@
if (sendercheck == 1) logstring(3," ");
if (sendercheck == 2) logstring(3,"-loose ");
if (sendercheck == 3) logstring(3,"-strict ");
+ if (sendercheck == 4) logstring(3,"-auth ");
if (rcptcheck) logstring(3,"rcptcheck ");
if (ldapsoftok) logstring(3,"ldapsoftok ");
if (flagauth) logstring(3, "smtp-auth");
@@ -831,7 +876,41 @@
return 0;
}
+#ifdef ENVELOPE_SCAN
+int envelope_scanner()
+{
+ int child;
+ int wstat;
+
+ if (!env_put2("HELO",helohost.s)) die_nomem();
+ char *envelope_scannerarg[] = { env_get("ENVELOPE_SCANNER") , 0};
+
+ switch(child = vfork()) {
+ case -1:
+ return 1;
+ case 0:
+ execv(*envelope_scannerarg,envelope_scannerarg);
+ _exit(111);
+ }
+
+ wait_pid(&wstat,child);
+ if (wait_crashed(wstat)) {
+ return 1;
+ }
+ switch(wait_exitcode(wstat)) {
+ case 100: /* rejected */
+ err_permfail();
+ return 0;
+ case 101: /* greylisted */
+ err_tempfail();
+ return 0;
+ default: /* something wrong happened */
+ return 1;
+ }
+}
+#endif
+
void smtp_helo(char *arg)
{
smtp_line("250 ");
@@ -882,6 +961,9 @@
unsigned int i,j;
char *rblname;
int bounceflag = 0;
+#ifdef ENVELOPE_SCAN
+ char *messagesize;
+#endif
/* address syntax check */
if (!addrparse(arg))
@@ -915,6 +997,12 @@
return;
}
+#ifdef ENVELOPE_SCAN
+ if (!env_put2("SMTPSTATE",RCPTSTATE)) die_nomem();
+ messagesize = getparameter(arg, "SIZE");
+ if (!env_put2("SIZE",messagesize ? messagesize : "0")) die_nomem();
+#endif
+
/* bad mailfrom check */
if (bmfcheck())
{
@@ -1046,6 +1134,12 @@
switch (ldaplookup(addr.s, &s)) {
case 1: /* valid */
logline(4,"sender verify OK");
+ if (sendercheck == 4 && !flagauthok) {
+ out("530 authentication needed\r\n");
+ logline(3, "auth needed");
+ if (errdisconnect) err_quit();
+ return;
+ }
break;
case 0: /* invalid */
logline2(2, "bad sender: ", addr.s);
@@ -1079,6 +1173,9 @@
if (!stralloc_copys(&rcptto,"")) die_nomem();
if (!stralloc_copys(&mailfrom,addr.s)) die_nomem();
if (!stralloc_0(&mailfrom)) die_nomem();
+#ifdef ENVELOPE_SCAN
+ if (!env_put2("SENDER",mailfrom.s)) die_nomem();
+#endif
rcptcount = 0;
if (loglevel < 4)
logline2(2,"mail from: ",mailfrom.s);
@@ -1137,6 +1234,18 @@
}
++rcptcount;
+#ifdef ENVELOPE_SCAN
+char recipientcount[FMT_ULONG];
+recipientcount[fmt_ulong(recipientcount,rcptcount)] = 0;
+
+ if (env_get("PSTATE_RCPT")) {
+ if (!env_put2("RCPTCOUNT",recipientcount)) die_nomem();
+ if (!env_put2("RECIPIENT",addr.s)) die_nomem();
+ if (!env_put2("SMTPSTATE",RCPTSTATE)) die_nomem();
+ if (env_get("ENVELOPE_SCANNER") && !envelope_scanner()) return;
+ }
+#endif
+
/* maximum recipient limit reached */
if (maxrcptcount && rcptcount > maxrcptcount) {
err_maxrcpt();
@@ -1405,6 +1514,10 @@
stralloc protocolinfo = {0};
#endif
+#ifdef ENVELOPE_SCAN
+char messagesize[FMT_ULONG];
+#endif
+
void smtp_data(char *arg) {
unsigned int hops;
unsigned long qp;
@@ -1479,6 +1592,15 @@
qmail_from(&qqt,mailfrom.s);
qmail_put(&qqt,rcptto.s,rcptto.len);
+#ifdef ENVELOPE_SCAN
+ if (env_get("PSTATE_EOM")) {
+ if (!env_put2("SMTPSTATE",EOMSTATE)) die_nomem();
+ messagesize[fmt_ulong(messagesize, bytesreceived)] = 0;
+ if (!env_put2("SIZE",messagesize));
+ if (env_get("ENVELOPE_SCANNER") && !envelope_scanner()) return;
+ }
+#endif
+
qqx = qmail_close(&qqt);
if (!*qqx) { acceptmessage(qp); return; }
if (hops) {
@@ -1594,6 +1716,9 @@
case '2':
flagauthok = 1;
remoteinfo = line.s;
+#ifdef ENVELOPE_SCAN
+ if (!env_put2("AUTH_USER",remoteinfo)) die_nomem();
+#endif
out(status);
logline2(2,"authentication success, user ", remoteinfo);
break;
@@ -1735,10 +1860,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 -Naur qmail-ldap-1.03-20060201/README.GREETDELAY qmail-ldap-hmonteiro-cumulative_patch-1.03-20060201/README.GREETDELAY
--- qmail-ldap-1.03-20060201/README.GREETDELAY 1970-01-01 01:00:00.000000000 +0100
+++ qmail-ldap-hmonteiro-cumulative_patch-1.03-20060201/README.GREETDELAY 2009-03-20 19:35:23.000000000 +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 GREETDELAY env var, which should be
+set to the amount of seconds that qmail-smtpd should wait until sending out
+the SMTP greeting message. If GREETDELAY is set but no value is specified (eg,
+GREETDELAY="" or > /var/qmail/boot/qmail-smtpd/env/GREETDELAY), the default value
+of zero will be used.
+
+In addition to GREETDELAY, 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]>
+
diff -Naur qmail-ldap-1.03-20060201/received.c qmail-ldap-hmonteiro-cumulative_patch-1.03-20060201/received.c
--- qmail-ldap-1.03-20060201/received.c 2010-03-24 17:58:13.000000000 +0000
+++ qmail-ldap-hmonteiro-cumulative_patch-1.03-20060201/received.c 2009-06-26 15:51:11.000000000 +0100
@@ -4,6 +4,9 @@
#include "datetime.h"
#include "date822fmt.h"
#include "received.h"
+#ifdef ENVELOPE_SCAN
+#include "env.h"
+#endif
static int issafe(ch) char ch;
{
@@ -54,6 +57,9 @@
const char *rcptto;
{
struct datetime dt;
+#ifdef ENVELOPE_SCAN
+ char *smtpauthuser;
+#endif
qmail_puts(qqt,"Received: from ");
safeput(qqt,remotehost);
@@ -71,6 +77,14 @@
safeput(qqt,remoteip);
qmail_puts(qqt,"])");
+#ifdef ENVELOPE_SCAN
+ smtpauthuser = env_get("AUTH_USER");
+ if (smtpauthuser) {
+ qmail_puts(qqt,"\n (SMTPAUTH User ");
+ safeput(qqt,smtpauthuser);
+ qmail_puts(qqt,")");
+ }
+#endif
if (mailfrom) {
qmail_puts(qqt,"\n (envelope-sender <");
safeput(qqt,mailfrom);
diff -Naur qmail-ldap-1.03-20060201/session.c qmail-ldap-hmonteiro-cumulative_patch-1.03-20060201/session.c
--- qmail-ldap-1.03-20060201/session.c 1970-01-01 01:00:00.000000000 +0100
+++ qmail-ldap-hmonteiro-cumulative_patch-1.03-20060201/session.c 2009-06-26 15:35:07.000000000 +0100
@@ -0,0 +1,20 @@
+#include <unistd.h>
+#include "session.h"
+#include "uint64.h"
+
+unsigned long long hash64(char *remoteip, unsigned long remoteport)
+{
+unsigned long long hv = 5381;
+int i = 0;
+
+ /* unique enough */
+ hv = ((hv << 5) + hv) ^ (unsigned int)getpid();
+ hv = ((hv << 5) + hv) ^ (unsigned int)time(NULL);
+ hv = ((hv << 5) + hv) ^ remoteport;
+
+ while (remoteip[i++]) {
+ hv = ((hv << 5) + hv) ^ (unsigned int)*remoteip;
+ }
+
+ return hv;
+}
diff -Naur qmail-ldap-1.03-20060201/session.h qmail-ldap-hmonteiro-cumulative_patch-1.03-20060201/session.h
--- qmail-ldap-1.03-20060201/session.h 1970-01-01 01:00:00.000000000 +0100
+++ qmail-ldap-hmonteiro-cumulative_patch-1.03-20060201/session.h 2009-06-26 15:34:57.000000000 +0100
@@ -0,0 +1,6 @@
+#ifndef SESSION_H
+#define SESSION_H
+
+unsigned long long hash64(char *remoteip, unsigned long remoteport);
+
+#endif
diff -Naur qmail-ldap-1.03-20060201/TARGETS qmail-ldap-hmonteiro-cumulative_patch-1.03-20060201/TARGETS
--- qmail-ldap-1.03-20060201/TARGETS 2010-03-24 17:58:13.000000000 +0000
+++ qmail-ldap-hmonteiro-cumulative_patch-1.03-20060201/TARGETS 2009-03-22 02:03:03.000000000 +0000
@@ -460,3 +460,6 @@
readwrite.o
smtpcall.o
xtext.o
+session.o
+fmt_uint64.o
+uint64.h
diff -Naur qmail-ldap-1.03-20060201/tryulong64.c qmail-ldap-hmonteiro-cumulative_patch-1.03-20060201/tryulong64.c
--- qmail-ldap-1.03-20060201/tryulong64.c 1970-01-01 01:00:00.000000000 +0100
+++ qmail-ldap-hmonteiro-cumulative_patch-1.03-20060201/tryulong64.c 2009-06-26 15:37:52.000000000 +0100
@@ -0,0 +1,11 @@
+int main()
+{
+ unsigned long u;
+ u = 1;
+ u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u;
+ u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u;
+ u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u;
+ u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u;
+ if (!u) _exit(1);
+ _exit(0);
+}
diff -Naur qmail-ldap-1.03-20060201/uint64.h1 qmail-ldap-hmonteiro-cumulative_patch-1.03-20060201/uint64.h1
--- qmail-ldap-1.03-20060201/uint64.h1 1970-01-01 01:00:00.000000000 +0100
+++ qmail-ldap-hmonteiro-cumulative_patch-1.03-20060201/uint64.h1 2009-06-26 15:34:19.000000000 +0100
@@ -0,0 +1,8 @@
+#ifndef UINT64_H
+#define UINT64_H
+
+/* sysdep: -ulong64 */
+
+typedef unsigned long long uint64;
+
+#endif
diff -Naur qmail-ldap-1.03-20060201/uint64.h2 qmail-ldap-hmonteiro-cumulative_patch-1.03-20060201/uint64.h2
--- qmail-ldap-1.03-20060201/uint64.h2 1970-01-01 01:00:00.000000000 +0100
+++ qmail-ldap-hmonteiro-cumulative_patch-1.03-20060201/uint64.h2 2009-06-26 15:34:25.000000000 +0100
@@ -0,0 +1,8 @@
+#ifndef UINT64_H
+#define UINT64_H
+
+/* sysdep: +ulong64 */
+
+typedef unsigned long uint64;
+
+#endif