]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-smtp: Add "unfinished %s command" if client disconnected during command processing
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 2 Mar 2021 12:17:29 +0000 (14:17 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Thu, 11 Mar 2021 11:19:09 +0000 (11:19 +0000)
This also removes the need for special code path to differentiate between
logging "Remote closed connection" and "Remote closed connection
unexpectedly".

src/lib-smtp/smtp-server-connection.c

index 61fe00b5929fdc85d1a11e78aacda2e03b2e6f17..c0ee9428ed4ba5cfa3ca97bec1018612915fbb13 100644 (file)
@@ -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);