From: Timo Sirainen Date: Tue, 31 Oct 2017 22:59:54 +0000 (+0200) Subject: login-common: Extract SSL/TLS initialization into client_init_ssl() X-Git-Tag: 2.3.0.rc1~522 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b1485f2691de41ed7b5f96cebda2ebcb69a5e22f;p=thirdparty%2Fdovecot%2Fcore.git login-common: Extract SSL/TLS initialization into client_init_ssl() --- diff --git a/src/login-common/client-common.c b/src/login-common/client-common.c index 7dbd24ef80..350565dff9 100644 --- a/src/login-common/client-common.c +++ b/src/login-common/client-common.c @@ -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); diff --git a/src/login-common/client-common.h b/src/login-common/client-common.h index 1d7de7f0a6..cc1127fad9 100644 --- a/src/login-common/client-common.h +++ b/src/login-common/client-common.h @@ -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;