prehor / amavisd-milter

Milter interface for the amavis spam filter engine.
BSD 3-Clause "New" or "Revised" License
8 stars 4 forks source link

Use {client_name} if available instead of hostname passed to xxfi_connect #1

Closed prehor closed 5 years ago

prehor commented 5 years ago

Moved form amavisd-milter-users mailing list.

From: Florian Pritz bluewind@xi... - 2017-12-15 23:35:26Attachments: signature.asc

Spamassassin's RDNS_NONE check tests if the rdns field in the Received header is empty or "unknown". Postfix sets the client_name macro to "unknown" when the FcrDNS check fails, but the hostname passed to xxfi_connect is set to the IP address which means that RDNS_NONE will never trigger. Fix this by using client_name if available and only fall back to the hostname parameter otherwise.

diff -ur src/amavisd-milter-1.6.1/amavisd-milter/mlfi.c src-mod/amavisd-milter-1.6.1/amavisd-milter/mlfi.c
--- src/amavisd-milter-1.6.1/amavisd-milter/mlfi.c  2015-05-24 20:59:19.000000000 +0200
+++ src-mod/amavisd-milter-1.6.1/amavisd-milter/mlfi.c  2017-12-15 18:08:15.007525175 +0100
@@ -315,6 +315,7 @@
     const void *addr;
     const char *prefix;
     const char *daemon_name;
+    const char *client_host;
     int        len, plen;

     logmsg(LOG_DEBUG, "%s: CONNECT", hostname);
@@ -331,8 +332,20 @@
     (void) memset(mlfi, '\0', sizeof(*mlfi));
     mlfi->mlfi_amasd = -1;

+   /* Try to get client_name from macros */
+   if ((client_host = smfi_getsymval(ctx, "{client_name}")) != NULL) {
+       logqidmsg(mlfi, LOG_INFO, "client_name: %s", client_host);
+       if ((mlfi->mlfi_client_host = strdup(client_host)) == NULL) {
+       logqidmsg(mlfi, LOG_ERR, "could not allocate memory");
+       mlfi_setreply_tempfail(ctx);
+       return SMFIS_TEMPFAIL;
+       }
+   } else {
+       logqidmsg(mlfi, LOG_INFO, "{client_name} undefined at connect time! Falling back to libmilter value.");
+   }
+
     /* Save connection informations */
-    if (hostname != NULL && *hostname != '\0') {
+    if (hostname != NULL && *hostname != '\0' && mlfi->mlfi_client_host == NULL) {
    if ((mlfi->mlfi_client_host = strdup(hostname)) == NULL) {
        logmsg(LOG_ERR, "%s: could not allocate memory", hostname);
        mlfi_setreply_tempfail(ctx);
Bluewind commented 5 years ago

FWIW, this patch is currently included in the Arch Linux package so given you are back working on amavisd-milter I'd love to get this merged. If you want, I can make it a proper commit and submit a PR.

prehor commented 5 years ago

Hi @Bluewind, it would be nice if you sent the PR.

Bluewind commented 5 years ago

I've opened a PR at #3