client-common.c revision 5f1d689131a75c39f064cbd4202373e7edf78f18
a8c5a86d183db25a57bf193c06b41e092ec2e151Timo Sirainen/* Copyright (c) 2002-2017 Dovecot authors, see the included COPYING file */
cd466fe7b84b0223735a6469c7f7bc225f65996dTimo Sirainenstatic unsigned int clients_count = 0;
0e3f8c6edad565112d91f0a53568c0313d657e48Timo Sirainenstatic ARRAY(struct login_client_module_hooks) module_hooks = ARRAY_INIT;
d56384d5226c8860079d0d0b08b83404e8c42986Timo Sirainenvoid login_client_hooks_add(struct module *module,
d6af1e63bc7824f1cc5b9b73a1c5f8f8789788d6Timo Sirainenvoid login_client_hooks_remove(const struct login_client_hooks *hooks)
d6af1e63bc7824f1cc5b9b73a1c5f8f8789788d6Timo Sirainen const struct login_client_module_hooks *module_hook;
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainen idx = array_foreach_idx(&module_hooks, module_hook);
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainenstatic void hook_login_client_allocated(struct client *client)
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen const struct login_client_module_hooks *module_hook;
a3ea111cfdbfd4f32baeb0bd7f1d72568c60a023Timo Sirainen ctx = hook_build_init((void *)&client->v, sizeof(client->v));
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainen if (module_hook->hooks->client_allocated != NULL) T_BEGIN {
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainenstatic void client_idle_disconnect_timeout(struct client *client)
1f57716285d4c5bc9bf2fd5569e3c85fd496afd9Timo Sirainen unsigned int secs;
1f57716285d4c5bc9bf2fd5569e3c85fd496afd9Timo Sirainen user_reason = "Timeout while finishing login.";
1f57716285d4c5bc9bf2fd5569e3c85fd496afd9Timo Sirainen "Timeout while finishing login (waited %u secs)", secs);
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen "Disconnected for inactivity during authentication.";
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen "Disconnected: Inactivity during authentication";
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen user_reason = "Timeout while finishing login.";
a3ea111cfdbfd4f32baeb0bd7f1d72568c60a023Timo Sirainen "proxy: Logging in to %s:%u timed out "
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen "(state=%s, duration=%us)",
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen client_notify_disconnect(client, CLIENT_DISCONNECT_TIMEOUT, user_reason);
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainenstatic void client_open_streams(struct client *client)
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen client->input = i_stream_create_fd(client->fd, LOGIN_MAX_INBUF_SIZE);
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen client->output = o_stream_create_fd(client->fd, LOGIN_MAX_OUTBUF_SIZE);
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen o_stream_set_no_error_handling(client->output, TRUE);
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen if (iostream_rawlog_create(login_rawlog_dir, &client->input,
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainenstatic bool client_is_trusted(struct client *client)
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen const char *const *net;
af208f4a43a81a39a2ec44e68d65d12b95f1b386Timo Sirainen unsigned int bits;
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainen if (client->set->login_trusted_networks == NULL)
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainen net = t_strsplit_spaces(client->set->login_trusted_networks, ", ");
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainen if (net_parse_range(*net, &net_ip, &bits) < 0) {
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainen if (net_is_in_network(&client->ip, &net_ip, bits))
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainen const struct master_service_ssl_settings *ssl_set,
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainen client = login_binary->client_vfuncs->alloc(pool);
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainen client->v.auth_send_challenge = client_auth_send_challenge;
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainen client->v.auth_parse_response = client_auth_parse_response;
9453e8d75cfd8fab2232cf772e9b120f308fb3eeTimo Sirainen client->preproxy_pool = pool_alloconly_create(MEMPOOL_GROWING"preproxy pool", 256);
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen p_array_init(&client->module_contexts, client->pool, 5);
return client;
const char *extra_reason =
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;
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_common_deinit(void)