diff src/context.cpp @ 467:f5b394bec28c

allow checking names without A records on uribl lists; improve extraction of fake TLDs from our RPZ zone
author Carl Byington <carl@five-ten-sg.com>
date Wed, 16 Dec 2020 10:25:37 -0800
parents 79e944269c0b
children 5209e92b4885
line wrap: on
line diff
--- a/src/context.cpp	Thu Apr 25 09:47:36 2019 -0700
+++ b/src/context.cpp	Wed Dec 16 10:25:37 2020 -0800
@@ -801,7 +801,7 @@
 const char *CONTEXT::get_full_name(char *buffer, int size) {
     if (!parent) return name;
     char buf[maxlen];
-    snprintf(buffer, size, "%s.%s", parent->get_full_name(buf, maxlen), name);
+    snprintf(buffer, size, "%s.%s", parent->get_full_name(buf, maxlen-strlen(name)-2), name);
     return buffer;
 }
 
@@ -1105,8 +1105,8 @@
 
 void CONTEXT::log(const char *queueid, const char *msg, const char *v) {
     if (debug_syslog > 1) {
-        char buf[maxlen];
-        snprintf(buf, maxlen, msg, v);
+        char buf[maxdnslength+100];
+        snprintf(buf, sizeof(buf), msg, v);
         my_syslog(queueid, buf);
     }
 }
@@ -1219,7 +1219,7 @@
             if (b) *b = '\0';
             if ((*p != '-') && (*p != '~') && (*p != '?')) {
                 if (*p == '+') p++;
-                if (strncmp(p, "ip4:", 4) == 0) {
+                if (strncasecmp(p, "ip4:", 4) == 0) {
                     p += 4;
                     char *s = strchr(p, '/');
                     if (s) *s = '\0';
@@ -1243,10 +1243,10 @@
                         }
                     }
                 }
-                else if (strncmp(p, "all", 3) == 0) {
+                else if (strncasecmp(p, "all", 3) == 0) {
                     // ignore it before looking for (a or a:) below
                 }
-                else if (strncmp(p, "exists:", 7) == 0) {
+                else if (strncasecmp(p, "exists:", 7) == 0) {
                     p += 7;
                     char buf[maxdnslength];
                     dns_interface(*priv, p, ns_t_a, false, NULL, buf, maxdnslength);
@@ -1256,7 +1256,7 @@
                         return true;
                     }
                 }
-                else if (strncmp(p, "mx", 2) == 0) {
+                else if (strncasecmp(p, "mx", 2) == 0) {
                     const char *name = (p[2] == ':') ? p+3 : from;
                     char buf[maxdnslength];
                     dns_interface(*priv, name, ns_t_mx, false, NULL, buf, maxdnslength);
@@ -1295,23 +1295,23 @@
                         }
                     }
                 }
-                else if (priv->client_dns_name && (!priv->client_dns_forged) && (strncmp(p, "ptr", 3) == 0)) {
+                else if (priv->client_dns_name && (!priv->client_dns_forged) && (strncasecmp(p, "ptr", 3) == 0)) {
                     const char *name = (p[3] == ':') ? p+4 : from;
                     size_t n = strlen(name);
                     size_t d = strlen(priv->client_dns_name);
                     if (d >= n) {
-                        if ((strncmp(priv->client_dns_name+d-n, name, n) == 0) &&       // trailing part matches
+                        if ((strncasecmp(priv->client_dns_name+d-n, name, n) == 0) &&       // trailing part matches
                             ((d == n) || (priv->client_dns_name[d-n-1] == '.'))) {      // same length, or dot just before match
                             log(priv->queueid, "match ptr:%s", priv->client_dns_name);
                             return true;
                         }
                     }
                 }
-                else if ((level < 5) && (strncmp(p, "redirect=", 9) == 0)) {
+                else if ((level < 5) && (strncasecmp(p, "redirect=", 9) == 0)) {
                     p += 9;
                     if (resolve_one_spf(p, ip, priv, NULL, level+1)) return true;
                 }
-                else if ((level < 5) && (strncmp(p, "include:", 8) == 0)) {
+                else if ((level < 5) && (strncasecmp(p, "include:", 8) == 0)) {
                     p += 8;
                     if (resolve_one_spf(p, ip, priv, NULL, level+1)) return true;
                 }