diff options
Diffstat (limited to 'rfc1035')
| -rw-r--r-- | rfc1035/spf.c | 62 | ||||
| -rw-r--r-- | rfc1035/testspf.c | 2 | ||||
| -rw-r--r-- | rfc1035/testsuite.txt | 1 |
3 files changed, 64 insertions, 1 deletions
diff --git a/rfc1035/spf.c b/rfc1035/spf.c index f811aad..7b9d40b 100644 --- a/rfc1035/spf.c +++ b/rfc1035/spf.c @@ -22,6 +22,7 @@ #include <time.h> #endif #endif +#include <idna.h> struct rfc1035_spf_info { const char *mailfrom; @@ -1313,8 +1314,69 @@ static int do_expand(const char *str, struct rfc1035_spf_info *info, static char *expandc(const char *ipaddr); static char *expandi(const char *ipaddr); +static char *get_macro2(struct rfc1035_spf_info *info, char name); + static char *get_macro(struct rfc1035_spf_info *info, char name) { + char *v=get_macro2(info, name); + char *p; + char *buf; + char *newbuf; + + if (!v) + return v; + + switch (name) { + case 's': + /* s = responsible-sender */ + + p=strrchr(v, '@'); + + /* Find domain, convert to ACE */ + if (!p || idna_to_ascii_8z(++p, &buf, 0) != IDNA_SUCCESS) + break; + + /* Buffer for local part + ACE domain */ + + newbuf=malloc(p-v+strlen(buf)+1); + + if (!newbuf) + { + free(buf); + break; + } + + /* Rebuild address with an ACE domain */ + + memcpy(newbuf, v, p-v); + strcpy(newbuf+(p-v), buf); + free(v); + v=newbuf; + free(buf); + break; + case 'o': + /* o = responsible-domain */ + case 'd': + /* d = current-domain */ + case 'p': + /* p = SMTP client domain name */ + case 'h': + /* h = HELO/EHLO domain */ + case 'r': + /* r = receiving domain */ + + if (idna_to_ascii_8z(v, &buf, 0) == IDNA_SUCCESS) + { + free(v); + v=buf; + } + } + + return v; +} + +static char *get_macro2(struct rfc1035_spf_info *info, char name) +{ char *p; const char *cp; diff --git a/rfc1035/testspf.c b/rfc1035/testspf.c index a28482f..aad9567 100644 --- a/rfc1035/testspf.c +++ b/rfc1035/testspf.c @@ -23,6 +23,7 @@ static struct testsuite_s { {"spf3.email-scan.com","192.168.1.10","spf1.email-scan.com","spf1","example.com"}, {"spf3.email-scan.com","191.168.2.10","spf1.email-scan.com","spf3.test","example.com"}, {"spf3.email-scan.com","1234:5678::9ABC","spf1.email-scan.com","spf1","example.com"}, + {"spf3.испытание.email-scan.com","1234:5678::9ABC","испытание.email-scan.com","испытание.email-scan.com","испытание.email-scan.com"}, {"spf4.email-scan.com","192.168.2.10","spf1.email-scan.com","10-1-168-192","example.com"}, {"spf5.email-scan.com","::ffff:192.168.1.0","spf5.email-scan.com","helo","example.com"}, {"spf5.email-scan.com","::ffff:192.168.1.1","spf5.email-scan.com","helo","example.com"}, @@ -117,4 +118,3 @@ int main(int argc, char **argv) return testspf(argv[1], argv[2], argv[3], argv[4], argv[5]); } - diff --git a/rfc1035/testsuite.txt b/rfc1035/testsuite.txt index aa98c1a..c500184 100644 --- a/rfc1035/testsuite.txt +++ b/rfc1035/testsuite.txt @@ -3,6 +3,7 @@ fail: Address does not pass the Sender Policy Framework pass fail: Error: l:postmaster, s:postmaster@spf3.email-scan.com, o:spf3.email-scan.com, d:spf3.email-scan.com, c:191.168.2.10, i:191.168.2.10, p:spf1.email-scan.com, v:in-addr, h:spf3.test, r:example.com, H:spf3%2Etest fail: Error: l:postmaster, s:postmaster@spf3.email-scan.com, o:spf3.email-scan.com, d:spf3.email-scan.com, c:1234:5678::9ABC, i:1.2.3.4.5.6.7.8.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.9.a.b.c, p:spf1.email-scan.com, v:ip6, h:spf1, r:example.com, H:spf1 +fail: Error: l:postmaster, s:postmaster@spf3.xn--80akhbyknj4f.email-scan.com, o:spf3.xn--80akhbyknj4f.email-scan.com, d:spf3.xn--80akhbyknj4f.email-scan.com, c:1234:5678::9ABC, i:1.2.3.4.5.6.7.8.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.9.a.b.c, p:xn--80akhbyknj4 pass pass fail: Address does not pass the Sender Policy Framework |
