]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
smtp/lmtp client: If dns-client socket path isn't given, use blocking lookup.
authorTimo Sirainen <tss@iki.fi>
Sat, 28 Jan 2012 17:24:17 +0000 (19:24 +0200)
committerTimo Sirainen <tss@iki.fi>
Sat, 28 Jan 2012 17:24:17 +0000 (19:24 +0200)
src/lib-lda/lmtp-client.c

index 0ad7735b1ec766b6e8e85acafcdbfae53da02868..6c7ac607437e24264aaa63e19132f6a68e1526ee 100644 (file)
@@ -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;
 }