diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2007-02-19 10:50:17 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2007-02-19 10:50:17 +0000 |
commit | f8d3c5b3f236ce32bff4ccb6d61d43d615851a94 (patch) | |
tree | dc7f2fd3e12677c60d9348e90250c69dcb449e44 /src/dnsbase.c | |
parent | 59570db68d1c94a36d82d4ede356880d2dcea0ef (diff) | |
download | mailfromd-f8d3c5b3f236ce32bff4ccb6d61d43d615851a94.tar.gz mailfromd-f8d3c5b3f236ce32bff4ccb6d61d43d615851a94.tar.bz2 |
Change calling convention for the interface functions (spf_query_t, spf_answer_t); fix IP address comparisons; implement builtin spf variables
git-svn-id: file:///svnroot/mailfromd/trunk@1255 7a8a7f39-df28-0410-adc6-e0d955640f24
Diffstat (limited to 'src/dnsbase.c')
-rw-r--r-- | src/dnsbase.c | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/src/dnsbase.c b/src/dnsbase.c index 203ce012..bf049c78 100644 --- a/src/dnsbase.c +++ b/src/dnsbase.c @@ -120,8 +120,8 @@ _getmx(const char *host, char *answer, size_t answer_size, mxbuf_t mxbuf, GETSHORT(type, cp); cp += INT16SZ; GETLONG(ttl, cp); - if (pttl && *pttl > ttl) - *pttl = ttl; + if (pttl) + UPDATE_TTL(*pttl, ttl); GETSHORT(n, cp); if (type != T_MX) { debug2(90,"unexpected answer type %d, size %d\n", @@ -358,8 +358,7 @@ cname_loop_body(struct loop_data *lp) GETSHORT(type, cp); cp += INT16SZ; /* skip over class */ GETLONG(ttl, cp); - if (lp->ttl > ttl) - lp->ttl = ttl; + UPDATE_TTL(lp->ttl, ttl); GETSHORT(n, cp); /* rdlength */ switch (type) { @@ -700,6 +699,7 @@ txt_lookup(const char *name, ld.atype = T_TXT; ld.name = xstrdup(name); ld.name_size = strlen(ld.name); + domainbuf[0] = 0; ld.domain = domainbuf; ld.domain_size = sizeof domainbuf; ld.answer = answer; @@ -738,32 +738,38 @@ spf_lookup(const char *domain, /* rfc4408, chapter 5.5 */ dns_status -ptr_validate(const char *ipstr, char ***vnptr, size_t *vcount) +ptr_validate(const char *ipstr, char ***vnptr, size_t *vcount, + unsigned long *pttl) { struct in_addr ip; char *names[11], **p; char *vnames[10]; size_t vi = 0; int status; + unsigned long minttl = ~(unsigned long)0; + unsigned long ttl; if (!inet_aton(ipstr, &ip)) return dns_failure; - status = ptr_lookup(ip, names, NELEMS(names), - NULL, NULL, 0); + status = ptr_lookup(ip, names, NELEMS(names), &ttl, NULL, 0); + if (status != dns_success) return status; + UPDATE_TTL(minttl, ttl); + for (p = names; *p; p++) { GACOPYZ_UINT32_T ipbuf[10]; size_t ipcount; status = a_lookup(*p, ipbuf, NELEMS(ipbuf), &ipcount, - NULL, NULL, 0); + &ttl, NULL, 0); if (status == dns_success && vi < NELEMS(vnames[0])) { size_t i; + UPDATE_TTL(minttl, ttl); for (i = 0; i < ipcount; i++) if (ipbuf[i] == ip.s_addr) { vnames[vi++] = *p; @@ -775,14 +781,19 @@ ptr_validate(const char *ipstr, char ***vnptr, size_t *vcount) free(*p); } - if (vi > 0 && vnptr) { - size_t i; + if (vi > 0) { + if (pttl) + *pttl = minttl; + if (vnptr) { + size_t i; - *vnptr = xcalloc(vi+1, sizeof vnptr[0]); - for (i = 0; i < vi; i++) - (*vnptr)[i] = vnames[i]; - (*vnptr)[i] = NULL; - *vcount = vi; + *vnptr = xcalloc(vi+1, sizeof vnptr[0]); + for (i = 0; i < vi; i++) + (*vnptr)[i] = vnames[i]; + (*vnptr)[i] = NULL; + *vcount = vi; + } } + return vi > 0 ? dns_success : dns_not_found; } |