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