diff src/context.cpp @ 423:c9b7b6dd1206 stable-6-0-59

use both envelope from and header from for spf checks when envelope from is a subdomain of the header from domain
author Carl Byington <carl@five-ten-sg.com>
date Wed, 26 Jul 2017 08:52:31 -0700
parents 22027ad2a28f
children 6f2db3d19a34
line wrap: on
line diff
--- a/src/context.cpp	Fri May 19 13:49:18 2017 -0700
+++ b/src/context.cpp	Wed Jul 26 08:52:31 2017 -0700
@@ -1145,10 +1145,11 @@
     }
 }
 
-bool CONTEXT::resolve_spf(const char *from, uint32_t ip, mlfiPriv *priv, int level)
+
+bool CONTEXT::resolve_spf(const char *from, uint32_t ip, mlfiPriv *priv)
 {
     // ip is in host order
-    if ((level == 0) && (priv->mailaddr)) {
+    if (priv->mailaddr) {
         const char *f = strchr(priv->mailaddr, '@');
         if (f) {
             f++;
@@ -1158,11 +1159,18 @@
                 size_t off = efl - hfl;
                 if ((f[off-1] == '.') && (strcmp(f+off,from) == 0)) {
                     // envelope from is a strict child of header from
-                    from = f;   // use envelope from rather than header from
+                    // use envelope from rather than header from
+                    if (resolve_one_spf(f, ip, priv)) return true;
                 }
             }
         }
     }
+    return resolve_one_spf(from, ip, priv);
+}
+
+
+bool CONTEXT::resolve_one_spf(const char *from, uint32_t ip, mlfiPriv *priv, int level)
+{
     char buf[maxlen];
     log(priv->queueid, "looking for %s txt record", from);
     dns_interface(*priv, from, ns_t_txt, false, NULL, buf, maxlen);
@@ -1284,11 +1292,11 @@
                 }
                 else if ((level < 5) && (strncmp(p, "redirect=", 9) == 0)) {
                     p += 9;
-                    if (resolve_spf(p, ip, priv, level+1)) return true;
+                    if (resolve_one_spf(p, ip, priv, level+1)) return true;
                 }
                 else if ((level < 5) && (strncmp(p, "include:", 8) == 0)) {
                     p += 8;
-                    if (resolve_spf(p, ip, priv, level+1)) return true;
+                    if (resolve_one_spf(p, ip, priv, level+1)) return true;
                 }
             }
             p = (b) ? b+1 : e;