]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
login-common: Extract SSL/TLS initialization into client_init_ssl()
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 31 Oct 2017 22:59:54 +0000 (00:59 +0200)
committerTimo Sirainen <tss@dovecot.fi>
Mon, 6 Nov 2017 23:09:00 +0000 (01:09 +0200)
src/login-common/client-common.c
src/login-common/client-common.h

index 7dbd24ef80fbe9e84cfb0b058a5bc38fc15db324..350565dff98667fd5f5d8228f4b2a9ab9d4602ca 100644 (file)
@@ -409,14 +409,30 @@ void clients_destroy_all(void)
        clients_destroy_all_reason("Disconnected: Shutting down");
 }
 
-static void client_start_tls(struct client *client)
+int client_init_ssl(struct client *client)
 {
        int fd_ssl;
 
+       i_assert(client->fd != -1);
+
        fd_ssl = ssl_proxy_alloc(client->fd, &client->ip, client->pool,
                                 client->set, client->ssl_set,
                                 &client->ssl_proxy);
-       if (fd_ssl == -1) {
+       if (fd_ssl == -1)
+               return -1;
+
+       ssl_proxy_set_client(client->ssl_proxy, client);
+       ssl_proxy_start(client->ssl_proxy);
+
+       client->tls = TRUE;
+       client->secured = TRUE;
+       client->fd = fd_ssl;
+       return 0;
+}
+
+static void client_start_tls(struct client *client)
+{
+       if (client_init_ssl(client) < 0) {
                client_notify_disconnect(client,
                        CLIENT_DISCONNECT_INTERNAL_ERROR,
                        "TLS initialization failed.");
@@ -424,15 +440,10 @@ static void client_start_tls(struct client *client)
                        "Disconnected: TLS initialization failed.");
                return;
        }
-       ssl_proxy_set_client(client->ssl_proxy, client);
-       ssl_proxy_start(client->ssl_proxy);
 
        client->starttls = TRUE;
-       client->tls = TRUE;
-       client->secured = TRUE;
        login_refresh_proctitle();
 
-       client->fd = fd_ssl;
        client->io = io_add(client->fd, IO_READ, client_input, client);
        i_stream_unref(&client->input);
        o_stream_unref(&client->output);
index 1d7de7f0a6133e3e74892648dae78645070d9b8d..cc1127fad95c71bb4e80adb0199c08d12ce1e717 100644 (file)
@@ -249,6 +249,7 @@ void client_destroy_success(struct client *client, const char *reason);
 void client_ref(struct client *client);
 bool client_unref(struct client **client) ATTR_NOWARN_UNUSED_RESULT;
 
+int client_init_ssl(struct client *client);
 void client_cmd_starttls(struct client *client);
 
 unsigned int clients_get_count(void) ATTR_PURE;