From: Stephan Bosch Date: Sat, 17 Feb 2018 00:46:15 +0000 (+0100) Subject: lib-smtp: client: Perform output stream error handling in one place. X-Git-Tag: 2.3.1~129 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3fd43b09490617de6d5420a30760aaf15711e05e;p=thirdparty%2Fdovecot%2Fcore.git lib-smtp: client: Perform output stream error handling in one place. --- diff --git a/src/lib-smtp/smtp-client-command.c b/src/lib-smtp/smtp-client-command.c index f67d01e328..42477f9f41 100644 --- a/src/lib-smtp/smtp-client-command.c +++ b/src/lib-smtp/smtp-client-command.c @@ -352,8 +352,7 @@ smtp_client_command_sent(struct smtp_client_command *cmd) } static int -smtp_client_command_send_stream(struct smtp_client_command *cmd, - const char **error_r) +smtp_client_command_send_stream(struct smtp_client_command *cmd) { struct smtp_client_connection *conn = cmd->conn; struct istream *stream = cmd->stream; @@ -382,11 +381,8 @@ smtp_client_command_send_stream(struct smtp_client_command *cmd, if (conn->dot_output != NULL) { /* this concludes the dot stream with CRLF.CRLF */ if ((ret=o_stream_finish(conn->dot_output)) < 0) { - *error_r = t_strdup_printf( - "flush(%s) failed: %s", - o_stream_get_name(output), - o_stream_get_error(output)); o_stream_unref(&conn->dot_output); + smtp_client_connection_handle_output_error(conn); return -1; } if (ret == 0) @@ -403,32 +399,32 @@ smtp_client_command_send_stream(struct smtp_client_command *cmd, stream->v_offset < cmd->stream_size); return 0; case OSTREAM_SEND_ISTREAM_RESULT_ERROR_INPUT: + /* the provided payload stream is broken; fail this command separately */ + smtp_client_command_error(cmd, "read(%s) failed: %s", + i_stream_get_name(stream), + i_stream_get_error(stream)); smtp_client_command_fail(&cmd, SMTP_CLIENT_COMMAND_ERROR_BROKEN_PAYLOAD, "Broken payload stream"); - /* we're in the middle of sending a command, so the connection will also have to be aborted */ - *error_r = t_strdup_printf("read(%s) failed: %s", - i_stream_get_name(stream), - i_stream_get_error(stream)); o_stream_unref(&conn->dot_output); + smtp_client_connection_fail(conn, + SMTP_CLIENT_COMMAND_ERROR_CONNECTION_LOST, + "Broken payload stream"); return -1; case OSTREAM_SEND_ISTREAM_RESULT_ERROR_OUTPUT: /* normal connection failure */ - *error_r = t_strdup_printf("write(%s) failed: %s", - o_stream_get_name(output), - o_stream_get_error(output)); o_stream_unref(&conn->dot_output); + smtp_client_connection_handle_output_error(conn); return -1; } i_unreached(); } -int smtp_client_command_send_more(struct smtp_client_connection *conn, - const char **error_r) +int smtp_client_command_send_more(struct smtp_client_connection *conn) { struct smtp_client_command *cmd; const char *data; @@ -486,10 +482,7 @@ int smtp_client_command_send_more(struct smtp_client_connection *conn, size = cmd->data->used - cmd->send_pos; if ((sent=o_stream_send(conn->conn.output, data, size)) <= 0) { if (sent < 0) { - *error_r = t_strdup_printf( - "write(%s) failed: %s", - o_stream_get_name(conn->conn.output), - o_stream_get_error(conn->conn.output)); + smtp_client_connection_handle_output_error(conn); return -1; } smtp_client_command_debug(cmd, @@ -503,7 +496,7 @@ int smtp_client_command_send_more(struct smtp_client_connection *conn, } if (cmd->stream != NULL && - (ret=smtp_client_command_send_stream(cmd, error_r)) <= 0) { + (ret=smtp_client_command_send_stream(cmd)) <= 0) { if (ret < 0) return -1; smtp_client_command_debug(cmd, diff --git a/src/lib-smtp/smtp-client-connection.c b/src/lib-smtp/smtp-client-connection.c index 347b8dad7a..32e83dd905 100644 --- a/src/lib-smtp/smtp-client-connection.c +++ b/src/lib-smtp/smtp-client-connection.c @@ -1094,7 +1094,6 @@ static void smtp_client_connection_input(struct connection *_conn) static int smtp_client_connection_output(struct smtp_client_connection *conn) { - const char *error; int ret; if (conn->to_connect != NULL) @@ -1107,15 +1106,8 @@ static int smtp_client_connection_output(struct smtp_client_connection *conn) } smtp_client_connection_ref(conn); - if (smtp_client_command_send_more(conn, &error) < 0) { - smtp_client_connection_error(conn, - "Connection lost: %s", error); - smtp_client_connection_fail(conn, - SMTP_CLIENT_COMMAND_ERROR_CONNECTION_LOST, - "Lost connection to remote server " - "(failed to send command)"); + if (smtp_client_command_send_more(conn) < 0) ret = -1; - } smtp_client_connection_unref(&conn); return ret; } diff --git a/src/lib-smtp/smtp-client-private.h b/src/lib-smtp/smtp-client-private.h index 603d614884..3be73fea84 100644 --- a/src/lib-smtp/smtp-client-private.h +++ b/src/lib-smtp/smtp-client-private.h @@ -186,8 +186,7 @@ struct smtp_client { */ void smtp_client_command_free(struct smtp_client_command *cmd); -int smtp_client_command_send_more(struct smtp_client_connection *conn, - const char **error_r); +int smtp_client_command_send_more(struct smtp_client_connection *conn); int smtp_client_command_input_reply(struct smtp_client_command *cmd, const struct smtp_reply *reply); void smtp_client_command_fail(struct smtp_client_command **_cmd,