diff options
author | Eric Faurot <eric@cvs.openbsd.org> | 2011-03-26 21:40:15 +0000 |
---|---|---|
committer | Eric Faurot <eric@cvs.openbsd.org> | 2011-03-26 21:40:15 +0000 |
commit | 3ac914959cc42d6cce45f37d1baf0894d6e882ce (patch) | |
tree | 3c743f548af640c786efde43b1deb5612d362161 /usr.sbin/smtpd | |
parent | d1acb624aed010b304b7cd5a115f16b366e0e13c (diff) |
Fix the MX lookup process:
- the MX records were not always properly inserted into the sorted
array, which led to some MX being silently dropped.
- if an MX address could not be resolved, mail delivery would fail,
even though other valid MX exist for that domain. Now only report
the failure if no server address can be found at all.
grrrreeat gilles@
Diffstat (limited to 'usr.sbin/smtpd')
-rw-r--r-- | usr.sbin/smtpd/dns.c | 56 |
1 files changed, 21 insertions, 35 deletions
diff --git a/usr.sbin/smtpd/dns.c b/usr.sbin/smtpd/dns.c index 38db61ff3df..e40b7a9dbe3 100644 --- a/usr.sbin/smtpd/dns.c +++ b/usr.sbin/smtpd/dns.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dns.c,v 1.33 2011/03/26 14:38:14 eric Exp $ */ +/* $OpenBSD: dns.c,v 1.34 2011/03/26 21:40:14 eric Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -279,6 +279,7 @@ dns_asr_handler(int fd, short event, void *arg) * * -- gilles@ */ + dnssession->mxfound = 0; dnssession->mxcurrent = 0; dnssession->aq = asr_query_host(asr, dnssession->mxarray[dnssession->mxcurrent].host, AF_UNSPEC); @@ -321,32 +322,22 @@ dns_asr_mx_handler(int fd, short event, void *arg) return; case ASR_YIELD: - case ASR_DONE: - break; - } - - query->error = EAI_AGAIN; - - if (ret == ASR_YIELD) { free(ar.ar_cname); memcpy(&query->ss, &ar.ar_sa.sa, ar.ar_sa.sa.sa_len); query->error = 0; imsg_compose_event(query->asker, IMSG_DNS_HOST, 0, 0, -1, query, sizeof(*query)); + dnssession->mxfound++; dns_asr_mx_handler(-1, -1, dnssession); return; - } - /* ASR_DONE */ - if (ar.ar_err) { - query->error = ar.ar_err; - goto end; + case ASR_DONE: + break; } - if (++dnssession->mxcurrent == dnssession->mxarraysz) { - query->error = 0; + if (++dnssession->mxcurrent == dnssession->mxarraysz) goto end; - } + dnssession->aq = asr_query_host(asr, dnssession->mxarray[dnssession->mxcurrent].host, AF_UNSPEC); if (dnssession->aq == NULL) @@ -355,6 +346,10 @@ dns_asr_mx_handler(int fd, short event, void *arg) return; end: + if (dnssession->mxfound == 0) + query->error = EAI_NONAME; + else + query->error = 0; imsg_compose_event(query->asker, IMSG_DNS_HOST_END, 0, 0, -1, query, sizeof(*query)); dnssession_destroy(env, dnssession); @@ -387,30 +382,21 @@ dnssession_destroy(struct smtpd *env, struct dnssession *dnssession) void dnssession_mx_insert(struct dnssession *dnssession, struct mx *mx) { - size_t i; - size_t j; + size_t i, j; - if (dnssession->mxarraysz > MAX_MX_COUNT) - dnssession->mxarraysz = MAX_MX_COUNT; + for (i = 0; i < dnssession->mxarraysz; i++) + if (mx->prio < dnssession->mxarray[i].prio) + break; - if (dnssession->mxarraysz == 0) { - dnssession->mxarray[0] = *mx; - dnssession->mxarraysz++; - return; - } + if (i == MAX_MX_COUNT) + return; - for (i = 0; i < dnssession->mxarraysz; ++i) - if (mx->prio < dnssession->mxarray[i].prio) - goto insert; + if (dnssession->mxarraysz < MAX_MX_COUNT) + dnssession->mxarraysz++; - if (i < MAX_MX_COUNT) - dnssession->mxarray[i] = *mx; - dnssession->mxarraysz++; - return; + for (j = dnssession->mxarraysz - 1; j > i; j--) + dnssession->mxarray[j] = dnssession->mxarray[j - 1]; -insert: - for (j = dnssession->mxarraysz; j > i; --j) - dnssession->mxarray[j] = dnssession->mxarray[j - 1]; dnssession->mxarray[i] = *mx; } |