Skip to content

Commit

Permalink
login-common: Extract SSL/TLS initialization into client_init_ssl()
Browse files Browse the repository at this point in the history
  • Loading branch information
sirainen authored and Timo Sirainen committed Nov 6, 2017
1 parent 66ea9ea commit b1485f2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/login-common/client-common.c
Expand Up @@ -409,30 +409,41 @@ 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.");
client_destroy(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);
Expand Down
1 change: 1 addition & 0 deletions src/login-common/client-common.h
Expand Up @@ -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;
Expand Down

0 comments on commit b1485f2

Please sign in to comment.