summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacek Masiulaniec <jacekm@cvs.openbsd.org>2009-11-11 16:55:19 +0000
committerJacek Masiulaniec <jacekm@cvs.openbsd.org>2009-11-11 16:55:19 +0000
commit007d01d41f95b61251c9834e840f660ee3b27b7c (patch)
treea833c65f08971a470772e3bb8c7ba4a65e464873
parent1925749e108d1798f9a10912440acac36be04943 (diff)
Fix previous. When configured to relay via IP address, MX lookup would fail
(NXDOMAIN), leading to a bounce. Precede the MX lookup with an attempt to parse the relay as numeric string. "reads ok" gilles@
-rw-r--r--usr.sbin/smtpd/dns.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/usr.sbin/smtpd/dns.c b/usr.sbin/smtpd/dns.c
index 749c0280902..63b08184bd8 100644
--- a/usr.sbin/smtpd/dns.c
+++ b/usr.sbin/smtpd/dns.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dns.c,v 1.18 2009/11/05 12:11:53 jsing Exp $ */
+/* $OpenBSD: dns.c,v 1.19 2009/11/11 16:55:18 jacekm Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -49,7 +49,7 @@ void parent_dispatch_dns(int, short, void *);
int dns(void);
void dns_dispatch_parent(int, short, void *);
-void lookup_a(struct imsgev *, struct dns *, int);
+void lookup_a(struct imsgev *, struct dns *, int, int);
void lookup_mx(struct imsgev *, struct dns *);
int get_mxlist(char *, char *, struct dns **);
void free_mxlist(struct dns *);
@@ -261,7 +261,7 @@ dns_dispatch_parent(int sig, short event, void *p)
switch (imsg.hdr.type) {
case IMSG_DNS_A:
- lookup_a(iev, imsg.data, 1);
+ lookup_a(iev, imsg.data, 0, 1);
break;
case IMSG_DNS_MX:
@@ -283,12 +283,13 @@ dns_dispatch_parent(int sig, short event, void *p)
}
void
-lookup_a(struct imsgev *iev, struct dns *query, int finalize)
+lookup_a(struct imsgev *iev, struct dns *query, int numeric, int finalize)
{
struct addrinfo *res0, *res, hints;
char *port = NULL;
- log_debug("lookup_a %s:%d", query->host, query->port);
+ log_debug("lookup_a %s:%d%s", query->host, query->port,
+ numeric ? " (numeric)" : "");
if (query->port && asprintf(&port, "%u", query->port) == -1)
fatal(NULL);
@@ -296,6 +297,8 @@ lookup_a(struct imsgev *iev, struct dns *query, int finalize)
bzero(&hints, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
+ if (numeric)
+ hints.ai_flags = AI_NUMERICHOST;
query->error = getaddrinfo(query->host, port, &hints, &res0);
if (query->error)
@@ -308,11 +311,10 @@ lookup_a(struct imsgev *iev, struct dns *query, int finalize)
freeaddrinfo(res0);
end:
free(port);
- if (finalize) {
- log_debug("lookup_a %s", query->error ? "failed" : "success");
+ log_debug("lookup_a %s", query->error ? "failed" : "success");
+ if (finalize)
imsg_compose_event(iev, IMSG_DNS_A_END, 0, 0, -1, query,
sizeof(*query));
- }
}
void
@@ -323,6 +325,12 @@ lookup_mx(struct imsgev *iev, struct dns *query)
log_debug("lookup_mx %s", query->host);
+ /* if ip address, skip MX lookup */
+ /* XXX: maybe do it just once in parse.y? */
+ lookup_a(iev, query, 1, 0);
+ if (!query->error)
+ goto end;
+
query->error = get_mxlist(query->host, query->env->sc_hostname, &mx0);
if (query->error)
goto end;
@@ -337,7 +345,7 @@ lookup_mx(struct imsgev *iev, struct dns *query)
for (mx = mx0; mx; mx = mx->next) {
mx->port = query->port;
mx->id = query->id;
- lookup_a(iev, mx, 0);
+ lookup_a(iev, mx, 0, 0);
if (!mx->error)
success++;
}