[exim-dev] [PATCH] Add support for SPF records in dnsdb look…

Página superior
Eliminar este mensaje
Responder a este mensaje
Autor: Janne Snabb
Fecha:  
A: exim-dev
Asunto: [exim-dev] [PATCH] Add support for SPF records in dnsdb lookups
Hi,

How about adding support for SPF record in dnsdb lookups?

I think the attached patch should do it. It handles SPF records
identically to TXT records.

--
Janne Snabb / EPIPE Communications
snabb@??? - http://epipe.com/


diff --git a/doc/doc-docbook/spec.xfpt b/doc/doc-docbook/spec.xfpt
index 0815c0e..500a82d 100644
--- a/doc/doc-docbook/spec.xfpt
+++ b/doc/doc-docbook/spec.xfpt
@@ -6756,8 +6756,8 @@ is used on its own as the result. If the lookup does not succeed, the
&`fail`& keyword causes a &'forced expansion failure'& &-- see section
&<<SECTforexpfai>>& for an explanation of what this means.

-The supported DNS record types are A, CNAME, MX, NS, PTR, SRV, and TXT, and,
-when Exim is compiled with IPv6 support, AAAA (and A6 if that is also
+The supported DNS record types are A, CNAME, MX, NS, PTR, SPF, SRV, and TXT,
+and, when Exim is compiled with IPv6 support, AAAA (and A6 if that is also
configured). If no type is given, TXT is assumed. When the type is PTR,
the data can be an IP address, written as normal; inversion and the addition of
&%in-addr.arpa%& or &%ip6.arpa%& happens automatically. For example:
@@ -6785,10 +6785,10 @@ ${lookup dnsdb{>: a=host1.example}}
It is permitted to specify a space as the separator character. Further
white space is ignored.

-.cindex "TXT record" "in &(dnsdb)& lookup"
-For TXT records with multiple items of data, only the first item is returned,
+.cindex "TXT and SPF records" "in &(dnsdb)& lookup"
+For TXT and SPF records with multiple items of data, only the first item is returned,
 unless a separator for them is specified using a comma after the separator
-character followed immediately by the TXT record item separator. To concatenate
+character followed immediately by the TXT/SPF record item separator. To concatenate
 items without a separator, use a semicolon instead.
 .code
 ${lookup dnsdb{>\n,: txt=a.b.example}}
diff --git a/doc/doc-txt/NewStuff b/doc/doc-txt/NewStuff
index ad17304..7f302e7 100644
--- a/doc/doc-txt/NewStuff
+++ b/doc/doc-txt/NewStuff
@@ -71,9 +71,12 @@ Version 4.78
     "socket activation", but forcing the activated socket to fd 0.  We're
     interested in adding more support for modern variants.


-10. ${eval } now uses 64-bit values on supporting platforms.  A new "G" suffux
+10. ${eval } now uses 64-bit values on supporting platforms.  A new "G" suffix
     for numbers indicates multiplication by 1024^3.


+11. ${lookup dnsdb{ }} supports now SPF record types. They are handled
+    identically to TXT record lookups.
+


 Version 4.77
 ------------
diff --git a/src/src/dns.c b/src/src/dns.c
index c903d0b..d521490 100644
--- a/src/src/dns.c
+++ b/src/src/dns.c
@@ -415,6 +415,7 @@ switch(t)
   case T_AAAA:  return US"AAAA";
   case T_A6:    return US"A6";
   case T_TXT:   return US"TXT";
+  case T_SPF:   return US"SPF";
   case T_PTR:   return US"PTR";
   case T_SOA:   return US"SOA";
   case T_SRV:   return US"SRV";
diff --git a/src/src/exim.h b/src/src/exim.h
index e6e72fa..a32898e 100644
--- a/src/src/exim.h
+++ b/src/src/exim.h
@@ -295,6 +295,12 @@ header files. I don't suppose they have T_SRV either. */
 #define T_SRV 33
 #endif


+/* Many systems do not have T_SPF. */
+
+#ifndef T_SPF
+#define T_SPF 99
+#endif
+
/* It seems that some versions of arpa/nameser.h don't define *any* of the
T_xxx macros, which seem to be non-standard nowadays. Just to be on the safe
side, put in definitions for all the ones that Exim uses. */
diff --git a/src/src/lookups/dnsdb.c b/src/src/lookups/dnsdb.c
index 2862a5b..6848317 100644
--- a/src/src/lookups/dnsdb.c
+++ b/src/src/lookups/dnsdb.c
@@ -17,6 +17,11 @@ 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 const char *type_names[] = {
@@ -33,6 +38,7 @@ static const char *type_names[] = {
   "mxh",
   "ns",
   "ptr",
+  "spf",
   "srv",
   "txt",
   "zns"
@@ -52,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" */
@@ -316,7 +323,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)
         {