DNS: Better handling of SOA when negative-caching lookups
authorJeremy Harris <jgh146exb@wizmail.org>
Sat, 8 May 2021 22:07:34 +0000 (23:07 +0100)
committerJeremy Harris <jgh146exb@wizmail.org>
Sat, 8 May 2021 22:07:34 +0000 (23:07 +0100)
src/src/dns.c
src/src/string.c
test/stderr/0277
test/stderr/0469
test/stderr/2202

index 217fe5f87167637958fc0afa585a519d5088fb89..490eb883d3d53eaf85f33063fd2e7bf148e37c43 100644 (file)
@@ -730,37 +730,37 @@ dns_expire_from_soa(dns_answer * dnsa, int type)
 {
 dns_scan dnss;
 
-if (!fake_dnsa_len_for_fail(dnsa, type)) return 0;
+if (fake_dnsa_len_for_fail(dnsa, type))
+  for (dns_record * rr = dns_next_rr(dnsa, &dnss, RESET_AUTHORITY);
+       rr; rr = dns_next_rr(dnsa, &dnss, RESET_NEXT)
+      ) if (rr->type == T_SOA)
+    {
+    const uschar * p = rr->data;
+    uschar discard_buf[256];
+    int len;
+    unsigned long ttl;
+
+    /* Skip the mname & rname strings */
+
+    if ((len = dn_expand(dnsa->answer, dnsa->answer + dnsa->answerlen,
+       p, (DN_EXPAND_ARG4_TYPE)discard_buf, 256)) < 0)
+      break;
+    p += len;
+    if ((len = dn_expand(dnsa->answer, dnsa->answer + dnsa->answerlen,
+       p, (DN_EXPAND_ARG4_TYPE)discard_buf, 256)) < 0)
+      break;
+    p += len;
+
+    /* Skip the SOA serial, refresh, retry & expire.  Grab the TTL */
+
+    if (p > dnsa->answer + dnsa->answerlen - 5 * INT32SZ)
+      break;
+    p += 4 * INT32SZ;
+    GETLONG(ttl, p);
+
+    return time(NULL) + ttl;
+    }
 
-for (dns_record * rr = dns_next_rr(dnsa, &dnss, RESET_AUTHORITY);
-     rr; rr = dns_next_rr(dnsa, &dnss, RESET_NEXT)
-    ) if (rr->type == T_SOA)
-  {
-  const uschar * p = rr->data;
-  uschar discard_buf[256];
-  int len;
-  unsigned long ttl;
-
-  /* Skip the mname & rname strings */
-
-  if ((len = dn_expand(dnsa->answer, dnsa->answer + dnsa->answerlen,
-      p, (DN_EXPAND_ARG4_TYPE)discard_buf, 256)) < 0)
-    break;
-  p += len;
-  if ((len = dn_expand(dnsa->answer, dnsa->answer + dnsa->answerlen,
-      p, (DN_EXPAND_ARG4_TYPE)discard_buf, 256)) < 0)
-    break;
-  p += len;
-
-  /* Skip the SOA serial, refresh, retry & expire.  Grab the TTL */
-
-  if (p > dnsa->answer + dnsa->answerlen - 5 * INT32SZ)
-    break;
-  p += 4 * INT32SZ;
-  GETLONG(ttl, p);
-
-  return time(NULL) + ttl;
-  }
 DEBUG(D_dns) debug_printf("DNS: no SOA record found for neg-TTL\n");
 return 0;
 }
@@ -1205,18 +1205,7 @@ switch (type)
     If the TLD and the 2LD exist but the explicit CSA record lookup failed, then
     the AUTHORITY SOA will be the 2LD's or a subdomain thereof. */
 
-    if (rc == DNS_NOMATCH)
-      {
-      if (!fake_dnsa_len_for_fail(dnsa, T_CSA)) return DNS_NOMATCH;
-
-      for (rr = dns_next_rr(dnsa, &dnss, RESET_AUTHORITY);
-          rr; rr = dns_next_rr(dnsa, &dnss, RESET_NEXT)
-         )
-       if (rr->type != T_SOA) continue;
-       else if (strcmpic(rr->name, US"") == 0 ||
-                strcmpic(rr->name, tld) == 0) return DNS_NOMATCH;
-       else break;
-      }
+    if (rc == DNS_NOMATCH) return DNS_NOMATCH;
 
     for (i = 0; i < limit; i++)
       {
index fbb19537cba40fcf6d0302f82a66a9a6c0619253..cb913242092e28e3e267a871b69e388eb77d0c3e 100644 (file)
@@ -960,7 +960,7 @@ else
        && (g->ptr == 1 || g->s[g->ptr-2] != '\\') )
     g->ptr--;
   buffer = string_from_gstring(g);
