]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-auth-client: Copy connection mechs to client
authorAki Tuomi <aki.tuomi@open-xchange.com>
Thu, 12 Oct 2023 10:57:20 +0000 (13:57 +0300)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Thu, 19 Oct 2023 18:00:45 +0000 (18:00 +0000)
This way they are available when connection is not.

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

index 674a06210d30d633e3967638281b6b41c1acb85d..c232b18ae6238b60c116a59cc4c530d0aed4a41b 100644 (file)
@@ -197,6 +197,18 @@ static void auth_client_connection_handshake_ready(struct connection *_conn)
        struct auth_client_connection *conn =
                container_of(_conn, struct auth_client_connection, conn);
 
+       struct auth_mech_desc *mech_desc;
+       array_foreach_modifiable(&conn->client->available_auth_mechs, mech_desc) {
+               i_free(mech_desc->name);
+       }
+       array_clear(&conn->client->available_auth_mechs);
+       array_foreach_modifiable(&conn->available_auth_mechs, mech_desc) {
+               struct auth_mech_desc *dup_desc =
+                       array_append_space(&conn->client->available_auth_mechs);
+               *dup_desc = *mech_desc;
+               dup_desc->name = i_strdup(mech_desc->name);
+       }
+
        timeout_remove(&conn->to);
        if (conn->client->connect_notify_callback != NULL) {
                conn->client->connect_notify_callback(conn->client, TRUE,
index 36b24631ba98998428b47c028edb5613e625532a..c392b9195d716b63da38040e8cbefaf36c2d3240 100644 (file)
@@ -48,6 +48,7 @@ struct auth_client {
 
        struct connection_list *clist;
        struct auth_client_connection *conn;
+       ARRAY(struct auth_mech_desc) available_auth_mechs;
 
        auth_connect_notify_callback_t *connect_notify_callback;
        void *connect_notify_context;
index 15321c46703facdadfa8bd6d16528c35052f56c9..98fa3f1025c64afd458b41c4a63a47a4d5b720df 100644 (file)
@@ -21,6 +21,7 @@ auth_client_init(const char *auth_socket_path, unsigned int client_pid,
        client->connect_timeout_msecs = AUTH_CONNECT_TIMEOUT_MSECS;
        client->clist = auth_client_connection_list_init();
 
+       i_array_init(&client->available_auth_mechs, 8);
        client->event = event_create(NULL);
        event_add_category(client->event, &event_category_auth_client);
        event_set_append_log_prefix(client->event, "auth-client: ");
@@ -33,6 +34,7 @@ auth_client_init(const char *auth_socket_path, unsigned int client_pid,
 void auth_client_deinit(struct auth_client **_client)
 {
        struct auth_client *client = *_client;
+       struct auth_mech_desc *mech_desc;
 
        if (client == NULL)
                return;
@@ -41,6 +43,9 @@ void auth_client_deinit(struct auth_client **_client)
        auth_client_connection_deinit(&client->conn);
        connection_list_deinit(&client->clist);
        event_unref(&client->event);
+       array_foreach_modifiable(&client->available_auth_mechs, mech_desc)
+               i_free(mech_desc->name);
+       array_free(&client->available_auth_mechs);
        i_free(client->auth_socket_path);
        i_free(client);
 }
@@ -86,9 +91,7 @@ const struct auth_mech_desc *
 auth_client_get_available_mechs(struct auth_client *client,
                                unsigned int *mech_count)
 {
-       i_assert(auth_client_is_connected(client));
-
-       return array_get(&client->conn->available_auth_mechs, mech_count);
+       return array_get(&client->available_auth_mechs, mech_count);
 }
 
 const struct auth_mech_desc *
@@ -96,7 +99,7 @@ auth_client_find_mech(struct auth_client *client, const char *name)
 {
        const struct auth_mech_desc *mech;
 
-       array_foreach(&client->conn->available_auth_mechs, mech) {
+       array_foreach(&client->available_auth_mechs, mech) {
                if (strcasecmp(mech->name, name) == 0)
                        return mech;
        }