client-common.c revision 38318f5e82662615cd88e99e398efe4a630ce020
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen/* Copyright (c) 2002-2008 Dovecot authors, see the included COPYING file */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenstatic unsigned int clients_count = 0;
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenunsigned int clients_get_count(void)
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenstatic const struct var_expand_table *
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen static struct var_expand_table static_tab[] = {
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen unsigned int i;
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen tab[1].value = t_strcut(client->virtual_user, '@');
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen tab[2].value = strchr(client->virtual_user, '@');
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen for (i = 0; i < 3; i++)
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen tab[i].value = str_sanitize(tab[i].value, 80);
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen tab[5].value = net_ip2addr(&client->local_ip);
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen tab[8].value = client->auth_mech_name == NULL ? NULL :
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen str_sanitize(client->auth_mech_name, MAX_MECH_NAME);
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen tab[11].value = client->secured ? "secured" : NULL;
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen const char *ssl_state = ssl_proxy_is_handshaked(client->proxy) ?
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen const char *ssl_error = ssl_proxy_get_last_error(client->proxy);
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen tab[11].value = ssl_error == NULL ? ssl_state :
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen t_strdup_printf("%s: %s", ssl_state, ssl_error);
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen tab[12].value = ssl_proxy_get_security_string(client->proxy);
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenstatic bool have_key(const struct var_expand_table *table, const char *str)
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen unsigned int i;
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenstatic void client_syslog_real(struct client *client, const char *msg)
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen static struct var_expand_table static_tab[3] = {
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen const struct var_expand_table *var_expand_table;
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen const char *p, *const *e;
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen var_expand_table = get_var_expand_table(client);
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen for (e = log_format_elements; *e != NULL; e++) {
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen for (p = *e; *p != '\0'; p++) {
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenvoid client_syslog(struct client *client, const char *msg)
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen const char *const *net;
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen unsigned int bits;
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen net = t_strsplit_spaces(trusted_networks, ", ");
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen if (net_parse_range(*net, &net_ip, &bits) < 0) {
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen if (net_is_in_network(&client->ip, &net_ip, bits))
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenconst char *client_get_extra_disconnect_reason(struct client *client)
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen if (ssl_require_client_cert && client->proxy != NULL) {
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen if (ssl_proxy_has_broken_client_cert(client->proxy))
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen return "(client sent an invalid cert)";
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen if (!ssl_proxy_has_valid_client_cert(client->proxy))
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen return "(client didn't send a cert)";
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen return "(no auth attempts)";
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen /* some auth attempts without SSL/TLS */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen return "(tried to use disabled plaintext auth)";
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen return "(cert required, client didn't start TLS)";
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen return t_strdup_printf("(auth failed, %u attempts)",