From: Timo Sirainen Date: Tue, 2 Mar 2021 12:17:29 +0000 (+0200) Subject: lib-smtp: Add "unfinished %s command" if client disconnected during command processing X-Git-Tag: 2.3.15~284 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=691d92feb98646139bbb23a6fe1d171635c08bb1;p=thirdparty%2Fdovecot%2Fcore.git lib-smtp: Add "unfinished %s command" if client disconnected during command processing This also removes the need for special code path to differentiate between logging "Remote closed connection" and "Remote closed connection unexpectedly". --- diff --git a/src/lib-smtp/smtp-server-connection.c b/src/lib-smtp/smtp-server-connection.c index 61fe00b592..c0ee9428ed 100644 --- a/src/lib-smtp/smtp-server-connection.c +++ b/src/lib-smtp/smtp-server-connection.c @@ -496,15 +496,13 @@ smtp_server_connection_handle_input(struct smtp_server_connection *conn) e_debug(conn->event, "Connection lost: Remote disconnected"); - if (conn->command_queue_head == NULL) { - /* No pending commands; close */ - smtp_server_connection_close(&conn, - "Remote closed connection"); - } else if (conn->command_queue_head->state < + if (conn->command_queue_head == NULL || + conn->command_queue_head->state < SMTP_SERVER_COMMAND_STATE_SUBMITTED_REPLY) { - /* Unfinished command; close */ + /* No pending commands or unfinished + command; close */ smtp_server_connection_close(&conn, - "Remote closed connection unexpectedly"); + "Remote closed connection"); } else { /* A command is still processing; only drop input io for now */ @@ -1069,6 +1067,14 @@ smtp_server_connection_disconnect(struct smtp_server_connection *conn, reason = smtp_server_connection_get_disconnect_reason(conn); else reason = t_str_oneline(reason); + + cmd = conn->command_queue_head; + if (cmd != NULL && cmd->reg != NULL) { + /* Unfinished command - include it in the reason string */ + reason = t_strdup_printf("%s (unfinished %s command)", + reason, cmd->reg->name); + } + e_debug(conn->event, "Disconnected: %s", reason); conn->disconnect_reason = i_strdup(reason);