]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-smtp: smtp-client-connection - Consistently log an error for connection failures.
authorStephan Bosch <stephan.bosch@open-xchange.com>
Wed, 22 Dec 2021 23:59:45 +0000 (00:59 +0100)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Mon, 10 Jan 2022 06:31:48 +0000 (06:31 +0000)
src/lib-smtp/smtp-client-connection.c
src/lib-smtp/test-smtp-client-errors.c

index 36e94581570a2dec4d5b689f9d3e0165d80f5e23..4be8060d4274f42625a3a699c6812df05abf60be 100644 (file)
@@ -1063,6 +1063,7 @@ smtp_client_connection_handshake_cb(const struct smtp_reply *reply,
 
        lines = reply->text_lines;
        if (*lines == NULL) {
+               e_error(conn->event, "Invalid handshake reply");
                smtp_client_connection_fail(
                        conn, SMTP_CLIENT_COMMAND_ERROR_BAD_REPLY,
                        "Invalid handshake reply");
@@ -1173,6 +1174,8 @@ smtp_client_connection_input_reply(struct smtp_client_connection *conn,
                        smtp_reply_log(reply));
                if (reply->status != 220) {
                        if (smtp_reply_is_success(reply)) {
+                               e_error(conn->event,
+                                       "Received inappropriate greeting");
                                smtp_client_connection_fail(
                                        conn,
                                        SMTP_CLIENT_COMMAND_ERROR_BAD_REPLY,
@@ -1193,7 +1196,7 @@ smtp_client_connection_input_reply(struct smtp_client_connection *conn,
 
        /* unexpected reply? */
        if (conn->cmd_wait_list_head == NULL) {
-               e_debug(conn->event, "Unexpected reply: %s",
+               e_error(conn->event, "Unexpected reply: %s",
                        smtp_reply_log(reply));
                smtp_client_connection_fail(
                        conn, SMTP_CLIENT_COMMAND_ERROR_BAD_REPLY,
@@ -1297,6 +1300,7 @@ static void smtp_client_connection_input(struct connection *_conn)
 
        if (ret < 0 || (ret == 0 && conn->conn.input->eof)) {
                if (conn->conn.input->stream_errno == ENOBUFS) {
+                       e_error(conn->event, "Command reply line too long");
                        smtp_client_connection_fail(
                                conn, SMTP_CLIENT_COMMAND_ERROR_BAD_REPLY,
                                "Command reply line too long");
@@ -1320,6 +1324,8 @@ static void smtp_client_connection_input(struct connection *_conn)
                        }
                } else {
                        i_assert(error != NULL);
+                       e_error(conn->event, "Invalid command reply: %s",
+                               error);
                        smtp_client_connection_fail(
                                conn, SMTP_CLIENT_COMMAND_ERROR_BAD_REPLY,
                                t_strdup_printf("Invalid command reply: %s",
index 145dd87d911844cff77faeb5898f83f7b527499e..863ee7c49e46a1c22bce455bfa43e6beb5abe1ce 100644 (file)
@@ -1901,6 +1901,8 @@ test_client_premature_reply(const struct smtp_client_settings *client_set)
        struct _premature_reply *ctx;
        unsigned int i;
 
+       test_expect_errors(6);
+
        ctx = i_new(struct _premature_reply, 1);
        ctx->count = 6;
 
@@ -2232,6 +2234,8 @@ test_client_early_data_reply(const struct smtp_client_settings *client_set)
        struct _early_data_reply *ctx;
        unsigned int i;
 
+       test_expect_errors(2);
+
        ctx = i_new(struct _early_data_reply, 1);
        ctx->count = 3;
 
@@ -2311,6 +2315,8 @@ test_client_bad_reply(
        struct smtp_client_command *scmd;
        struct _bad_reply *ctx;
 
+       test_expect_errors(2);
+
        ctx = i_new(struct _bad_reply, 1);
        ctx->count = 2;
 
@@ -2452,6 +2458,8 @@ test_client_bad_greeting(const struct smtp_client_settings *client_set)
 {
        struct _bad_greeting *ctx;
 
+       test_expect_errors(2);
+
        ctx = i_new(struct _bad_greeting, 1);
        ctx->count = 3;
 
@@ -3279,6 +3287,8 @@ test_client_authentication_failed(const struct smtp_client_settings *client_set)
        struct _authentication_failed *ctx;
        unsigned int i;
 
+       test_expect_errors(2);
+
        ctx = i_new(struct _authentication_failed, 1);
        ctx->count = 2;
 
@@ -3299,7 +3309,6 @@ static void test_authentication_failed(void)
        test_client_defaults(&smtp_client_set);
 
        test_begin("authentication failed");
-       test_expect_errors(1);
        test_run_client_server(&smtp_client_set,
                               test_client_authentication_failed,
                               test_server_authentication_failed, 2, NULL);