Second SPF fix, moved to where type is correct.
[exim.git] / src / src / lookups / dnsdb.c
index 5c9f96b79873b890a3957d53b984c3bb0b55879d..0bbc86a56a6f4a2c44c6b15e8971876037af77c8 100644 (file)
@@ -1,10 +1,8 @@
-/* $Cambridge: exim/src/src/lookups/dnsdb.c,v 1.20 2010/05/29 19:23:26 nm4 Exp $ */
-
 /*************************************************
 *     Exim - an Internet mail transport agent    *
 *************************************************/
 
-/* Copyright (c) University of Cambridge 1995 - 2009 */
+/* Copyright (c) University of Cambridge 1995 - 2012 */
 /* See the file NOTICE for conditions of use and distribution. */
 
 #include "../exim.h"
@@ -19,9 +17,14 @@ header files. */
 #define T_TXT 16
 #endif
 
+/* Many systems do not have T_SPF. */
+#ifndef T_SPF
+#define T_SPF 99
+#endif
+
 /* Table of recognized DNS record types and their integer values. */
 
-static char *type_names[] = {
+static const char *type_names[] = {
   "a",
 #if HAVE_IPV6
   "aaaa",
@@ -35,6 +38,7 @@ static char *type_names[] = {
   "mxh",
   "ns",
   "ptr",
+  "spf",
   "srv",
   "txt",
   "zns"
@@ -54,6 +58,7 @@ static int type_values[] = {
   T_MXH,     /* Private type for "MX hostnames" */
   T_NS,
   T_PTR,
+  T_SPF,
   T_SRV,
   T_TXT,
   T_ZNS      /* Private type for "zone nameservers" */
@@ -91,7 +96,8 @@ separator is newline.
 character used for multiple items of text in "TXT" records. Alternatively,
 if the next character is ';' then these multiple items are concatenated with
 no separator. With neither of these options specified, only the first item
-is output.
+is output.  Similarly for "SPF" records, but the default for joining multiple
+items in one SPF record is the empty string, for direct concatenation.
 
 (c) If the next sequence of characters is 'defer_FOO' followed by a comma,
 the defer behaviour is set to FOO. The possible behaviours are: 'strict', where
@@ -116,7 +122,7 @@ int size = 256;
 int ptr = 0;
 int sep = 0;
 int defer_mode = PASS;
-int type = T_TXT;
+int type;
 int failrc = FAIL;
 uschar *outsep = US"\n";
 uschar *outsep2 = NULL;
@@ -192,8 +198,10 @@ if (strncmpic(keystring, US"defer_", 6) == 0)
   while (isspace(*keystring)) keystring++;
   }
 
-/* If the keystring contains an = this must be preceded by a valid type name. */
+/* Figure out the "type" value if it is not T_TXT.
+If the keystring contains an = this must be preceded by a valid type name. */
 
+type = T_TXT;
 if ((equals = Ustrchr(keystring, '=')) != NULL)
   {
   int i, len;
@@ -241,6 +249,14 @@ if (type == T_PTR && keystring[0] != '<' &&
     string_is_ip_address(keystring, NULL) != 0)
   sep = -1;
 
+/* 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. */
+
+if (type == T_SPF && outsep2 == NULL)
+  outsep2 = US"";
+
 /* Now scan the list and do a lookup for each item */
 
 while ((domain = string_nextinlist(&keystring, &sep, buffer, sizeof(buffer)))
@@ -318,7 +334,7 @@ while ((domain = string_nextinlist(&keystring, &sep, buffer, sizeof(buffer)))
 
     if (ptr != 0) yield = string_cat(yield, &size, &ptr, outsep, 1);
 
-    if (type == T_TXT)
+    if (type == T_TXT || type == T_SPF)
       {
       if (outsep2 == NULL)
         {
@@ -429,6 +445,25 @@ yield[ptr] = 0;
 return OK;
 }
 
+
+
+/*************************************************
+*         Version reporting entry point          *
+*************************************************/
+
+/* See local README for interface description. */
+
+#include "../version.h"
+
+void
+dnsdb_version_report(FILE *f)
+{
+#ifdef DYNLOOKUP
+fprintf(f, "Library version: DNSDB: Exim version %s\n", EXIM_VERSION_STR);
+#endif
+}
+
+
 static lookup_info _lookup_info = {
   US"dnsdb",                     /* lookup name */
   lookup_querystyle,             /* query style */
@@ -437,7 +472,8 @@ static lookup_info _lookup_info = {
   dnsdb_find,                    /* find function */
   NULL,                          /* no close function */
   NULL,                          /* no tidy function */
-  NULL                           /* no quoting function */
+  NULL,                          /* no quoting function */
+  dnsdb_version_report           /* version reporting */
 };
 
 #ifdef DYNLOOKUP