]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
login-common: client_auth_parse_args() - Don't modify client directly
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 14 May 2020 18:12:03 +0000 (21:12 +0300)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Mon, 17 Jan 2022 11:52:08 +0000 (13:52 +0200)
Return alt_usernames in reply, and modify client in
client_auth_handle_reply().

src/login-common/client-common-auth.c
src/login-common/client-common.h

index 716061e338bee170b6a22dd46bed9356856ceb8f..c31db7f1a31b3e6c8af5ffecfa235676db27c4cb 100644 (file)
@@ -129,15 +129,14 @@ static void alt_username_set(ARRAY_TYPE(const_string) *alt_usernames, pool_t poo
        array_push_back(alt_usernames, &value);
 }
 
-static void client_auth_parse_args(struct client *client, bool success,
+static void client_auth_parse_args(const struct client *client, bool success,
                                   const char *const *args,
                                   struct client_auth_reply *reply_r)
 {
        const char *key, *value, *p, *error;
-       ARRAY_TYPE(const_string) alt_usernames;
 
-       t_array_init(&alt_usernames, 4);
        i_zero(reply_r);
+       t_array_init(&reply_r->alt_usernames, 4);
        reply_r->proxy_host_immediate_failure_after_secs =
                LOGIN_PROXY_DEFAULT_HOST_IMMEDIATE_FAILURE_AFTER_SECS;
 
@@ -233,23 +232,14 @@ static void client_auth_parse_args(struct client *client, bool success,
                        /* already handled in sasl-server.c */
                } else if (str_begins(key, "user_")) {
                        if (success) {
-                               alt_username_set(&alt_usernames, client->pool,
-                                                key, value);
+                               alt_username_set(&reply_r->alt_usernames,
+                                                client->pool, key, value);
                        }
                } else if (str_begins(key, "forward_")) {
                        /* these are passed to upstream */
                } else
                        e_debug(event_auth, "Ignoring unknown passdb extra field: %s", key);
        }
-       if (array_count(&alt_usernames) > 0) {
-               const char **alt;
-
-               alt = p_new(client->pool, const char *,
-                           array_count(&alt_usernames) + 1);
-               memcpy(alt, array_front(&alt_usernames),
-                      sizeof(*alt) * array_count(&alt_usernames));
-               client->alt_usernames = alt;
-       }
        if (reply_r->port == 0)
                reply_r->port = login_binary->default_port;
 
@@ -587,6 +577,16 @@ static bool
 client_auth_handle_reply(struct client *client,
                         const struct client_auth_reply *reply, bool success)
 {
+       if (array_count(&reply->alt_usernames) > 0) {
+               const char **alt;
+
+               alt = p_new(client->pool, const char *,
+                           array_count(&reply->alt_usernames) + 1);
+               memcpy(alt, array_front(&reply->alt_usernames),
+                      sizeof(*alt) * array_count(&reply->alt_usernames));
+               client->alt_usernames = alt;
+       }
+
        if (reply->proxy) {
                /* we want to proxy the connection to another server.
                   don't do this unless authentication succeeded. with
index 064cba6aaea24a33edaacb0e97b48e4b25d8b9b8..8c5c3dd004fe48811a38ca209f9f8ba20cc7e438 100644 (file)
@@ -96,6 +96,7 @@ enum client_list_type {
 struct client_auth_reply {
        const char *master_user, *reason;
        enum client_auth_fail_code fail_code;
+       ARRAY_TYPE(const_string) alt_usernames;
 
        /* for proxying */
        const char *host, *hostip, *source_ip;