30int match_ip4(
unsigned char ip1[4],
int prefix,
char ip2[4])
32 stralloc iptest1 = {0};
33 stralloc iptest2 = {0};
37 if (ip4_bytestring(&iptest1,ip1,prefix) == prefix)
38 if (ip4_bytestring(&iptest2,ip2,prefix) == prefix)
39 if (byte_diff(iptest1.s,prefix,iptest2.s))
return 0;
44int match_ip6(
unsigned char ip1[16],
int prefix,
char ip2[16])
46 stralloc iptest1 = {0};
47 stralloc iptest2 = {0};
51 if (ip6_bytestring(&iptest1,ip1,prefix) == prefix)
52 if (ip6_bytestring(&iptest2,ip2,prefix) == prefix)
53 if (byte_diff(iptest1.s,prefix,iptest2.s))
return 0;
70 if (!prefix || *prefix ==
'0') {
75 pos = scan_ulong(prefix,&r);
76 if (!pos || (prefix[pos] && !(prefix[pos] ==
'/')))
return SPF_SYNTAX;
95 static stralloc
out = {0};
96 static stralloc spf = {0};
104 r = dns_txt(&
out,(
const stralloc *)
domain);
112 for (
k = 0;
k <
out.len; ++
k) {
113 if (case_starts(
out.s +
k,
"v=spf1")) {
123 for (i = begin; i <
out.len; ++i) {
124 if (
out.s[i] ==
'\r' ||
out.s[i] ==
'\n' ||
out.s[i] ==
'\0')
break;
145int spf_a(
char *spfspec,
char *prefix)
155 if (!stralloc_readyplus(&ip,0))
return SPF_NOMEM;
160 switch (dns_ip4(&ip,&
sa)) {
166 for (
j = 0;
j + 4 <= ip.len;
j += 4)
171 switch (dns_ip6(&ip,&
sa)) {
177 for (
j = 0;
j + 16 <= ip.len;
j += 16)
196 unsigned long random;
203 random =
now() + (getpid() << 16);
213 for (
j = 0;
j <
ia.len; ++
j) {
240 int slen = str_len(spfspec);
256 if (pos > 0 &&
dnsname.s[pos - 1] !=
'.')
break;
257 if (case_diffb(
dnsname.s + pos,slen,spfspec))
break;
268 if (!stralloc_readyplus(&fqdn,255))
return SPF_NOMEM;
270 if (!stralloc_readyplus(&ip,32))
return SPF_NOMEM;
281 switch (dns_ip6(&ip,&
out)) {
286 for (
k = 0;
k + 16 <= ip.len;
k += 16) {
291 pos =
out.len - slen;
292 if (pos < 0)
continue;
293 if (pos > 0 &&
out.s[pos - 1] !=
'.')
continue;
294 if (case_diffb(
out.s + pos,slen,spfspec))
continue;
310 switch (dns_ip4(&ip,&
out)) {
315 for (
k = 0;
k + 4 <= ip.len;
k += 4) {
320 pos =
out.len - slen;
321 if (pos < 0)
continue;
322 if (pos > 0 &&
out.s[pos - 1] !=
'.')
continue;
323 if (case_diffb(
out.s + pos,slen,spfspec))
continue;
353 if (!ip4_scan(spfspec,spfip))
return SPF_SYNTAX;
376 if (!ip6_scan(spfspec,spfip))
return SPF_SYNTAX;
399 switch (dns_ip4(&ip,&
sa)) {
int stralloc_copys(stralloc *, char const *)
int dns_mxip(ipalloc *ia, stralloc *sa, unsigned long random)
int spf_info(char *, const char *)
int match_ip6(unsigned char ip1[16], int prefix, char ip2[16])
int spf_exists(char *spfspec, char *prefix)
spf_exists (exists; exists:fqdn) simply looks for a A records only for SPF info and client host
int spf_mx(char *spfspec, char *prefix)
spf_mx (mx; mx:domain; mx:domain/24) compares MX records for SPF info and client host
int get_prefix(char *prefix)
get_prefix return integer value of prefix length
int spf_ptr(char *spfspec, char *prefix)
spf_ptr (ptr; ptr:fqdn) compares PTR records from SPF info and client host
int spf_ip4(char *spfspec, char *prefix)
spf_ip4 (ip4; ip4:fqdn; ip4:fqdn/24) compares A records for SPF info and client host
int match_ip4(unsigned char ip1[4], int prefix, char ip2[4])
match_ip compares IPv4/IPv6 addreses up to prefix length
int spf_records(stralloc *spfrec, stralloc *domain)
spf_records get TXT records for domain and extract SPF information
int spf_ip6(char *spfspec, char *prefix)
spf_ip6 (ip6; ip6:fqdn; ip6:fqdn/56) compares AAAA records for SPF info and client host
int spf_a(char *spfspec, char *prefix)
spf_a (a; a:fqdns; a:fqdns/56) compares A + AAAA records for SPF info and client host