diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2017-10-23 20:50:09 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2017-10-23 20:50:09 +0300 |
commit | 368a705fe49cc31857c08e357d42314b3d54b2b5 (patch) | |
tree | dbe8071907c0908737c42ca0d1566efbbbd21f58 /src/builtin/dns.bi | |
parent | 2f77b90a2d1e7a43f7d77f06c953142cb90146f4 (diff) | |
download | mailfromd-368a705fe49cc31857c08e357d42314b3d54b2b5.tar.gz mailfromd-368a705fe49cc31857c08e357d42314b3d54b2b5.tar.bz2 |
Improve DNS API; rewrite DNS testsuite.
* lib/dns.c (dnsbase_real_init): Take configuration text
as argument (can be NULL).
Enable adns debugging on trace9
(dnsbase_file_init): New function.
(dns_reply_init): New function.
(dns_reply_push): New function.
(soa_check): New function.
Rewrite all functions using dns_reply_init+dns_reply_push, as appropriate.
* lib/dns.h (dns_reply) <maxcount, data.ptr>: New members.
(dnsbase_real_init, dnsbase_file_init)
(dns_reply_init, soa_check): New protos.
* src/builtin/dns.bi (resolve_host): Rewrite to return all A records.
(dns_replies_intersect): New static function.
(primitive_ismx): Rewrite taking into account all A records.
* src/main.c: New option --resolv-conf-file (mostly for checking.
* tests/resolv.c: Change option handling, implement new options.
* tests/atlocal.in (MF_TOPDOMAIN,MF_NAMESERVER): New variables.
(at_resolv_conf): New function.
* tests/Makefile.am: Add new tests.
* tests/testsuite.at: Include new tests.
* tests/hasmx.at: Use dedicated MF test domains,
* tests/hostname.at: Likewise.
* tests/ismx.at: Likewise.
* tests/rescname.at: Likewise.
* tests/resolve.at: Likewise.
* tests/resolv_a.at: New test.
* tests/resolv_mx.at: Likewise.
* tests/resolv_ptr.at: Likewise.
* tests/resolv_ptr_val.at: Likewise.
* tests/resolv_spf.at: Likewise.
* tests/resolv_txt.at: Likewise.
Diffstat (limited to 'src/builtin/dns.bi')
-rw-r--r-- | src/builtin/dns.bi | 67 |
1 files changed, 30 insertions, 37 deletions
diff --git a/src/builtin/dns.bi b/src/builtin/dns.bi index 336d8f40..0b7bfdbc 100644 --- a/src/builtin/dns.bi +++ b/src/builtin/dns.bi @@ -203,59 +203,52 @@ MF_DEFUN(getmx, STRING, STRING domain, OPTIONAL, NUMBER resolve) } END -static int -resolve_host(const char *string, unsigned long *ip) +static dns_status +resolve_host(const char *string, struct dns_reply *reply) { - int rc; struct in_addr addr; - char *ipstr; if (inet_aton(string, &addr)) { - *ip = addr.s_addr; - return 0; + dns_reply_init(reply, dns_reply_ip, 1); + reply->data.ip[0] = addr.s_addr; + return dns_success; } - - if (resolve_hostname(string, &ipstr) != mf_success) - return 1; + return a_lookup(string, reply); +} - rc = inet_aton(ipstr, &addr); - free(ipstr); - if (rc == 0) { - mu_error(_("INTERNAL ERROR at %s:%d: resolve_hostname returned " - "invalid IP address: %s"), - __FILE__, __LINE__, ipstr); - return 1; +static int +dns_replies_intersect(struct dns_reply const *a, struct dns_reply const *b) +{ + int i, j; + + if (a->type == b->type && a->type == dns_reply_ip) { + for (i = 0; i < a->count; i++) + for (j = 0; j < b->count; j++) + if (a->data.ip[i] == b->data.ip[j]) + return 1; } - *ip = addr.s_addr; return 0; } MF_DEFUN(primitive_ismx, NUMBER, STRING domain, STRING ipstr) { - struct dns_reply reply; - mf_status mxstat; - unsigned long ip; + struct dns_reply areply, mxreply; + dns_status status; int rc = 0; - int i; - - MF_ASSERT(resolve_host(ipstr, &ip) == 0, mfe_noresolve, - _("cannot resolve host name %s"), ipstr); - ip = ntohl(ip); - - mxstat = dns_to_mf_status(mx_lookup(domain, 1, &reply)); - if (mxstat != mf_success) { - MF_THROW(mf_status_to_exception(mxstat), + status = resolve_host(ipstr, &areply); + MF_ASSERT(status == dns_success, + mf_status_to_exception(dns_to_mf_status(status)), + _("cannot resolve host name %s"), ipstr); + status = mx_lookup(domain, 1, &mxreply); + if (status != dns_success) { + dns_reply_free(&areply); + MF_THROW(mf_status_to_exception(dns_to_mf_status(status)), _("cannot get MXs for %s"), domain); } - - for (i = 0; i < reply.count; i++) { - if (reply.data.ip[i] == ip) { - rc = 1; - break; - } - } - dns_reply_free(&reply); + rc = dns_replies_intersect(&areply, &mxreply); + dns_reply_free(&areply); + dns_reply_free(&mxreply); MF_RETURN(rc); } END |