]> git.donarmstrong.com Git - deb_pkgs/spamass-milter.git/blobdiff - spamass-milter.cpp
switch to quilt
[deb_pkgs/spamass-milter.git] / spamass-milter.cpp
index 65657c193021b13020da2e3c69a5cda7935a1f63..b3ba061b668514b763345e87c08dee8fbd662e48 100644 (file)
@@ -1,6 +1,6 @@
 // 
 //
-//  $Id: spamass-milter.cpp,v 1.90 2006/03/23 21:41:36 dnelson Exp $
+//  $Id: spamass-milter.cpp,v 1.94 2011/02/14 21:50:53 dnelson Exp $
 //
 //  SpamAss-Milter 
 //    - a rather trivial SpamAssassin Sendmail Milter plugin
@@ -127,7 +127,7 @@ int daemon(int nochdir, int noclose);
 
 // }}} 
 
-static const char Id[] = "$Id: spamass-milter.cpp,v 1.90 2006/03/23 21:41:36 dnelson Exp $";
+static const char Id[] = "$Id: spamass-milter.cpp,v 1.94 2011/02/14 21:50:53 dnelson Exp $";
 
 struct smfiDesc smfilter =
   {
@@ -169,7 +169,6 @@ bool flag_bucket_only = false;
 char *spambucket;
 bool flag_full_email = false;          /* pass full email address to spamc */
 bool flag_expand = false;      /* alias/virtusertable expansion */
-bool ignore_authenticated_senders = false;
 bool warnedmacro = false;      /* have we logged that we couldn't fetch a macro? */
 
 // {{{ main()
@@ -178,7 +177,7 @@ int
 main(int argc, char* argv[])
 {
    int c, err = 0;
-   const char *args = "fd:mMp:P:r:u:D:i:Ib:B:e:x";
+   const char *args = "fd:mMp:P:r:u:D:i:b:B:e:x";
    char *sock = NULL;
    bool dofork = false;
    char *pidfilename = NULL;
@@ -210,10 +209,6 @@ main(int argc, char* argv[])
                                debug(D_MISC, "Parsing ignore list");
                                parse_networklist(optarg, &ignorenets);
                                break;
-                       case 'I':
-                               debug(D_MISC, "Ignore authenticated senders");
-                               ignore_authenticated_senders = true;
-                               break;
                        case 'm':
                                dontmodifyspam = true;
                                smfilter.xxfi_flags &= ~SMFIF_CHGBODY;
@@ -281,7 +276,7 @@ main(int argc, char* argv[])
       cout << PACKAGE_NAME << " - Version " << PACKAGE_VERSION << endl;
       cout << "SpamAssassin Sendmail Milter Plugin" << endl;
       cout << "Usage: spamass-milter -p socket [-b|-B bucket] [-d xx[,yy...]] [-D host]" << endl;
-      cout << "                      [-e defaultdomain] [-f] [-i networks] [-I] [-m] [-M]" << endl;
+      cout << "                      [-e defaultdomain] [-f] [-i networks] [-m] [-M]" << endl;
       cout << "                      [-P pidfile] [-r nn] [-u defaultuser] [-x]" << endl;
       cout << "                      [-- spamc args ]" << endl;
       cout << "   -p socket: path to create socket" << endl;
@@ -295,7 +290,6 @@ main(int argc, char* argv[])
       cout << "   -f: fork into background" << endl;
       cout << "   -i: skip (ignore) checks from these IPs or netblocks" << endl;
       cout << "          example: -i 192.168.12.5,10.0.0.0/8,172.16.0.0/255.255.0.0" << endl;
-      cout << "   -I: skip (ignore) checks if sender is authenticated" << endl;
       cout << "   -m: don't modify body, Content-type: or Subject:" << endl;
       cout << "   -M: don't modify the message at all" << endl;
       cout << "   -P pidfile: Put processid in pidfile" << endl;
@@ -465,13 +459,14 @@ assassinate(SMFICTX* ctx, SpamAssassin* assassin)
                           the only way to do it. */
                        char *popen_argv[3];
                        FILE *p;
+                       pid_t pid;
 
                        popen_argv[0] = SENDMAIL;
                        popen_argv[1] = spambucket;
                        popen_argv[2] = NULL;
                        
                        debug(D_COPY, "calling %s %s", SENDMAIL, spambucket);
-                       p = popenv(popen_argv, "w");
+                       p = popenv(popen_argv, "w", &pid);
                        if (!p)
                        {
                                debug(D_COPY, "popenv failed(%s).  Will not send a copy to spambucket", strerror(errno));
@@ -480,6 +475,7 @@ assassinate(SMFICTX* ctx, SpamAssassin* assassin)
                                // Send message provided by SpamAssassin
                                fwrite(assassin->d().c_str(), assassin->d().size(), 1, p);
                                fclose(p); p = NULL;
+                               waitpid(pid, NULL, 0);
                        }
                }
                return SMFIS_REJECT;
@@ -750,22 +746,6 @@ mlfi_envfrom(SMFICTX* ctx, char** envfrom)
   }
   /* debug(D_ALWAYS, "ZZZ got private context %p", sctx); */
 
