From: Timo Sirainen Date: Mon, 8 Sep 2014 07:14:42 +0000 (+0300) Subject: pop3c: If base_dir isn't set, lookup pop3c_host with regular blocking DNS lookup. X-Git-Tag: 2.2.14.rc1~108 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7a88e726e7300fb0273cb4e55b43c27fbd90bdbd;p=thirdparty%2Fdovecot%2Fcore.git pop3c: If base_dir isn't set, lookup pop3c_host with regular blocking DNS lookup. --- diff --git a/src/lib-storage/index/pop3c/pop3c-client.c b/src/lib-storage/index/pop3c/pop3c-client.c index 966daee9cf..a4a7892569 100644 --- a/src/lib-storage/index/pop3c/pop3c-client.c +++ b/src/lib-storage/index/pop3c/pop3c-client.c @@ -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, diff --git a/src/lib-storage/index/pop3c/pop3c-storage.c b/src/lib-storage/index/pop3c/pop3c-storage.c index 292db11bdc..e032386ec5 100644 --- a/src/lib-storage/index/pop3c/pop3c-storage.c +++ b/src/lib-storage/index/pop3c/pop3c-storage.c @@ -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);