client-common.c revision e2a88d59c0d47d63ce1ad5b1fd95e487124a3fd4
2454dfa32c93c20a8522c6ed42fe057baaac9f9aStephan Bosch/* Copyright (c) 2002-2012 Dovecot authors, see the included COPYING file */
a443e5aaf632257bfd1e7aa9b3c42c09512bbe43Timo Sirainenstruct client *clients = NULL, *last_client = NULL;
a443e5aaf632257bfd1e7aa9b3c42c09512bbe43Timo Sirainenstatic unsigned int clients_count = 0;
a443e5aaf632257bfd1e7aa9b3c42c09512bbe43Timo Sirainenstatic void client_idle_disconnect_timeout(struct client *client)
a443e5aaf632257bfd1e7aa9b3c42c09512bbe43Timo Sirainen unsigned int secs;
5a37e34b1b5acf453372cd112c70bb4e46b4bee2Timo Sirainen user_reason = "Timeout while finishing login.";
a443e5aaf632257bfd1e7aa9b3c42c09512bbe43Timo Sirainen "Timeout while finishing login (waited %u secs)", secs);
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen "Disconnected for inactivity during authentication.";
5a37e34b1b5acf453372cd112c70bb4e46b4bee2Timo Sirainen "Disconnected: Inactivity during authentication";
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen user_reason = "Timeout while finishing login.";
4ea6c43a08b37f270bd54b5809142246fd118263Timo Sirainen "proxy: Logging in to %s:%u timed out "
bf9ea5404a0094a8fb8199b677d81f803512c44eTimo Sirainen "(state=%u, duration=%us)",
4ea6c43a08b37f270bd54b5809142246fd118263Timo Sirainen client_notify_disconnect(client, CLIENT_DISCONNECT_TIMEOUT, user_reason);
5a37e34b1b5acf453372cd112c70bb4e46b4bee2Timo Sirainenstatic void client_open_streams(struct client *client)
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen i_stream_create_fd(client->fd, LOGIN_MAX_INBUF_SIZE, FALSE);
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen o_stream_create_fd(client->fd, LOGIN_MAX_OUTBUF_SIZE, FALSE);
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen o_stream_set_no_error_handling(client->output, TRUE);
a443e5aaf632257bfd1e7aa9b3c42c09512bbe43Timo Sirainen if (iostream_rawlog_create(login_rawlog_dir, &client->input,
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainenstatic bool client_is_trusted(struct client *client)
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen const char *const *net;
7d87a87b360ecac47fe10e7ca5c7e1433dd63004Timo Sirainen unsigned int bits;
c0a87e5f3316a57e6f915882fa1951d0fbb74a61Timo Sirainen if (client->set->login_trusted_networks == NULL)
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen net = t_strsplit_spaces(client->set->login_trusted_networks, ", ");
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen if (net_parse_range(*net, &net_ip, &bits) < 0) {
a443e5aaf632257bfd1e7aa9b3c42c09512bbe43Timo Sirainen if (net_is_in_network(&client->ip, &net_ip, bits))
44f93baa7b8dca7d00bf187cd3db1c15eed384d2Timo Sirainen const struct login_settings *set, void **other_sets,
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen const struct ip_addr *local_ip, const struct ip_addr *remote_ip)
a443e5aaf632257bfd1e7aa9b3c42c09512bbe43Timo Sirainen client = login_binary->client_vfuncs->alloc(pool);
5a37e34b1b5acf453372cd112c70bb4e46b4bee2Timo Sirainen client->v.auth_send_challenge = client_auth_send_challenge;
bd7b1a9000b12349e2a99bb43b3ce8b96a18e92bTimo Sirainen client->v.auth_parse_response = client_auth_parse_response;
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainenvoid client_destroy(struct client *client, const char *reason)
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen if (!client->login_success && reason != NULL) {
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen client_get_extra_disconnect_reason(client), NULL);
e5dca7edde333c2759b0e6b1d0d00b94ea303322Timo Sirainen master_auth_request_abort(master_auth, client->master_tag);
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen if (client_unref(&client) && initial_service_count == 1) {
bf9ea5404a0094a8fb8199b677d81f803512c44eTimo Sirainen /* as soon as this connection is done with proxying
bf9ea5404a0094a8fb8199b677d81f803512c44eTimo Sirainen (or whatever), the process will die. there's no need for
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen authentication anymore, so close the connection.
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen do this only with initial service_count=1, in case there
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen are other clients with pending authentications */
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen auth_client_disconnect(auth_client, "unnecessary connection");
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainenvoid client_destroy_success(struct client *client, const char *reason)
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainenvoid client_destroy_internal_failure(struct client *client)
cd2cd224d3216a243d55c71c298a5b7684de0ac4Timo Sirainen client_notify_disconnect(client, CLIENT_DISCONNECT_INTERNAL_ERROR,
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen "Internal login failure. "
66a872b4569c048e804f0731680d89c6042d8890Timo Sirainen "Refer to server log for more information.");
66a872b4569c048e804f0731680d89c6042d8890Timo Sirainen "Internal login failure (pid=%s id=%u)",
return FALSE;
void client_destroy_oldest(void)
void clients_destroy_all(void)
int fd_ssl;
int ret;
if (ret > 0) {
if (!ssl_initialized) {
unsigned int clients_get_count(void)
return clients_count;
#ifdef HAVE_IPV6
static const struct var_expand_table *
sizeof(login_var_expand_empty_tab));
const char *ssl_state =
const char *ssl_error =
return tab;
char key;
str++;
return TRUE;
return FALSE;
unsigned int pos;
if (have_username_key(*e)) {
T_BEGIN {
} T_END;
T_BEGIN {
} T_END;
T_BEGIN {
} T_END;
return t_strdup_printf(
const char *text)
return FALSE;
return FALSE;
return TRUE;
return TRUE;