From: Aki Tuomi Date: Wed, 3 Jun 2020 05:32:58 +0000 (+0300) Subject: auth: db-oauth2 - Keep initialized oauth2 databases in memory X-Git-Tag: 2.4.1~1022 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=88d3317b698ef57cb5cd71e439effcefe6efe96b;p=thirdparty%2Fdovecot%2Fcore.git auth: db-oauth2 - Keep initialized oauth2 databases in memory Removes refcounting. This avoids losing cache. Simplifies next change. --- diff --git a/src/auth/db-oauth2.c b/src/auth/db-oauth2.c index 80b295d073..77e86dd3b1 100644 --- a/src/auth/db-oauth2.c +++ b/src/auth/db-oauth2.c @@ -82,8 +82,6 @@ struct db_oauth2 { struct oauth2_settings oauth2_set; struct db_oauth2_request *head; - - unsigned int refcount; }; static struct db_oauth2 *db_oauth2_head = NULL; @@ -157,7 +155,6 @@ struct db_oauth2 *db_oauth2_init(const char *config_path) for(db = db_oauth2_head; db != NULL; db = db->next) { if (strcmp(db->config_path, config_path) == 0) { - db->refcount++; return db; } } @@ -165,7 +162,6 @@ struct db_oauth2 *db_oauth2_init(const char *config_path) pool_t pool = pool_alloconly_create("db_oauth2", 128); db = p_new(pool, struct db_oauth2, 1); db->pool = pool; - db->refcount = 1; db->config_path = p_strdup(pool, config_path); db->set = default_oauth2_settings; @@ -253,18 +249,9 @@ struct db_oauth2 *db_oauth2_init(const char *config_path) return db; } -void db_oauth2_ref(struct db_oauth2 *db) -{ - i_assert(db->refcount > 0); - db->refcount++; -} - -void db_oauth2_unref(struct db_oauth2 **_db) +static void db_oauth2_free(struct db_oauth2 **_db) { struct db_oauth2 *ptr, *db = *_db; - i_assert(db->refcount > 0); - - if (--db->refcount > 0) return; for(ptr = db_oauth2_head; ptr != NULL; ptr = ptr->next) { if (ptr == db) { @@ -846,3 +833,11 @@ bool db_oauth2_uses_password_grant(const struct db_oauth2 *db) { return db->set.use_grant_password; } + +void db_oauth2_deinit(void) +{ + while (db_oauth2_head != NULL) { + struct db_oauth2 *db = db_oauth2_head; + db_oauth2_free(&db); + } +} diff --git a/src/auth/db-oauth2.h b/src/auth/db-oauth2.h index c2d2d37edc..b4313743d8 100644 --- a/src/auth/db-oauth2.h +++ b/src/auth/db-oauth2.h @@ -32,9 +32,6 @@ struct db_oauth2_request { struct db_oauth2 *db_oauth2_init(const char *config_path); -void db_oauth2_ref(struct db_oauth2 *); -void db_oauth2_unref(struct db_oauth2 **); - bool db_oauth2_uses_password_grant(const struct db_oauth2 *db); const char *db_oauth2_get_openid_configuration_url(const struct db_oauth2 *db); @@ -45,4 +42,6 @@ void db_oauth2_lookup(struct db_oauth2 *db, struct db_oauth2_request *req, const CALLBACK_TYPECHECK(callback, void(*)(struct db_oauth2_request *, enum passdb_result, const char*, typeof(context))), \ request, (db_oauth2_lookup_callback_t*)callback, (void*)context) +void db_oauth2_deinit(void); + #endif diff --git a/src/auth/main.c b/src/auth/main.c index d4e0f88ae3..bc203d7e4b 100644 --- a/src/auth/main.c +++ b/src/auth/main.c @@ -31,6 +31,7 @@ #include "auth-master-connection.h" #include "auth-client-connection.h" #include "auth-policy.h" +#include "db-oauth2.h" #include #include @@ -269,6 +270,7 @@ static void main_deinit(void) auth_policy_deinit(); mech_register_deinit(&mech_reg); mech_otp_deinit(); + db_oauth2_deinit(); mech_deinit(global_auth_settings); settings_free(global_auth_settings); diff --git a/src/auth/passdb-oauth2.c b/src/auth/passdb-oauth2.c index 52245a05fe..a5331d8fd6 100644 --- a/src/auth/passdb-oauth2.c +++ b/src/auth/passdb-oauth2.c @@ -61,10 +61,8 @@ oauth2_preinit(pool_t pool, const char *args) return &module->module; } -static void oauth2_deinit(struct passdb_module *passdb) +static void oauth2_deinit(struct passdb_module *passdb ATTR_UNUSED) { - struct oauth2_passdb_module *module = (struct oauth2_passdb_module *)passdb; - db_oauth2_unref(&module->db); } /* FIXME: Remove when oauth2 mech is fixed */