Withdraw A6 DNS record support
[exim.git] / src / src / lookups / dnsdb.c
index 5c077fb3151c4e32287ca9a8d9f5edd6baf536f1..1e8df3b169e51d13dc610b15574dc625bc86dd1d 100644 (file)
@@ -34,9 +34,6 @@ static const char *type_names[] = {
 #if HAVE_IPV6
   "a+",
   "aaaa",
-  #ifdef SUPPORT_A6
-  "a6",
-  #endif
 #endif
   "cname",
   "csa",
@@ -54,11 +51,8 @@ static const char *type_names[] = {
 static int type_values[] = {
   T_A,
 #if HAVE_IPV6
-  T_APL,     /* Private type for AAAA + A */
+  T_ADDRESSES,     /* Private type for AAAA + A */
   T_AAAA,
-  #ifdef SUPPORT_A6
-  T_A6,
-  #endif
 #endif
   T_CNAME,
   T_CSA,     /* Private type for "Client SMTP Authorization". */
@@ -127,7 +121,7 @@ which may start with '<' in order to set a specific separator. The default
 separator, as always, is colon. */
 
 static int
-dnsdb_find(void *handle, uschar *filename, uschar *keystring, int length,
+dnsdb_find(void *handle, uschar *filename, const uschar *keystring, int length,
   uschar **result, uschar **errmsg, BOOL *do_cache)
 {
 int rc;
@@ -138,8 +132,8 @@ int defer_mode = PASS;
 int dnssec_mode = OK;
 int type;
 int failrc = FAIL;
-uschar *outsep = US"\n";
-uschar *outsep2 = NULL;
+const uschar *outsep = CUS"\n";
+const uschar *outsep2 = NULL;
 uschar *equals, *domain, *found;
 uschar buffer[256];
 
@@ -295,10 +289,15 @@ if (type == T_PTR && keystring[0] != '<' &&
 /* SPF strings should be concatenated without a separator, thus make
 it the default if not defined (see RFC 4408 section 3.1.3).
 Multiple SPF records are forbidden (section 3.1.2) but are currently
-not handled specially, thus they are concatenated with \n by default. */
+not handled specially, thus they are concatenated with \n by default.
+MX priority and value are space-separated by default.
+SRV and TLSA record parts are space-separated by default. */
 
-if (type == T_SPF && outsep2 == NULL)
-  outsep2 = US"";
+if (!outsep2) switch(type)
+  {
+  case T_SPF:                         outsep2 = US"";  break;
+  case T_SRV: case T_MX: case T_TLSA: outsep2 = US" "; break;
+  }
 
 /* Now scan the list and do a lookup for each item */
 
@@ -328,9 +327,9 @@ while ((domain = string_nextinlist(&keystring, &sep, buffer, sizeof(buffer)))
     DEBUG(D_lookup) debug_printf("dnsdb key: %s\n", domain);
 
     /* Do the lookup and sort out the result. There are four special types that
-    are handled specially: T_CSA, T_ZNS, T_APL and T_MXH.
+    are handled specially: T_CSA, T_ZNS, T_ADDRESSES and T_MXH.
     The first two are handled in a special lookup function so that the facility
-    could be used from other parts of the Exim code. T_APL is handled by looping
+    could be used from other parts of the Exim code. T_ADDRESSES is handled by looping
     over the types of A lookup.  T_MXH affects only what happens later on in
     this function, but for tidiness it is handled by the "special". If the
     lookup fails, continue with the next domain. In the case of DEFER, adjust
@@ -338,27 +337,23 @@ while ((domain = string_nextinlist(&keystring, &sep, buffer, sizeof(buffer)))
 
     found = domain;
 #if HAVE_IPV6
-    if (type == T_APL)         /* NB cannot happen unless HAVE_IPV6 */
+    if (type == T_ADDRESSES)           /* NB cannot happen unless HAVE_IPV6 */
       {
-      if (searchtype == T_APL)
-# if defined(SUPPORT_A6)
-                                     searchtype = T_A6;
-# else
-                                     searchtype = T_AAAA;
-# endif
-      else if (searchtype == T_A6)   searchtype = T_AAAA;
+      if (searchtype == T_ADDRESSES) searchtype = T_AAAA;
       else if (searchtype == T_AAAA) searchtype = T_A;
-      rc = dns_special_lookup(&dnsa, domain, searchtype, &found);
+      rc = dns_special_lookup(&dnsa, domain, searchtype, CUSS &found);
       }
     else
 #endif
-      rc = dns_special_lookup(&dnsa, domain, type, &found);
+      rc = dns_special_lookup(&dnsa, domain, type, CUSS &found);
 
     lookup_dnssec_authenticated = dnssec_mode==OK ? NULL
       : dns_is_secure(&dnsa) ? US"yes" : US"no";
 
     if (rc == DNS_NOMATCH || rc == DNS_NODATA) continue;
-    if (rc != DNS_SUCCEED)
+    if (  rc != DNS_SUCCEED
+       || (dnssec_mode == DEFER && !dns_is_secure(&dnsa))
+       )
       {
       if (defer_mode == DEFER)
        {
@@ -368,11 +363,6 @@ while ((domain = string_nextinlist(&keystring, &sep, buffer, sizeof(buffer)))
       if (defer_mode == PASS) failrc = DEFER;         /* defer only if all do */
       continue;                                       /* treat defer as fail */
       }
-    if (dnssec_mode == DEFER && !dns_is_secure(&dnsa))
-      {
-      failrc = DEFER;
-      continue;
-      }
 
 
     /* Search the returned records */
@@ -387,12 +377,7 @@ while ((domain = string_nextinlist(&keystring, &sep, buffer, sizeof(buffer)))
       separator between them, just as for between several records. However, A6
       support is not normally configured these days. */
 
-      if (type == T_A ||
-          #ifdef SUPPORT_A6
-          type == T_A6 ||
-          #endif
-          type == T_AAAA ||
-         type == T_APL)
+      if (type == T_A || type == T_AAAA || type == T_ADDRESSES)
         {
         dns_address *da;
         for (da = dns_address_from_rr(&dnsa, rr); da != NULL; da = da->next)
@@ -445,7 +430,8 @@ while ((domain = string_nextinlist(&keystring, &sep, buffer, sizeof(buffer)))
         matching_type = *p++;
         /* What's left after removing the first 3 bytes above */
         payload_length = rr->size - 3;
-        sp += sprintf(CS s, "%d %d %d ", usage, selector, matching_type);
+        sp += sprintf(CS s, "%d%c%d%c%d%c", usage, *outsep2,
+               selector, *outsep2, matching_type, *outsep2);
         /* Now append the cert/identifier, one hex char at a time */
         for (i=0;
              i < payload_length && sp-s < (MAX_TLSA_EXPANDED_SIZE - 4);
@@ -469,7 +455,7 @@ while ((domain = string_nextinlist(&keystring, &sep, buffer, sizeof(buffer)))
         else if (type == T_MX)
           {
           GETSHORT(priority, p);
-          sprintf(CS s, "%d ", priority);
+          sprintf(CS s, "%d%c", priority, *outsep2);
           yield = string_cat(yield, &size, &ptr, s, Ustrlen(s));
           }
         else if (type == T_SRV)
@@ -477,7 +463,8 @@ while ((domain = string_nextinlist(&keystring, &sep, buffer, sizeof(buffer)))
           GETSHORT(priority, p);
           GETSHORT(weight, p);
           GETSHORT(port, p);
-          sprintf(CS s, "%d %d %d ", priority, weight, port);
+          sprintf(CS s, "%d%c%d%c%d%c", priority, *outsep2,
+                                       weight, *outsep2, port, *outsep2);
           yield = string_cat(yield, &size, &ptr, s, Ustrlen(s));
           }
         else if (type == T_CSA)
@@ -494,7 +481,7 @@ while ((domain = string_nextinlist(&keystring, &sep, buffer, sizeof(buffer)))
           the subdomain assertions in the port field, else analyse the direct
           authorization status in the weight field. */
 
-          if (found != domain)
+          if (Ustrcmp(found, domain) != 0)
             {
             if (port & 1) *s = 'X';         /* explicit authorization required */
             else *s = '?';                  /* no subdomain assertions here */
@@ -530,7 +517,7 @@ while ((domain = string_nextinlist(&keystring, &sep, buffer, sizeof(buffer)))
       }    /* Loop for list of returned records */
 
            /* Loop for set of A-lookupu types */
-    } while (type == T_APL && searchtype != T_A);
+    } while (type == T_ADDRESSES && searchtype != T_A);
 
   }        /* Loop for list of domains */