[Patch] sa_username_conf and LDAP

Marco falon at ruparpiemonte.it
Thu Mar 8 16:34:23 CET 2018


Hello Amavis users,

  amavis 2.11.0 lacks in LDAP sa_username_conf support. With this patch 
SpamAssassin's LDAP database is consulted if user_scores_dsn is declared 
in a SpamAssassin configuration file, and the @sa_userconf_maps returns 
a string starting with 'ldap:' (case insensitive, the rest of the string 
is ignored).

Configure Spamassassin as explained in
https://svn.apache.org/repos/asf/spamassassin/branches/3.4/ldap/README

I hope this feature could be included to official releases of Amavis.

Feel free to improve this patch or find bug on it.

Kind Regards
--
Marco Favero
-------------- next part --------------
--- /usr/sbin/amavisd.orig      2017-04-19 14:28:21.000000000 +0200
+++ /usr/sbin/amavisd   2018-03-08 15:56:41.286362482 +0100
@@ -26792,7 +26792,7 @@

         if not mail_id then
           -- no matching mail_id
-        elseif msginfo[mail_id] then  -- already looked-up
+        elsif msginfo[mail_id] then  -- already looked-up
           rx_time_n = msginfo[mail_id].rx_time_n
         else  -- not yet looked-up
           msginfo[mail_id] = {}
@@ -30807,13 +30807,16 @@
       if ($uconf =~ /^sql:/i) {
         $uconf = $uname eq $sa_default_username ? '' : 'sql:'.$uname;
       }
+      elsif ($uconf =~ /^ldap:/i) {
+       $uconf = $uname eq $sa_default_username ? '' : 'ldap:'.$uname;
+      }
       if ($sa_version_num < 3.003000 && $uconf ne '') {
         $uconf = ''; $uconf_unsupported = 1;
       }
       if ($uconf eq '') {
         # ok, no special config required, just using a default
-      } elsif ($uconf =~ /^sql:/i) {
-        # assume data is in SQL, possibly an empty set
+      } elsif ($uconf =~ /^(sql|ldap):/i) {
+        # assume data is in SQL or LDAP, possibly an empty set
       } else {
         $uconf = "$MYHOME/$uconf"  if $uconf !~ m{^/};
         if ($uconf_filename_available{$uconf}) {
@@ -30979,6 +30982,11 @@
             or die "panic: loading SA config mismatch: $uname <-> $uconf";
           do_log(5,"loading SA user config from SQL %s", $uname);
           $spamassassin_obj->load_scoreonly_sql($uname);
+       } elsif ($uconf =~ /^ldap:/) {
+         $uconf eq 'ldap:'.$uname
+            or die "panic: loading SA config mismatch: $uname <-> $uconf";
+          do_log(5,"loading SA user config from LDAP %s", $uname);
+          $spamassassin_obj->load_scoreonly_ldap($uname);
         } else {
           do_log(5,"loading SA user config file %s", $uconf);
           $spamassassin_obj->read_scoreonly_config($uconf);


More information about the amavis-users mailing list