--- qmail-smtpd.c.orig Mon Jun 15 19:53:16 1998 +++ qmail-smtpd.c Tue Oct 5 10:46:21 2004 @@ -49,6 +49,7 @@ 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 err_bhelo() { out("553 sorry, your HELO is in my badhelo list (#5.7.1)\r\n"); { extern stralloc helohost; char *s; s = "badhelo: "; write(2, s, str_len(s)); write(2, helohost.s, helohost.len - 1); write(2, "\n", 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"); } void err_unimpl() { out("502 unimplemented (#5.5.1)\r\n"); } @@ -85,14 +86,32 @@ stralloc helohost = {0}; char *fakehelo; /* pointer into helohost, or 0 */ +static int bhelook = 0; +static stralloc bhelo = {0}; +static struct constmap mapbhelo; +static int flagbadhelo; + +static int bhelocheck() +{ + int j; + if (!bhelook) return 0; + if (!helohost.s) return 0; + if (constmap(&mapbhelo,helohost.s,helohost.len - 1)) return 1; + return 0; +} + void dohelo(arg) char *arg; { if (!stralloc_copys(&helohost,arg)) die_nomem(); if (!stralloc_0(&helohost)) die_nomem(); fakehelo = case_diffs(remotehost,helohost.s) ? helohost.s : 0; + flagbadhelo = bhelocheck(); } int liphostok = 0; stralloc liphost = {0}; +int gmfok = 0; +stralloc gmf = {0}; +struct constmap mapgmf; int bmfok = 0; stralloc bmf = {0}; struct constmap mapbmf; @@ -112,6 +131,14 @@ if (rcpthosts_init() == -1) die_control(); + bhelook = control_readfile(&bhelo,"control/badhelo",0); + if (bhelook == -1) die_control(); + if (bhelook) + if (!constmap_init(&mapbhelo,bhelo.s,bhelo.len,0)) die_nomem(); + gmfok = control_readfile(&gmf,"control/goodmailfrom",0); + if (gmfok == -1) die_control(); + if (gmfok) + if (!constmap_init(&mapgmf,gmf.s,gmf.len,0)) die_nomem(); bmfok = control_readfile(&bmf,"control/badmailfrom",0); if (bmfok == -1) die_control(); if (bmfok) @@ -197,6 +224,17 @@ return 1; } +int gmfcheck() +{ + int j; + if (!gmfok) return 0; + if (constmap(&mapgmf,addr.s,addr.len - 1)) return 1; + j = byte_rchr(addr.s,addr.len,'@'); + if (j < addr.len) + if (constmap(&mapgmf,addr.s + j,addr.len - j - 1)) return 1; + return 0; +} + int bmfcheck() { int j; @@ -240,6 +278,7 @@ void smtp_mail(arg) char *arg; { if (!addrparse(arg)) { err_syntax(); return; } + if (gmfcheck()) { flagbadhelo = 0;} flagbarf = bmfcheck(); seenmail = 1; if (!stralloc_copys(&rcptto,"")) die_nomem(); @@ -372,6 +411,7 @@ if (!seenmail) { err_wantmail(); return; } if (!rcptto.len) { err_wantrcpt(); return; } + if (flagbadhelo) { err_bhelo(); return; } seenmail = 0; if (databytes) bytestooverflow = databytes + 1; if (qmail_open(&qqt) == -1) { err_qqt(); return; }