From: Stephan Bosch Date: Wed, 22 Dec 2021 23:59:45 +0000 (+0100) Subject: lib-smtp: smtp-client-connection - Consistently log an error for connection failures. X-Git-Tag: 2.3.18~37 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f436df8709988a61ba41932bead8db98e101433b;p=thirdparty%2Fdovecot%2Fcore.git lib-smtp: smtp-client-connection - Consistently log an error for connection failures. --- diff --git a/src/lib-smtp/smtp-client-connection.c b/src/lib-smtp/smtp-client-connection.c index 36e9458157..4be8060d42 100644 --- a/src/lib-smtp/smtp-client-connection.c +++ b/src/lib-smtp/smtp-client-connection.c @@ -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", diff --git a/src/lib-smtp/test-smtp-client-errors.c b/src/lib-smtp/test-smtp-client-errors.c index 145dd87d91..863ee7c49e 100644 --- a/src/lib-smtp/test-smtp-client-errors.c +++ b/src/lib-smtp/test-smtp-client-errors.c @@ -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);