client-common.c revision 0f5dc4da3982053036be65190e44bf28a67b1ca2
a8c5a86d183db25a57bf193c06b41e092ec2e151Timo Sirainen/* Copyright (c) 2002-2016 Dovecot authors, see the included COPYING file */
ddd1adf19cacc6186fbc713d255e1e82086d7751Timo Sirainenstatic unsigned int clients_count = 0;
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainenstatic void empty_login_client_allocated_hook(struct client *client ATTR_UNUSED)
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainenstatic login_client_allocated_func_t *hook_client_allocated =
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainenlogin_client_allocated_hook_set(login_client_allocated_func_t *new_hook)
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen login_client_allocated_func_t *old_hook = hook_client_allocated;
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainenstatic void client_idle_disconnect_timeout(struct client *client)
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen unsigned int secs;
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen user_reason = "Timeout while finishing login.";
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen "Timeout while finishing login (waited %u secs)", secs);
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen "Disconnected for inactivity during authentication.";
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen "Disconnected: Inactivity during authentication";
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen user_reason = "Timeout while finishing login.";
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen "proxy: Logging in to %s:%u timed out "
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen "(state=%u, duration=%us)",
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen client_notify_disconnect(client, CLIENT_DISCONNECT_TIMEOUT, user_reason);
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainenstatic void client_open_streams(struct client *client)
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen client->input = i_stream_create_fd(client->fd, LOGIN_MAX_INBUF_SIZE);
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen client->output = o_stream_create_fd(client->fd, LOGIN_MAX_OUTBUF_SIZE);
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen o_stream_set_no_error_handling(client->output, TRUE);
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen if (iostream_rawlog_create(login_rawlog_dir, &client->input,
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainenstatic bool client_is_trusted(struct client *client)
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen const char *const *net;
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen unsigned int bits;
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen if (client->set->login_trusted_networks == NULL)
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen net = t_strsplit_spaces(client->set->login_trusted_networks, ", ");
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen if (net_parse_range(*net, &net_ip, &bits) < 0) {
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen if (net_is_in_network(&client->ip, &net_ip, bits))
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen const struct master_service_ssl_settings *ssl_set,
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen client = login_binary->client_vfuncs->alloc(pool);
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen client->v.auth_send_challenge = client_auth_send_challenge;
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen client->v.auth_parse_response = client_auth_parse_response;
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen p_array_init(&client->module_contexts, client->pool, 5);
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen client->real_local_port = conn->real_local_port;
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen client->real_remote_ip = conn->real_remote_ip;
ddd1adf19cacc6186fbc713d255e1e82086d7751Timo Sirainen client->real_remote_port = conn->real_remote_port;
ddd1adf19cacc6186fbc713d255e1e82086d7751Timo Sirainen client->listener_name = p_strdup(client->pool, conn->name);
ddd1adf19cacc6186fbc713d255e1e82086d7751Timo Sirainen net_ip_compare(&conn->real_remote_ip, &conn->real_local_ip);
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainenvoid client_destroy(struct client *client, const char *reason)
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen if (!client->login_success && reason != NULL) {
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen client_get_extra_disconnect_reason(client), NULL);
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen if (!client->login_success && client->ssl_proxy != NULL)
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen master_auth_request_abort(master_auth, client->master_tag);
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen dsasl_client_free(&client->proxy_sasl_client);
return TRUE;
return FALSE;
void client_destroy_oldest(void)
void clients_destroy_all(void)
int fd_ssl;
int ret;
if (ret > 0) {
unsigned int clients_get_count(void)
return clients_count;
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 i, field_name_len;
return NULL;
field_name_len) == 0 &&
return NULL;
const char *error;
unsigned int pos;
*e, error);
if (have_username_key(*e)) {
&error) <= 0) {
T_BEGIN {
} T_END;
T_BEGIN {
} T_END;
T_BEGIN {
} T_END;
return t_strdup_printf(
return t_strdup_printf(
const char *text)
return FALSE;
return FALSE;
return TRUE;
return TRUE;