From: Timo Sirainen Date: Sat, 28 Jan 2012 17:24:17 +0000 (+0200) Subject: smtp/lmtp client: If dns-client socket path isn't given, use blocking lookup. X-Git-Tag: 2.1.rc6~122 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4d406197fdf9bf6896aa8b0585ff74803ad45ff2;p=thirdparty%2Fdovecot%2Fcore.git smtp/lmtp client: If dns-client socket path isn't given, use blocking lookup. --- diff --git a/src/lib-lda/lmtp-client.c b/src/lib-lda/lmtp-client.c index 0ad7735b1e..6c7ac60743 100644 --- a/src/lib-lda/lmtp-client.c +++ b/src/lib-lda/lmtp-client.c @@ -538,6 +538,9 @@ int lmtp_client_connect_tcp(struct lmtp_client *client, const char *host, unsigned int port) { struct dns_lookup_settings dns_lookup_set; + struct ip_addr *ips; + unsigned int ips_count; + int ret; client->input_state = LMTP_INPUT_STATE_GREET; client->host = p_strdup(client->pool, host); @@ -554,14 +557,26 @@ int lmtp_client_connect_tcp(struct lmtp_client *client, client->set.dns_client_socket_path; dns_lookup_set.timeout_msecs = LMTP_CLIENT_DNS_LOOKUP_TIMEOUT_MSECS; - if (net_addr2ip(host, &client->ip) < 0) { - if (dns_lookup(host, &dns_lookup_set, - lmtp_client_dns_done, client) < 0) + if (net_addr2ip(host, &client->ip) == 0) { + /* IP address */ + } else if (dns_lookup_set.dns_client_socket_path == NULL) { + /* no dns-client, use blocking lookup */ + ret = net_gethostbyname(host, &ips, &ips_count); + if (ret != 0) { + i_error("lmtp client: DNS lookup of %s failed: %s", + client->host, net_gethosterror(ret)); return -1; + } + client->ip = ips[0]; } else { - if (lmtp_client_connect(client) < 0) + if (dns_lookup(host, &dns_lookup_set, + lmtp_client_dns_done, client) < 0) return -1; + return 0; } + + if (lmtp_client_connect(client) < 0) + return -1; return 0; }