[Greylist-users] qmail implementation - correct this time, I hope

Tony Arcieri tarcieri at atmos.colostate.edu
Thu Jun 26 18:03:06 PDT 2003


Here's another patch with some more changes.  The (now) envelope_scanner()
function call was in the wrong location.  It's now no longer called if the
RELAYCLIENT environment variable is set.

I also renamed the executed program from qmail-env-scanner to
qmail-envelope-scanner as people suggested 'env' is traditionally
used to represent 'environment' and thus it could be easily confused.

Tony Arcieri
-------------- next part --------------
--- qmail-1.03/qmail-smtpd.c	Mon Jun 15 04:53:16 1998
+++ qmail-1.03-scanenv/qmail-smtpd.c	Thu Jun 26 16:16:24 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 message temporarily rejected (#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 message permanently rejected (#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,44 @@
 stralloc mailfrom = {0};
 stralloc rcptto = {0};
 
+int envelope_scanner()
+{
+  int child;
+  int wstat;
+  char *env_scannerarg[] = { "bin/qmail-envelope-scanner", mailfrom.s, addr.s, 0 };
+  
+  switch(child = vfork()) {
+    case -1:
+      return 1;
+    case 0:
+      execv(*env_scannerarg,env_scannerarg);
+      _exit(111);
+  }
+
+  wait_pid(&wstat,child);
+  if (wait_crashed(wstat)) {
+    /* Can't call log1 here? */
+    /* log1("warning: envelope scanner crashed\n"); */   
+    return 1;
+  }
+  
+  switch(wait_exitcode(wstat)) {
+    case 0:
+      return 1; 
+    case 100:
+      die_tempfail();
+    case 101:
+      return 0;
+    case 111:
+      /* Can't call log1 here? */
+      /* log1("warning: cannot execute envelope scanner\n"); */
+      return 1;
+    default:
+      /* log1("warning: envelope scanner exited with error code\n"); */
+      return 1;
+  }
+}
+
 void smtp_helo(arg) char *arg;
 {
   smtp_greet("250 "); out("\r\n");
@@ -256,8 +298,10 @@
     if (!stralloc_cats(&addr,relayclient)) die_nomem();
     if (!stralloc_0(&addr)) die_nomem();
   }
-  else
+  else {
     if (!addrallowed()) { err_nogateway(); return; }
+    if(!envelope_scanner()) { err_permfail(); return; }
+  }   
   if (!stralloc_cats(&rcptto,"T")) die_nomem();
   if (!stralloc_cats(&rcptto,addr.s)) die_nomem();
   if (!stralloc_0(&rcptto)) die_nomem();


More information about the Greylist-users mailing list