From: Timo Sirainen Date: Wed, 3 Feb 2021 19:58:15 +0000 (+0200) Subject: *-login: Add "Disconnected: " prefix to most disconnection log lines X-Git-Tag: 2.3.15~272 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=04440c6364c0d6e7e13fe5490fcba0337fe6510d;p=thirdparty%2Fdovecot%2Fcore.git *-login: Add "Disconnected: " prefix to most disconnection log lines All except "Disconnected by proxy" disconnections. --- diff --git a/src/imap-login/imap-login-client.c b/src/imap-login/imap-login-client.c index b2c8af9cbf..b426a0c2a5 100644 --- a/src/imap-login/imap-login-client.c +++ b/src/imap-login/imap-login-client.c @@ -60,8 +60,7 @@ bool client_handle_parser_error(struct imap_client *client, case IMAP_PARSE_ERROR_LITERAL_TOO_BIG: client_send_reply(&client->common, IMAP_CMD_REPLY_BYE, msg); - client_destroy(&client->common, - t_strconcat("Disconnected: ", msg, NULL)); + client_destroy(&client->common, msg); return FALSE; default: break; @@ -201,8 +200,7 @@ static bool client_invalid_command(struct imap_client *client) if (++client->common.bad_counter >= CLIENT_MAX_BAD_COMMANDS) { client_send_reply(&client->common, IMAP_CMD_REPLY_BYE, "Too many invalid IMAP commands."); - client_destroy(&client->common, - "Disconnected: Too many invalid commands"); + client_destroy(&client->common, "Too many invalid commands"); return FALSE; } client_send_reply(&client->common, IMAP_CMD_REPLY_BAD, diff --git a/src/login-common/client-common.c b/src/login-common/client-common.c index cb0f9fbaac..e3a9a614c7 100644 --- a/src/login-common/client-common.c +++ b/src/login-common/client-common.c @@ -101,8 +101,7 @@ static void client_idle_disconnect_timeout(struct client *client) } else if (client->auth_request != NULL) { user_reason = "Disconnected for inactivity during authentication."; - destroy_reason = - "Disconnected: Inactivity during authentication"; + destroy_reason = "Inactivity during authentication"; } else if (client->login_proxy != NULL) { secs = ioloop_time - client->created; user_reason = "Timeout while finishing login."; @@ -114,7 +113,7 @@ static void client_idle_disconnect_timeout(struct client *client) "%s", destroy_reason); } else { user_reason = "Disconnected for inactivity."; - destroy_reason = "Disconnected: Inactivity"; + destroy_reason = "Inactivity"; } client_notify_disconnect(client, CLIENT_DISCONNECT_TIMEOUT, user_reason); client_destroy(client, destroy_reason); @@ -250,7 +249,8 @@ void client_init(struct client *client, void **other_sets) login_refresh_proctitle(); } -void client_disconnect(struct client *client, const char *reason) +void client_disconnect(struct client *client, const char *reason, + bool add_disconnected_prefix) { if (client->disconnected) return; @@ -267,7 +267,10 @@ void client_disconnect(struct client *client, const char *reason) struct event *event = client->login_proxy == NULL ? client->event : login_proxy_get_event(client->login_proxy); - e_info(event, "%s", reason); + if (add_disconnected_prefix) + e_info(event, "Disconnected: %s", reason); + else + e_info(event, "%s", reason); } if (client->output != NULL) @@ -305,7 +308,7 @@ void client_destroy(struct client *client, const char *reason) client_fd_proxies. */ DLLIST_REMOVE(&clients, client); - client_disconnect(client, reason); + client_disconnect(client, reason, !client->login_success); pool_unref(&client->preproxy_pool); @@ -441,7 +444,7 @@ void client_destroy_oldest(void) client_notify_disconnect(client, CLIENT_DISCONNECT_RESOURCE_CONSTRAINT, "Connection queue full"); - client_destroy(client, "Disconnected: Connection queue full"); + client_destroy(client, "Connection queue full"); } void clients_destroy_all_reason(const char *reason) @@ -458,7 +461,7 @@ void clients_destroy_all_reason(const char *reason) void clients_destroy_all(void) { - clients_destroy_all_reason("Disconnected: Shutting down"); + clients_destroy_all_reason("Shutting down"); } static int client_sni_callback(const char *name, const char **error_r, @@ -549,8 +552,7 @@ static void client_start_tls(struct client *client) client_notify_disconnect(client, CLIENT_DISCONNECT_INTERNAL_ERROR, "TLS initialization failed."); - client_destroy(client, - "Disconnected: TLS initialization failed."); + client_destroy(client, "TLS initialization failed."); return; } login_refresh_proctitle(); @@ -1105,7 +1107,7 @@ bool client_read(struct client *client) client_notify_disconnect(client, CLIENT_DISCONNECT_RESOURCE_CONSTRAINT, "Input buffer full, aborting"); - client_destroy(client, "Disconnected: Input buffer full"); + client_destroy(client, "Input buffer full"); return FALSE; case -1: /* disconnected */ diff --git a/src/login-common/client-common.h b/src/login-common/client-common.h index 98bebf154f..90232f47f6 100644 --- a/src/login-common/client-common.h +++ b/src/login-common/client-common.h @@ -263,7 +263,8 @@ client_alloc(int fd, pool_t pool, const struct login_settings *set, const struct master_service_ssl_settings *ssl_set); void client_init(struct client *client, void **other_sets); -void client_disconnect(struct client *client, const char *reason); +void client_disconnect(struct client *client, const char *reason, + bool add_disconnected_prefix); void client_destroy(struct client *client, const char *reason); /* Destroy the client after a successful login. Either the client fd was sent to the post-login process, or the connection will be proxied. */ diff --git a/src/login-common/login-proxy.c b/src/login-common/login-proxy.c index bb23b90d01..5e3b59c3a8 100644 --- a/src/login-common/login-proxy.c +++ b/src/login-common/login-proxy.c @@ -883,7 +883,8 @@ login_proxy_cmd_kick_full(struct ipc_cmd *cmd, const char *const *args, next = proxy->next; if (want_kick(proxy, args, key_idx)) { - client_destroy(proxy->client, KILLED_BY_ADMIN_REASON); + client_disconnect(proxy->client, KILLED_BY_ADMIN_REASON, FALSE); + client_destroy(proxy->client, NULL); count++; } } T_END; @@ -983,7 +984,8 @@ login_proxy_cmd_kick_director_hash(struct ipc_cmd *cmd, const char *const *args) if (director_username_hash(proxy->client, &proxy_hash) && proxy_hash == hash && !net_ip_compare(&proxy->ip, &except_ip)) { - client_destroy(proxy->client, KILLED_BY_DIRECTOR_REASON); + client_disconnect(proxy->client, KILLED_BY_DIRECTOR_REASON, FALSE); + client_destroy(proxy->client, NULL); count++; } } diff --git a/src/login-common/main.c b/src/login-common/main.c index a4e5597385..cee6d43d14 100644 --- a/src/login-common/main.c +++ b/src/login-common/main.c @@ -293,7 +293,7 @@ static void auth_connect_notify(struct auth_client *client ATTR_UNUSED, /* auth disconnected without having ever succeeded, so the auth process is probably misconfigured. no point in keeping the client connections hanging. */ - clients_destroy_all_reason("Disconnected: Auth process broken"); + clients_destroy_all_reason("Auth process broken"); } } diff --git a/src/submission-login/client.c b/src/submission-login/client.c index 479eb0d806..122ace3d1a 100644 --- a/src/submission-login/client.c +++ b/src/submission-login/client.c @@ -213,7 +213,8 @@ static void client_connection_disconnect(void *context, const char *reason) struct submission_client *client = context; client->pending_auth = NULL; - client_disconnect(&client->common, reason); + client_disconnect(&client->common, reason, + !client->common.login_success); } static void client_connection_free(void *context)