summaryrefslogtreecommitdiffabout
path: root/src
authorSergey Poznyakoff <gray@gnu.org.ua>2017-10-20 10:23:47 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2017-10-20 11:35:20 (GMT)
commit5cf28509ada303e8995113af9390d10553c60bef (patch) (side-by-side diff)
tree6ef3c94ee4bf7350f8a3d26331ae4d0c260ccf11 /src
parent04a44fafaa2baf0be206a457febca5540b7e3f4a (diff)
downloadmailfromd-5cf28509ada303e8995113af9390d10553c60bef.tar.gz
mailfromd-5cf28509ada303e8995113af9390d10553c60bef.tar.bz2
Rewrite base dns functions using adns.
* configure.ac: Require libadns. * lib/dns.c: Rewrite. * lib/dns.h (dns_resolve_ipstr, dns_resolve_hostname): Simplify parameters. (dns_reply): Remove max, last_len, and last_max.
Diffstat (limited to 'src') (more/less context) (ignore whitespace changes)
-rw-r--r--src/builtin/dns.bi12
-rw-r--r--src/spf.c26
2 files changed, 10 insertions, 28 deletions
diff --git a/src/builtin/dns.bi b/src/builtin/dns.bi
index 137cccc..c23aaf3 100644
--- a/src/builtin/dns.bi
+++ b/src/builtin/dns.bi
@@ -61,8 +61,8 @@ END
static int
ipaddr_cmp(const void *a, const void *b)
{
- GACOPYZ_UINT32_T ipa = ntohl(**(GACOPYZ_UINT32_T**)a);
- GACOPYZ_UINT32_T ipb = ntohl(**(GACOPYZ_UINT32_T**)b);
+ GACOPYZ_UINT32_T ipa = ntohl(*(GACOPYZ_UINT32_T*)a);
+ GACOPYZ_UINT32_T ipb = ntohl(*(GACOPYZ_UINT32_T*)b);
if (ipa < ipb)
return -1;
if (ipa > ipb)
@@ -80,12 +80,12 @@ MF_DEFUN(dns_getaddr, STRING, STRING string)
switch (dnstat) {
case dns_success: {
MF_OBSTACK_BEGIN();
- qsort(r.base, r.count, sizeof r.base[0], ipaddr_cmp);
+ qsort(r.data.ip, r.count, sizeof r.data.ip[0], ipaddr_cmp);
for (i = 0; i < r.count; i++) {
struct in_addr addr;
char *q;
- addr.s_addr = dns_reply_ip(&r, i);
+ addr.s_addr = r.data.ip[i];
q = inet_ntoa(addr);
if (i > 0)
MF_OBSTACK_1GROW(' ');
@@ -125,13 +125,13 @@ MF_DEFUN(dns_getname, STRING, STRING ipstr)
case dns_success: {
size_t i;
- qsort(r.base, r.count, sizeof r.base[0], hostname_cmp);
+ qsort(r.data.str, r.count, sizeof r.data.str[0], hostname_cmp);
MF_OBSTACK_BEGIN();
for (i = 0; i < r.count; i++) {
if (i > 0)
MF_OBSTACK_1GROW(' ');
- MF_OBSTACK_GROW((char*)r.base[i]);
+ MF_OBSTACK_GROW((char*)r.data.str[i]);
}
MF_OBSTACK_1GROW(0);
diff --git a/src/spf.c b/src/spf.c
index edec1d4..05fbd53 100644
--- a/src/spf.c
+++ b/src/spf.c
@@ -641,7 +641,7 @@ mech_a(spf_data *dat, spf_term_arg *arg, unsigned long masklen)
res = spf_term_nomatch;
for (i = 0; i < r.count; i++) {
- if (ntohl(dns_reply_ip(&r, i) & netmask) == addr.s_addr) {
+ if (ntohl(r.data.ip[i] & netmask) == addr.s_addr) {
res = spf_term_match;
break;
}
@@ -807,7 +807,7 @@ mod_exp(spf_data *dat, spf_term_arg *arg, unsigned long masklen)
char *text;
for (i = 0; i < r.count; i++) {
- mu_opool_appendz(dat->tmpool, r.base[i]);
+ mu_opool_appendz(dat->tmpool, r.data.str[i]);
}
dns_reply_free(&r);
mu_opool_append_char(dat->tmpool, 0);
@@ -1195,9 +1195,6 @@ spf_test_record(const char *rec, spf_query_t *q, spf_answer_t *a)
spf_result
spf_check_host_internal(spf_query_t *q, spf_answer_t *a, size_t loopno)
{
- char **txt_rec;
- size_t txt_num;
- int i;
char *spf_rec = NULL;
struct spf_data dat;
spf_result result;
@@ -1224,7 +1221,7 @@ spf_check_host_internal(spf_query_t *q, spf_answer_t *a, size_t loopno)
if (strlen(q->domain) > 63)
SPF_RETURN(spf_none, "domain too long");
- switch (spf_lookup(q->domain, &txt_rec, &txt_num)) {
+ switch (spf_lookup(q->domain, &spf_rec)) {
case dns_success:
break;
@@ -1237,21 +1234,6 @@ spf_check_host_internal(spf_query_t *q, spf_answer_t *a, size_t loopno)
SPF_RETURN(spf_temp_error, "DNS temporary failure");
}
- /* Select SPF1 records */
- for (i = 0; txt_rec[i]; i++) {
- if (memcmp(txt_rec[i], "v=spf1", 6) == 0
- && (txt_rec[i][6] == 0 || mu_isspace(txt_rec[i][6]))) {
- mu_debug(MF_SOURCE_SPF, MU_DEBUG_TRACE6,
- ("record: %s", txt_rec[i]));
- if (spf_rec) {
- SPF_RETURN(spf_perm_error,
- "too many SPF records published");
- }
- spf_rec = txt_rec[i];
- break;
- }
- }
-
mu_debug(MF_SOURCE_SPF, MU_DEBUG_TRACE0,
("SPF record: %s", spf_rec));
@@ -1261,7 +1243,7 @@ spf_check_host_internal(spf_query_t *q, spf_answer_t *a, size_t loopno)
result = spf_exec_query(spf_rec, &dat);
spf_data_free(&dat);
- mu_argcv_free(txt_num, txt_rec);
+ free(spf_rec);
SPF_RETURN(result, "");
}

Return to:

Send suggestions and report system problems to the System administrator.