Re: [exim] sa-exim & spamassassin with user_scores_sql_custo…

Page principale
Supprimer ce message
Répondre à ce message
Auteur: Magnus Holmgren
Date:  
À: exim-users
Sujet: Re: [exim] sa-exim & spamassassin with user_scores_sql_custom_query
On Sunday 31 December 2006 17:38, Maik Derstappen wrote:
> Magnus Holmgren wrote:
> > On Sunday 31 December 2006 14:34, Maik Derstappen wrote:
> >> hello,
> >>
> >> i will use user_scores_sql_custom_query in Spamassassin whith sa-exim.
> >> but in SA the _USERNAME_ is not set.
> >> how can i set this in sa-exim?
> >> or have anyone an another solution for this use case.
> >
> > It's not possible to pass a username (the -u parameter of spamc) to SA
> > with SA-Exim at the moment, but it will be in a near future.
>
> hello magnus,
>
> thanks for you quick answer.
> can you tell me, when may it be possible.


As soon as I get my source directory sorted out. Meanwhile, here's the patch.

-- 
Magnus Holmgren        holmgren@???
Debian maintaner of SA-Exim

--- sa-exim.c.orig    2006-12-03 06:35:42.267035158 +0100
+++ sa-exim.c    2006-12-03 06:32:14.038724154 +0100
@@ -515,6 +515,7 @@
     int pid;
     int writefd[2];
     int readfd[2];
+    char *spamc_argv[10];
     int i;
     /* These are the only values that we want working after the longjmp 
      * The automatic ones can be clobbered, but we don't really care */
@@ -552,6 +553,7 @@
     static char *SAspamcSockPath=NULL;
     static char *SAspamcPort="783";
     static char *SAspamcHost="127.0.0.1";
+    static char *SAspamcUser=NULL;
     static char *SAEximRunCond="0";
     static char *SAEximRejCond="1";
     static int SAmaxbody=250*1024;
@@ -712,6 +714,7 @@
         M_CHECKFORSTR(SAspamcSockPath);
         M_CHECKFORSTR(SAspamcPort);
         M_CHECKFORSTR(SAspamcHost);
+        M_CHECKFORSTR(SAspamcUser);
         M_CHECKFORSTR(SAEximRunCond);
         M_CHECKFORSTR(SAEximRejCond);
         M_CHECKFORVAR(SAmaxbody, "%d");
@@ -914,6 +917,22 @@
     ret=dup2(readfd[1],2);
     CHECKERR(ret,"dup2 stderr",__LINE__);


+    i = 0;
+    spamc_argv[i++] = "spamc";
+    if (SAspamcUser && SAspamcUser[0])
+    {
+        expand=expand_string(SAspamcUser);
+        if (expand == NULL)
+        {
+        log_write(0, LOG_MAIN | LOG_PANIC, "SA: SAspamcUser expansion failure on %s, will run as Exim user instead.", SAspamcUser);
+        }
+        else if (isalnum(expand[0]))
+        {
+        spamc_argv[i++] = "-u";
+        spamc_argv[i++] = expand;
+        }
+    }
+
     /* 
          * I could implement the spamc protocol and talk to spamd directly
          * instead of forking spamc, but considering the overhead spent
@@ -924,17 +943,26 @@
     /* Ok, we cheat, spamc cares about how big the whole message is and
          * we only know about the body size, so I'll  give an extra 16K
          * to account for any headers that can accompany the message */
+
+    spamc_argv[i++] = "-s";
+    spamc_argv[i++] = string_sprintf("%d", SAmaxbody+16384);
+
     if(SAspamcSockPath)
     {
-        ret=execl(SAspamcpath, "spamc", "-s", string_sprintf("%d", SAmaxbody+16384), "-U", SAspamcSockPath, NULL);
-        CHECKERR(ret,string_sprintf("exec %s", SAspamcpath),__LINE__);
+            spamc_argv[i++] = "-U";
+        spamc_argv[i++] = SAspamcSockPath;
     }
     else
     {
-        ret=execl(SAspamcpath, "spamc", "-s", string_sprintf("%d", SAmaxbody+16384), "-d", SAspamcHost, "-p", SAspamcPort, NULL);
-        CHECKERR(ret,string_sprintf("exec %s", SAspamcpath),__LINE__);
+            spamc_argv[i++] = "-d";
+        spamc_argv[i++] = SAspamcHost;
+            spamc_argv[i++] = "-p";
+        spamc_argv[i++] = SAspamcPort;
     }
-    
+    spamc_argv[i++] = NULL;
+
+    ret=execv(SAspamcpath, spamc_argv);
+    CHECKERR(ret,string_sprintf("exec %s", SAspamcpath),__LINE__);
     }


     if (SAEximDebug > 8)
--- sa-exim.conf.orig    2006-12-03 05:08:41.626021998 +0100
+++ sa-exim.conf    2006-12-03 06:32:14.142736297 +0100
@@ -54,6 +54,12 @@
 SAspamcHost: 127.0.0.1
 SAspamcPort: 783


+# SAspamcUser: The username passed to spamc. Some tricks are needed to
+# decide on one user when there are many recipients. This string is of
+# course expanded. If unset or empty, spamc will use the user Exim
+# runs as. We suggest that you decide what username to use in the ACLs
+# and set an ACL variable.
+#SAspamcUser: $acl_m2

# Exim configuration string to run before running SA against the message
# This decides whether SA gets run against the message or not. This