]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-smtp: smtp-client-connection - Fix authentication with multi-roundtrip SASL mecha...
authorStephan Bosch <stephan.bosch@open-xchange.com>
Wed, 26 Jan 2022 02:58:49 +0000 (03:58 +0100)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Fri, 28 Jan 2022 13:22:35 +0000 (14:22 +0100)
Before, it would fail with an unexpected reply error.

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

index e72777fa1a815d60214828c0e1184b9e212f7411..f2443fe13152a25032de1a0b02583af7f15f494e 100644 (file)
@@ -722,8 +722,12 @@ static void
 smtp_client_connection_auth_cb(const struct smtp_reply *reply,
                               struct smtp_client_connection *conn)
 {
+       struct smtp_client_command *cmd, *cmd_auth = conn->cmd_auth;
        const char *error;
 
+       conn->cmd_auth = NULL;
+       i_assert(cmd_auth != NULL);
+
        if (reply->status == 334) {
                const unsigned char *sasl_output;
                size_t sasl_output_len, input_len;
@@ -742,9 +746,12 @@ smtp_client_connection_auth_cb(const struct smtp_reply *reply,
                if (conn->sasl_ir != NULL) {
                        if (*reply->text_lines[0] == '\0') {
                                /* Send intial response */
-                               o_stream_nsend_str(conn->conn.output,
-                                                  conn->sasl_ir);
-                               o_stream_nsend_str(conn->conn.output, "\r\n");
+                               cmd = smtp_client_command_new(
+                                       conn, SMTP_CLIENT_COMMAND_FLAG_PRELOGIN,
+                                       smtp_client_connection_auth_cb, conn);
+                               smtp_client_command_write(cmd, conn->sasl_ir);
+                               smtp_client_command_submit_after(cmd, cmd_auth);
+                               conn->cmd_auth = cmd;
                                i_free(conn->sasl_ir);
                                return;
                        }
@@ -781,9 +788,12 @@ smtp_client_connection_auth_cb(const struct smtp_reply *reply,
                                MAX_BASE64_ENCODED_SIZE(sasl_output_len) + 2);
                        base64_encode(sasl_output, sasl_output_len,
                                      smtp_output);
-                       str_append(smtp_output, "\r\n");
-                       o_stream_nsend(conn->conn.output, str_data(smtp_output),
-                                      str_len(smtp_output));
+                       cmd = smtp_client_command_new(
+                               conn, SMTP_CLIENT_COMMAND_FLAG_PRELOGIN,
+                               smtp_client_connection_auth_cb, conn);
+                       smtp_client_command_write(cmd, conn->sasl_ir);
+                       smtp_client_command_submit_after(cmd, cmd_auth);
+                       conn->cmd_auth = cmd;
                        return;
                }
 
@@ -967,6 +977,7 @@ smtp_client_connection_authenticate(struct smtp_client_connection *conn)
                                           mech_name, init_resp);
        }
        smtp_client_command_submit(cmd);
+       conn->cmd_auth = cmd;
 
        smtp_client_connection_set_state(
                conn, SMTP_CLIENT_CONNECTION_STATE_AUTHENTICATING);
index b5b9cccff4c7f390f967a57853aec5623a0703c8..3b864f1e42adb5a935fa04fc2a67b894a3e9ee16 100644 (file)
@@ -195,8 +195,11 @@ struct smtp_client_connection {
        unsigned int xclient_replies_expected;
 
        struct dns_lookup *dns_lookup;
+
        struct dsasl_client *sasl_client;
        char *sasl_ir;
+       struct smtp_client_command *cmd_auth;
+
        struct timeout *to_connect, *to_trans, *to_commands, *to_cmd_fail;
        struct io *io_cmd_payload;