summaryrefslogtreecommitdiffabout
path: root/src
authorSergey Poznyakoff <gray@gnu.org.ua>2017-10-20 15:36:47 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2017-10-20 15:36:47 (GMT)
commitef49628b07df9ddb5f6035fc4941a10136a73b22 (patch) (side-by-side diff)
tree50c3ae5ae4eb565c2a6736f3e691ba98b5abd66e /src
parent91217d82391e4480fa7f72b7bc66a7bc53a9c3dd (diff)
downloadmailfromd-ef49628b07df9ddb5f6035fc4941a10136a73b22.tar.gz
mailfromd-ef49628b07df9ddb5f6035fc4941a10136a73b22.tar.bz2
Bugfixes; implement test program for DNS API.
* lib/dns.c (ptr_lookup): Reverse IP octets prior to look up. Use adns_r_ptr_raw to disable consistency checks. (ptr_validate): Return values in struct dns_reply. All uses changed. * lib/dns.h (ptr_validate): Change signature. * tests/resolv.c: New test program. * tests/Makefile.am: Add resolv.c * tests/.gitignore: Update.
Diffstat (limited to 'src') (more/less context) (ignore whitespace changes)
-rw-r--r--src/builtin/dns.bi20
-rw-r--r--src/spf.c34
2 files changed, 26 insertions, 28 deletions
diff --git a/src/builtin/dns.bi b/src/builtin/dns.bi
index f63a236..4bde967 100644
--- a/src/builtin/dns.bi
+++ b/src/builtin/dns.bi
@@ -169,10 +169,10 @@ END
MF_DEFUN(getmx, STRING, STRING domain, OPTIONAL, NUMBER no_resolve)
{
mf_status mxstat;
- struct dns_reply repl;
+ struct dns_reply reply;
if (MF_OPTVAL(no_resolve)) {
- mxstat = getmxip(domain, &repl);
+ mxstat = getmxip(domain, &reply);
if (!mf_resolved(mxstat)) {
MF_THROW(mf_status_to_exception(mxstat),
_("cannot get MX records for %s"), domain);
@@ -183,20 +183,20 @@ MF_DEFUN(getmx, STRING, STRING domain, OPTIONAL, NUMBER no_resolve)
int i;
MF_OBSTACK_BEGIN();
- for (i = 0; i < repl.count; i++) {
+ for (i = 0; i < reply.count; i++) {
struct in_addr s;
- s.s_addr = htonl(repl.data.ip[i]);
+ s.s_addr = htonl(reply.data.ip[i]);
if (i > 0)
MF_OBSTACK_1GROW(' ');
MF_OBSTACK_GROW(inet_ntoa(s));
}
MF_OBSTACK_1GROW(0);
- dns_reply_free(&repl);
+ dns_reply_free(&reply);
MF_RETURN_OBSTACK();
}
} else {
- mxstat = getmx(domain, &repl);
+ mxstat = getmx(domain, &reply);
if (!mf_resolved(mxstat)) {
MF_THROW(mf_status_to_exception(mxstat),
_("cannot get MX records for %s"), domain);
@@ -207,13 +207,13 @@ MF_DEFUN(getmx, STRING, STRING domain, OPTIONAL, NUMBER no_resolve)
int i;
MF_OBSTACK_BEGIN();
- for (i = 0; i < repl.count; i++) {
+ for (i = 0; i < reply.count; i++) {
if (i > 0)
MF_OBSTACK_1GROW(' ');
- MF_OBSTACK_GROW(repl.data.str[i]);
+ MF_OBSTACK_GROW(reply.data.str[i]);
}
MF_OBSTACK_1GROW(0);
- dns_reply_free(&repl);
+ dns_reply_free(&reply);
MF_RETURN_OBSTACK();
}
}
@@ -286,7 +286,7 @@ END
MF_DEFUN(ptr_validate, NUMBER, STRING s)
{
int rc, res;
- switch (rc = ptr_validate(s, NULL, NULL)) {
+ switch (rc = ptr_validate(s, NULL)) {
case dns_success:
res = 1;
break;
diff --git a/src/spf.c b/src/spf.c
index 0b570a0..87a158a 100644
--- a/src/spf.c
+++ b/src/spf.c
@@ -334,32 +334,31 @@ spf_expand_do(struct spf_data *dat, int allow_exp, const char **pptr)
int rc;
size_t i;
char *name = NULL;
- char **vnames;
- size_t vcount;
- dns_status status = ptr_validate(dat->q.ipstr,
- &vnames, &vcount);
+ struct dns_reply reply;
+ dns_status status = ptr_validate(dat->q.ipstr, &reply);
if (status != dns_success)
return spf_transform(dat, "unknown", 0, pptr);
- for (i = 0; i < vcount; i++)
- if (strcasecmp(vnames[i], dat->q.domain) == 0) {
- name = vnames[i];
+ for (i = 0; i < reply.count; i++)
+ if (strcasecmp(reply.data.str[i], dat->q.domain) == 0) {
+ name = reply.data.str[i];
break;
}
if (!name) {
- for (i = 0; i < vcount; i++)
- if (domain_match(vnames[i], dat->q.domain)) {
- name = vnames[i];
+ for (i = 0; i < reply.count; i++)
+ if (domain_match(reply.data.str[i],
+ dat->q.domain)) {
+ name = reply.data.str[i];
break;
}
if (!name)
- name = vnames[0];
+ name = reply.data.str[0];
}
rc = spf_transform(dat, name, 0, pptr);
- mu_argcv_free(vcount, vnames);
+ dns_reply_free(&reply);
return rc;
}
@@ -698,8 +697,7 @@ mech_mx(spf_data *dat, spf_term_arg *arg, unsigned long masklen)
static spf_term_result
mech_ptr(spf_data *dat, spf_term_arg *arg, unsigned long masklen)
{
- char **vnames;
- size_t vcount;
+ struct dns_reply reply;
size_t i;
const char *domain_spec;
spf_term_result result = spf_term_nomatch;
@@ -709,14 +707,14 @@ mech_ptr(spf_data *dat, spf_term_arg *arg, unsigned long masklen)
else
domain_spec = dat->q.domain;
- DNS_CATCH(ptr_validate(dat->q.ipstr, &vnames, &vcount));
+ DNS_CATCH(ptr_validate(dat->q.ipstr, &reply));
- for (i = 0; i < vcount; i++)
- if (domain_match(vnames[i], domain_spec)) {
+ for (i = 0; i < reply.count; i++)
+ if (domain_match(reply.data.str[i], domain_spec)) {
result = spf_term_match;
break;
}
- mu_argcv_free(vcount, vnames);
+ dns_reply_free(&reply);
return result;
}

Return to:

Send suggestions and report system problems to the System administrator.