]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
pop3c: If base_dir isn't set, lookup pop3c_host with regular blocking DNS lookup.
authorTimo Sirainen <tss@iki.fi>
Mon, 8 Sep 2014 07:14:42 +0000 (10:14 +0300)
committerTimo Sirainen <tss@iki.fi>
Mon, 8 Sep 2014 07:14:42 +0000 (10:14 +0300)
src/lib-storage/index/pop3c/pop3c-client.c
src/lib-storage/index/pop3c/pop3c-storage.c

index 966daee9cf5c4662b2c8fb74c52a30d5fbb7a072..a4a78925694e684eeed43b38bafa448a9efde507 100644 (file)
@@ -67,6 +67,7 @@ struct pop3c_client {
 static void
 pop3c_dns_callback(const struct dns_lookup_result *result,
                   struct pop3c_client *client);
+static void pop3c_client_connect_ip(struct pop3c_client *client);
 
 struct pop3c_client *
 pop3c_client_init(const struct pop3c_client_settings *set)
@@ -196,6 +197,39 @@ static void pop3c_client_timeout(struct pop3c_client *client)
        pop3c_client_disconnect(client);
 }
 
+static int pop3c_client_dns_lookup(struct pop3c_client *client)
+{
+       struct dns_lookup_settings dns_set;
+
+       i_assert(client->state == POP3C_CLIENT_STATE_CONNECTING);
+
+       if (client->set.dns_client_socket_path[0] == '\0') {
+               struct ip_addr *ips;
+               unsigned int ips_count;
+               int ret;
+
+               ret = net_gethostbyname(client->set.host, &ips, &ips_count);
+               if (ret != 0) {
+                       i_error("pop3c(%s): net_gethostbyname() failed: %s",
+                               client->set.host, net_gethosterror(ret));
+                       return -1;
+               }
+               i_assert(ips_count > 0);
+               client->ip = ips[0];
+               pop3c_client_connect_ip(client);
+       } else {
+               memset(&dns_set, 0, sizeof(dns_set));
+               dns_set.dns_client_socket_path =
+                       client->set.dns_client_socket_path;
+               dns_set.timeout_msecs = POP3C_DNS_LOOKUP_TIMEOUT_MSECS;
+               if (dns_lookup(client->set.host, &dns_set,
+                              pop3c_dns_callback, client,
+                              &client->dns_lookup) < 0)
+                       return -1;
+       }
+       return 0;
+}
+
 void pop3c_client_run(struct pop3c_client *client)
 {
        struct ioloop *ioloop, *prev_ioloop = current_ioloop;
@@ -210,16 +244,7 @@ void pop3c_client_run(struct pop3c_client *client)
        if (client->ip.family == 0) {
                /* we're connecting, start DNS lookup after our ioloop
                   is created */
-               struct dns_lookup_settings dns_set;
-
-               i_assert(client->state == POP3C_CLIENT_STATE_CONNECTING);
-               memset(&dns_set, 0, sizeof(dns_set));
-               dns_set.dns_client_socket_path =
-                       client->set.dns_client_socket_path;
-               dns_set.timeout_msecs = POP3C_DNS_LOOKUP_TIMEOUT_MSECS;
-               if (dns_lookup(client->set.host, &dns_set,
-                              pop3c_dns_callback, client,
-                              &client->dns_lookup) < 0)
+               if (pop3c_client_dns_lookup(client) < 0)
                        failed = TRUE;
        } else if (client->to == NULL) {
                client->to = timeout_add(POP3C_COMMAND_TIMEOUT_MSECS,
index 292db11bdcd886789808844206631df84e8ab2be..e032386ec5b1bf083448f3a45839d7cc64daaf20 100644 (file)
@@ -63,6 +63,7 @@ pop3c_client_create_from_set(struct mail_storage *storage,
        client_set.master_user = set->pop3c_master_user;
        client_set.password = set->pop3c_password;
        client_set.dns_client_socket_path =
+               storage->user->set->base_dir[0] == '\0' ? "" :
                t_strconcat(storage->user->set->base_dir, "/",
                            DNS_CLIENT_SOCKET_NAME, NULL);
        str = t_str_new(128);