client-common.c revision dfafc4ac89195b8cdd48afa619599d5b392ef479
45312f52ff3a3d4c137447be4c7556500c2f8bf2Timo Sirainen/* Copyright (c) 2002-2017 Dovecot authors, see the included COPYING file */
dabb4cec4cf9bdb34013de682b08f1284cfb670fTimo Sirainenstatic unsigned int clients_count = 0;
dabb4cec4cf9bdb34013de682b08f1284cfb670fTimo Sirainenstatic struct client *client_fd_proxies = NULL;
dabb4cec4cf9bdb34013de682b08f1284cfb670fTimo Sirainenstatic unsigned int client_fd_proxies_count = 0;
dabb4cec4cf9bdb34013de682b08f1284cfb670fTimo Sirainenstatic ARRAY(struct login_client_module_hooks) module_hooks = ARRAY_INIT;
dabb4cec4cf9bdb34013de682b08f1284cfb670fTimo Sirainenvoid login_client_hooks_add(struct module *module,
dabb4cec4cf9bdb34013de682b08f1284cfb670fTimo Sirainenvoid login_client_hooks_remove(const struct login_client_hooks *hooks)
dabb4cec4cf9bdb34013de682b08f1284cfb670fTimo Sirainen const struct login_client_module_hooks *module_hook;
7a62083331fbbb73121d16d6e13fc3dbc5720aa7Timo Sirainen idx = array_foreach_idx(&module_hooks, module_hook);
ec23a602b0230eea29e64e2f283a9cf215be1f82Timo Sirainenstatic void hook_login_client_allocated(struct client *client)
ec23a602b0230eea29e64e2f283a9cf215be1f82Timo Sirainen const struct login_client_module_hooks *module_hook;
ec23a602b0230eea29e64e2f283a9cf215be1f82Timo Sirainen ctx = hook_build_init((void *)&client->v, sizeof(client->v));
dabb4cec4cf9bdb34013de682b08f1284cfb670fTimo Sirainen if (module_hook->hooks->client_allocated != NULL) T_BEGIN {
dabb4cec4cf9bdb34013de682b08f1284cfb670fTimo Sirainenstatic void client_idle_disconnect_timeout(struct client *client)
dabb4cec4cf9bdb34013de682b08f1284cfb670fTimo Sirainen unsigned int secs;
dabb4cec4cf9bdb34013de682b08f1284cfb670fTimo Sirainen user_reason = "Timeout while finishing login.";
dabb4cec4cf9bdb34013de682b08f1284cfb670fTimo Sirainen "Timeout while finishing login (waited %u secs)", secs);
dabb4cec4cf9bdb34013de682b08f1284cfb670fTimo Sirainen "Disconnected for inactivity during authentication.";
dabb4cec4cf9bdb34013de682b08f1284cfb670fTimo Sirainen "Disconnected: Inactivity during authentication";
dabb4cec4cf9bdb34013de682b08f1284cfb670fTimo Sirainen user_reason = "Timeout while finishing login.";
dabb4cec4cf9bdb34013de682b08f1284cfb670fTimo Sirainen "proxy: Logging in to %s:%u timed out "
dabb4cec4cf9bdb34013de682b08f1284cfb670fTimo Sirainen "(state=%s, duration=%us)",
dabb4cec4cf9bdb34013de682b08f1284cfb670fTimo Sirainen client_notify_disconnect(client, CLIENT_DISCONNECT_TIMEOUT, user_reason);
dabb4cec4cf9bdb34013de682b08f1284cfb670fTimo Sirainenstatic void client_open_streams(struct client *client)
dabb4cec4cf9bdb34013de682b08f1284cfb670fTimo Sirainen client->input = i_stream_create_fd(client->fd, LOGIN_MAX_INBUF_SIZE);
dabb4cec4cf9bdb34013de682b08f1284cfb670fTimo Sirainen client->output = o_stream_create_fd(client->fd, LOGIN_MAX_OUTBUF_SIZE);
dabb4cec4cf9bdb34013de682b08f1284cfb670fTimo Sirainen o_stream_set_no_error_handling(client->output, TRUE);
dabb4cec4cf9bdb34013de682b08f1284cfb670fTimo Sirainen if (iostream_rawlog_create(login_rawlog_dir, &client->input,
dabb4cec4cf9bdb34013de682b08f1284cfb670fTimo Sirainenstatic bool client_is_trusted(struct client *client)
dabb4cec4cf9bdb34013de682b08f1284cfb670fTimo Sirainen const char *const *net;
dabb4cec4cf9bdb34013de682b08f1284cfb670fTimo Sirainen unsigned int bits;
dabb4cec4cf9bdb34013de682b08f1284cfb670fTimo Sirainen if (client->set->login_trusted_networks == NULL)
dabb4cec4cf9bdb34013de682b08f1284cfb670fTimo Sirainen net = t_strsplit_spaces(client->set->login_trusted_networks, ", ");
dabb4cec4cf9bdb34013de682b08f1284cfb670fTimo Sirainen if (net_parse_range(*net, &net_ip, &bits) < 0) {
dabb4cec4cf9bdb34013de682b08f1284cfb670fTimo Sirainen if (net_is_in_network(&client->ip, &net_ip, bits))
dabb4cec4cf9bdb34013de682b08f1284cfb670fTimo Sirainen const struct master_service_ssl_settings *ssl_set)
dabb4cec4cf9bdb34013de682b08f1284cfb670fTimo Sirainen client = login_binary->client_vfuncs->alloc(pool);
dabb4cec4cf9bdb34013de682b08f1284cfb670fTimo Sirainen client->v.auth_send_challenge = client_auth_send_challenge;
dabb4cec4cf9bdb34013de682b08f1284cfb670fTimo Sirainen client->v.auth_parse_response = client_auth_parse_response;
return client;
const char *extra_reason =
return TRUE;
return FALSE;
return FALSE;
void client_destroy_oldest(void)
void clients_destroy_all(void)
void *context)
void **other_sets;
const char *error;
const char *error;
int ret;
if (ret > 0) {
client);
unsigned int clients_get_count(void)
return clients_count;
unsigned int clients_get_fd_proxies_count(void)
return client_fd_proxies_count;
return client_fd_proxies;
const char *value)
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;
const char **value_r,
field_name_len) == 0 &&
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;
void client_common_init(void)
void client_destroy_fd_proxies(void)
void client_common_deinit(void)