From: Timo Sirainen Date: Wed, 5 Apr 2017 12:59:51 +0000 (+0300) Subject: *-login: Minor logging cleanup if client is disconnected before sending banner. X-Git-Tag: 2.3.0.rc1~1779 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=56af9dd10e7e6caeaca64395bad3f882b28ecdff;p=thirdparty%2Fdovecot%2Fcore.git *-login: Minor logging cleanup if client is disconnected before sending banner. Avoid unnecessarily adding "(no auth attempts in 0 secs)" when the reason string already makes it clear that the user didn't even have a chance to authenticate. This kind of disconnection currently happens only with some plugins. --- diff --git a/src/imap-login/imap-login-client.c b/src/imap-login/imap-login-client.c index f1f09a7c10..224bf61c19 100644 --- a/src/imap-login/imap-login-client.c +++ b/src/imap-login/imap-login-client.c @@ -637,6 +637,8 @@ static void imap_client_notify_auth_ready(struct client *client) str_append(greet, "\r\n"); client_send_raw(client, str_c(greet)); + + client->banner_sent = TRUE; } static void imap_client_starttls(struct client *client) diff --git a/src/login-common/client-common.c b/src/login-common/client-common.c index 2b6fa76c60..546d49ff4e 100644 --- a/src/login-common/client-common.c +++ b/src/login-common/client-common.c @@ -228,8 +228,10 @@ void client_destroy(struct client *client, const char *reason) pool_unref(&client->preproxy_pool); if (!client->login_success && reason != NULL) { - reason = t_strconcat(reason, " ", - client_get_extra_disconnect_reason(client), NULL); + const char *extra_reason = + client_get_extra_disconnect_reason(client); + if (extra_reason[0] != '\0') + reason = t_strconcat(reason, " ", extra_reason, NULL); } if (reason != NULL) client_log(client, reason); @@ -791,6 +793,10 @@ const char *client_get_extra_disconnect_reason(struct client *client) (unsigned int)(ioloop_time - client->created)); if (client->auth_attempts == 0) { + if (!client->banner_sent) { + /* disconnected by a plugin */ + return ""; + } return t_strdup_printf("(no auth attempts in %u secs)", (unsigned int)(ioloop_time - client->created)); } diff --git a/src/login-common/client-common.h b/src/login-common/client-common.h index f3d188e7a4..f93b2e5f3e 100644 --- a/src/login-common/client-common.h +++ b/src/login-common/client-common.h @@ -195,6 +195,7 @@ struct client { bool secured:1; bool trusted:1; bool ssl_servername_settings_read:1; + bool banner_sent:1; bool authenticating:1; bool auth_try_aborted:1; bool auth_initializing:1; diff --git a/src/pop3-login/client.c b/src/pop3-login/client.c index 41efd2fe93..10a855d101 100644 --- a/src/pop3-login/client.c +++ b/src/pop3-login/client.c @@ -222,6 +222,8 @@ static void pop3_client_notify_auth_ready(struct client *client) if (pop3_client->apop_challenge != NULL) str_printfa(str, " %s", pop3_client->apop_challenge); client_send_reply(client, POP3_CMD_REPLY_OK, str_c(str)); + + client->banner_sent = TRUE; } static void