[Greylist-users] qmail implementation

Tony Arcieri tarcieri at atmos.colostate.edu
Wed Jun 25 15:48:40 PDT 2003


There was an error in the last patch.  I've also revised the patch so that
errors invoking /var/qmail/bin/qmail-env-scanner result in the message
simply being passed along rather than rejected.  I've also changed the
exit code semantics:

100 - temporary failure
101 - permanent failure
Anything else - pass message

Tony Arcieri
-------------- next part --------------
--- qmail-1.03/qmail-smtpd.c	Mon Jun 15 04:53:16 1998
+++ qmail-1.03-scanenv/qmail-smtpd.c	Wed Jun 25 14:43:38 2003
@@ -19,6 +19,8 @@
 #include "env.h"
 #include "now.h"
 #include "exit.h"
+#include "fork.h"
+#include "wait.h"
 #include "rcpthosts.h"
 #include "timeoutread.h"
 #include "timeoutwrite.h"
@@ -45,10 +47,12 @@
 void die_read() { _exit(1); }
 void die_alarm() { out("451 timeout (#4.4.2)\r\n"); flush(); _exit(1); }
 void die_nomem() { out("421 out of memory (#4.3.0)\r\n"); flush(); _exit(1); }
+void die_tempfail() { out("421 temporary envelope failure (#4.3.0)\r\n"); flush(); _exit(1); } 
 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 err_permfail() { out("553 permanent envelope failure (#5.7.1)\r\n"); }
 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"); }
@@ -222,6 +226,32 @@
 stralloc mailfrom = {0};
 stralloc rcptto = {0};
 
+int env_scanner()
+{
+  int child;
+  int wstat;
+  char *env_scannerarg[] = { "bin/qmail-env-scanner", mailfrom.s, addr.s, 0 };
+  
+  switch(child = vfork()) {
+    case -1:
+      return 0;
+    case 0:
+      execv(*env_scannerarg,env_scannerarg);
+      return 0;
+  }
+
+  wait_pid(&wstat,child);
+  if (wait_crashed(wstat)) return 0;
+  switch(wait_exitcode(wstat)) {
+    case 100:
+      die_tempfail();
+    case 101:
+      return 0;
+    default:
+      return 1;
+  }
+}
+
 void smtp_helo(arg) char *arg;
 {
   smtp_greet("250 "); out("\r\n");
@@ -245,6 +275,7 @@
   if (!stralloc_copys(&rcptto,"")) die_nomem();
   if (!stralloc_copys(&mailfrom,addr.s)) die_nomem();
   if (!stralloc_0(&mailfrom)) die_nomem();
+  if(!env_scanner()) { err_permfail(); return; }
   out("250 ok\r\n");
 }
 void smtp_rcpt(arg) char *arg; {


More information about the Greylist-users mailing list