-  if (ignore_authenticated_senders)
-  {
-    char *auth_authen;
-
-    auth_authen = smfi_getsymval(ctx, "{auth_authen}");
-    debug(D_MISC, "auth_authen=%s", auth_authen ?: "<unauthenticated>");
-
-    if (auth_authen)
-    {
-      debug(D_MISC, "sender authenticated (%s) - accepting message",
-           auth_authen);
-      debug(D_FUNC, "mlfi_envfrom: exit ignore");
-      return SMFIS_ACCEPT;
-    }
-  }
-
   debug(D_FUNC, "mlfi_envfrom: enter");
   try {
     // launch new SpamAssassin
@@ -814,9 +794,6 @@ mlfi_envrcpt(SMFICTX* ctx, char** envrcpt)
        struct context *sctx = (struct context*)smfi_getpriv(ctx);
        SpamAssassin* assassin = sctx->assassin;
        FILE *p;
-#if defined(__FreeBSD__)
-       int rv;
-#endif
 
        debug(D_FUNC, "mlfi_envrcpt: enter");
 
@@ -826,6 +803,7 @@ mlfi_envrcpt(SMFICTX* ctx, char** envrcpt)
 
                char buf[1024];
                char *popen_argv[4];
+               pid_t pid;
                
                popen_argv[0] = SENDMAIL;
                popen_argv[1] = "-bv";
@@ -834,7 +812,7 @@ mlfi_envrcpt(SMFICTX* ctx, char** envrcpt)
 
                debug(D_RCPT, "calling %s -bv %s", SENDMAIL, envrcpt[0]);
 
-               p = popenv(popen_argv, "r");
+               p = popenv(popen_argv, "r", &pid);
                if (!p)
                {
                        debug(D_RCPT, "popenv failed(%s).  Will not expand aliases", strerror(errno));
@@ -863,6 +841,7 @@ mlfi_envrcpt(SMFICTX* ctx, char** envrcpt)
                                }
                        }
                        fclose(p); p = NULL;
+                       waitpid(pid, NULL, 0);
                }
        } else
        {
@@ -966,7 +945,7 @@ mlfi_envrcpt(SMFICTX* ctx, char** envrcpt)
 
                assassin->output((string)
                        "Received: from "+macro_s+" ("+macro__+")\r\n\t"+
-                       "by "+macro_j+" ("+macro_v+"/"+macro_Z+") with "+macro_r+" id "+macro_i+"\r\n\t"+
+                       "by "+macro_j+"("+macro_v+"/"+macro_Z+") with "+macro_r+" id "+macro_i+";\r\n\t"+
                        macro_b+"\r\n\t"+
                        "(envelope-from "+assassin->from()+")\r\n");
 
@@ -2124,13 +2103,14 @@ void warnmacro(char *macro, char *scope)
 /*
    untrusted-argument-safe popen function - only supports "r" and "w" modes
    for simplicity, and always reads stdout and stderr in "r" mode.  Call
-   fclose to close the FILE.
+   fclose to close the FILE, and waitpid to reap the child process (pid).
 */
-FILE *popenv(char *const argv[], const char *type)
+FILE *popenv(char *const argv[], const char *type, pid_t *pid)
 {
        FILE *iop;
        int pdes[2];
        int save_errno;
+
        if ((*type != 'r' && *type != 'w') || type[1])
        {
                errno = EINVAL;
@@ -2138,7 +2118,7 @@ FILE *popenv(char *const argv[], const char *type)
        }
        if (pipe(pdes) < 0)
                return (NULL);
-       switch (fork()) {
+       switch (*pid = fork()) {
        
        case -1:                        /* Error. */
                save_errno = errno;