From: Aki Tuomi Date: Thu, 12 Oct 2023 10:57:20 +0000 (+0300) Subject: lib-auth-client: Copy connection mechs to client X-Git-Tag: 2.4.0~2509 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=12623438519dd1adbe636a0222f3254269ff9738;p=thirdparty%2Fdovecot%2Fcore.git lib-auth-client: Copy connection mechs to client This way they are available when connection is not. --- diff --git a/src/lib-auth-client/auth-client-connection.c b/src/lib-auth-client/auth-client-connection.c index 674a06210d..c232b18ae6 100644 --- a/src/lib-auth-client/auth-client-connection.c +++ b/src/lib-auth-client/auth-client-connection.c @@ -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, diff --git a/src/lib-auth-client/auth-client-private.h b/src/lib-auth-client/auth-client-private.h index 36b24631ba..c392b9195d 100644 --- a/src/lib-auth-client/auth-client-private.h +++ b/src/lib-auth-client/auth-client-private.h @@ -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; diff --git a/src/lib-auth-client/auth-client.c b/src/lib-auth-client/auth-client.c index 15321c4670..98fa3f1025 100644 --- a/src/lib-auth-client/auth-client.c +++ b/src/lib-auth-client/auth-client.c @@ -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; }