-  gstring_release_unused_trc(g, func, line);
+  gstring_release_unused_trc(g, CCS func, line);
   }
 
 /* Update the current pointer and return the new string */
index 0cbd2a9874ddbc58d346b6455c0cb195238b7b5e..9f606b93264499786c484569e0efdaa754263b87 100644 (file)
@@ -19,6 +19,7 @@ DNS lookup of 4.3.2.V4NET.in-addr.arpa (PTR) using fakens
 DNS lookup of 4.3.2.V4NET.in-addr.arpa (PTR) gave HOST_NOT_FOUND
 returning DNS_NOMATCH
 DNS: couldn't fake dnsa len
+DNS: no SOA record found for neg-TTL
  writing neg-cache entry for 4.3.2.V4NET.in-addr.arpa-PTR-xxxx, ttl -1
 LOG: host_lookup_failed MAIN
   no host name found for IP address V4NET.2.3.4
@@ -97,6 +98,7 @@ DNS lookup of 12.11.10.V4NET.in-addr.arpa (PTR) using fakens
 DNS lookup of 12.11.10.V4NET.in-addr.arpa (PTR) gave HOST_NOT_FOUND
 returning DNS_NOMATCH
 DNS: couldn't fake dnsa len
+DNS: no SOA record found for neg-TTL
  writing neg-cache entry for 12.11.10.V4NET.in-addr.arpa-PTR-xxxx, ttl -1
 LOG: host_lookup_failed MAIN
   no host name found for IP address V4NET.10.11.12
@@ -142,6 +144,7 @@ DNS lookup of 1.1.1.V4NET.in-addr.arpa (PTR) using fakens
 DNS lookup of 1.1.1.V4NET.in-addr.arpa (PTR) gave HOST_NOT_FOUND
 returning DNS_NOMATCH
 DNS: couldn't fake dnsa len
+DNS: no SOA record found for neg-TTL
  writing neg-cache entry for 1.1.1.V4NET.in-addr.arpa-PTR-xxxx, ttl -1
 LOG: host_lookup_failed MAIN
   no host name found for IP address V4NET.1.1.1
@@ -187,6 +190,7 @@ DNS lookup of 2.2.2.V4NET.in-addr.arpa (PTR) using fakens
 DNS lookup of 2.2.2.V4NET.in-addr.arpa (PTR) gave HOST_NOT_FOUND
 returning DNS_NOMATCH
 DNS: couldn't fake dnsa len
+DNS: no SOA record found for neg-TTL
  writing neg-cache entry for 2.2.2.V4NET.in-addr.arpa-PTR-xxxx, ttl -1
 LOG: host_lookup_failed MAIN
   no host name found for IP address V4NET.2.2.2
index f3b559327237ad7470bfefeee5444e2ef1d17697..4f6d216d250fb7e05ef8b0cd0e5c169f12cb9535 100644 (file)
@@ -25,6 +25,7 @@ DNS lookup of dontqualify (A) using fakens
 DNS lookup of dontqualify (A) gave NO_DATA
 returning DNS_NODATA
 DNS: couldn't fake dnsa len
+DNS: no SOA record found for neg-TTL
  writing neg-cache entry for dontqualify-A-xxxx, ttl -1
 fully qualified name = mxt1c.test.ex
 host_find_bydns yield = HOST_FIND_FAILED (0); returned hosts:
index a7c78ea3aa7e2525a42edcf4aea7549071efb7e3..3ce137682477fa6a764c0476f1fa26102545c3e6 100644 (file)
@@ -43,6 +43,7 @@ DNS lookup of cioce.test.again.dns (MX) gave TRY_AGAIN
 cioce.test.again.dns in dns_again_means_nonexist? yes (matched "*")
 cioce.test.again.dns is in dns_again_means_nonexist: returning DNS_NOMATCH
 DNS: couldn't fake dnsa len
+DNS: no SOA record found for neg-TTL
  writing neg-cache entry for cioce.test.again.dns-MX-xxxx, ttl -1
  creating new cache entry
  lookup failed
@@ -66,6 +67,7 @@ DNS lookup of cioce.test.again.dns (A) gave TRY_AGAIN
 cioce.test.again.dns in dns_again_means_nonexist? yes (matched "*")
 cioce.test.again.dns is in dns_again_means_nonexist: returning DNS_NOMATCH
 DNS: couldn't fake dnsa len
+DNS: no SOA record found for neg-TTL
  writing neg-cache entry for cioce.test.again.dns-A-xxxx, ttl -1
 host_fake_gethostbyname(af=inet) returned 1 (HOST_NOT_FOUND)
 no IP address found for host cioce.test.again.dns (during SMTP connection from the.local.host.name [ip4.ip4.ip4.ip4])