]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-smtp: client: Fix rawlog input stream inconsistency by updating streams right...
authorStephan Bosch <stephan.bosch@dovecot.fi>
Sun, 24 Dec 2017 13:35:15 +0000 (14:35 +0100)
committerStephan Bosch <stephan.bosch@dovecot.fi>
Sun, 24 Dec 2017 14:20:21 +0000 (15:20 +0100)
Restructured the code to call a new function called smtp_client_connection_streams_changed() which performs all the necessary updates.
Before, enabling rawlog could break the TLS handshake.

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

index 8d7878d0beeb6ecfdf0d18b527ec353ed536e1a0..d9839d7f684ccc6f17598739f01fe283da7d6406 100644 (file)
@@ -1117,27 +1117,9 @@ static void smtp_client_connection_destroy(struct connection *_conn)
 static void
 smtp_client_connection_established(struct smtp_client_connection *conn)
 {
-       struct stat st;
-
        if (conn->to_connect != NULL)
                timeout_reset(conn->to_connect);
 
-       /* (re-)initialize rawlog */
-       if (conn->set.rawlog_dir != NULL &&
-           stat(conn->set.rawlog_dir, &st) == 0) {
-               iostream_rawlog_create(conn->set.rawlog_dir,
-                                      &conn->conn.input, &conn->conn.output);
-       }
-
-       /* create/update reply parser */
-       if (conn->reply_parser == NULL) {
-               conn->reply_parser = smtp_reply_parser_init(
-                       conn->conn.input, conn->set.max_reply_size);
-       } else {
-               smtp_reply_parser_set_stream(conn->reply_parser,
-                                            conn->conn.input);
-       }
-
        /* set flush callback */
        o_stream_set_flush_callback(conn->conn.output,
                smtp_client_connection_output, conn);
@@ -1164,6 +1146,26 @@ smtp_client_connection_ssl_handshaked(const char **error_r, void *context)
        return 0;
 }
 
+static void
+smtp_client_connection_streams_changed(struct smtp_client_connection *conn)
+{
+       struct stat st;
+
+       if (conn->set.rawlog_dir != NULL &&
+           stat(conn->set.rawlog_dir, &st) == 0) {
+               iostream_rawlog_create(conn->set.rawlog_dir,
+                                      &conn->conn.input, &conn->conn.output);
+       }
+
+       if (conn->reply_parser == NULL) {
+               conn->reply_parser = smtp_reply_parser_init(
+                       conn->conn.input, conn->set.max_reply_size);
+       } else {
+               smtp_reply_parser_set_stream(conn->reply_parser,
+                                            conn->conn.input);
+       }
+}
+
 static int
 smtp_client_connection_ssl_init(struct smtp_client_connection *conn,
                                const char **error_r)
@@ -1208,6 +1210,8 @@ smtp_client_connection_ssl_init(struct smtp_client_connection *conn,
                        conn->conn.name, error);
                return -1;
        }
+       smtp_client_connection_streams_changed(conn);
+
        ssl_iostream_set_handshake_callback(conn->ssl_iostream,
                smtp_client_connection_ssl_handshaked, conn);
        if (ssl_iostream_handshake(conn->ssl_iostream) < 0) {
@@ -1277,6 +1281,7 @@ smtp_client_connection_connected(struct connection *_conn, bool success)
 
        conn->raw_input = conn->conn.input;
        conn->raw_output = conn->conn.output;
+       smtp_client_connection_streams_changed(conn);
 
        if (conn->ssl_mode == SMTP_CLIENT_SSL_MODE_IMMEDIATE) {
                if (smtp_client_connection_ssl_init(conn, &error) < 0) {