From: Aki Tuomi Date: Fri, 25 Jul 2025 05:16:52 +0000 (+0300) Subject: auth: Use AUTH_CACHE_KEY_USER instead of per-database constants X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a70ce7d3e2f983979e971414c5892c4e30197231;p=thirdparty%2Fdovecot%2Fcore.git auth: Use AUTH_CACHE_KEY_USER instead of per-database constants Fixes cache key issue where users would end up overwriting each other in cache due to cache key being essentially static string because we no longer support %u. Forgotten in 2e298e7ee98b6df61cf85117f000290d60a473b8 --- diff --git a/src/auth/auth-settings.h b/src/auth/auth-settings.h index 1d420eceaa..90aba17ec3 100644 --- a/src/auth/auth-settings.h +++ b/src/auth/auth-settings.h @@ -1,6 +1,8 @@ #ifndef AUTH_SETTINGS_H #define AUTH_SETTINGS_H +#define AUTH_CACHE_KEY_USER "%{user}" + struct master_service; struct master_service_settings_output; diff --git a/src/auth/passdb-bsdauth.c b/src/auth/passdb-bsdauth.c index 68292679b7..1b86da4053 100644 --- a/src/auth/passdb-bsdauth.c +++ b/src/auth/passdb-bsdauth.c @@ -14,8 +14,6 @@ #include #include -#define BSDAUTH_CACHE_KEY "%u" - struct passdb_bsdauth_settings { pool_t pool; }; @@ -104,7 +102,7 @@ bsdauth_preinit(pool_t pool, struct event *event, &post_set, error_r) < 0) return -1; module->default_cache_key = auth_cache_parse_key_and_fields( - pool, BSDAUTH_CACHE_KEY, &post_set->fields, "bsdauth"); + pool, AUTH_CACHE_KEY_USER, &post_set->fields, "bsdauth"); settings_free(post_set); *module_r = module; diff --git a/src/auth/passdb-oauth2.c b/src/auth/passdb-oauth2.c index 96d902d323..91fed06018 100644 --- a/src/auth/passdb-oauth2.c +++ b/src/auth/passdb-oauth2.c @@ -53,7 +53,7 @@ oauth2_preinit(pool_t pool, struct event *event, struct passdb_module **module_r if (db_oauth2_init(event, TRUE, &module->db, error_r) < 0) return -1; module->module.default_pass_scheme = "PLAIN"; - module->module.default_cache_key = "%u"; + module->module.default_cache_key = AUTH_CACHE_KEY_USER; *module_r = &module->module; return 0; } diff --git a/src/auth/passdb-pam.c b/src/auth/passdb-pam.c index 2acbceb80a..fdf0f573ef 100644 --- a/src/auth/passdb-pam.c +++ b/src/auth/passdb-pam.c @@ -415,7 +415,8 @@ static int pam_preinit(pool_t pool, struct event *event, module = p_new(pool, struct pam_passdb_module, 1); module->module.default_cache_key = auth_cache_parse_key_and_fields(pool, - t_strdup_printf("%%u/%s", set->service_name), + t_strdup_printf("%"AUTH_CACHE_KEY_USER"\t%s", + set->service_name), &post_set->fields, "pam"); module->requests_left = set->max_requests; module->pam_setcred = set->setcred; diff --git a/src/auth/passdb-passwd.c b/src/auth/passdb-passwd.c index 13003151f9..22e2eae7fa 100644 --- a/src/auth/passdb-passwd.c +++ b/src/auth/passdb-passwd.c @@ -10,7 +10,6 @@ #include "safe-memset.h" #include "ipwd.h" -#define PASSWD_CACHE_KEY "%u" #define PASSWD_PASS_SCHEME "CRYPT" #undef DEF @@ -142,7 +141,7 @@ static int passwd_preinit(pool_t pool, struct event *event, &post_set, error_r) < 0) return -1; module->default_cache_key = auth_cache_parse_key_and_fields(pool, - PASSWD_CACHE_KEY, + AUTH_CACHE_KEY_USER, &post_set->fields, "passwd"); settings_free(post_set); diff --git a/src/auth/userdb-passwd.c b/src/auth/userdb-passwd.c index 5241129a0c..14cf90a6d6 100644 --- a/src/auth/userdb-passwd.c +++ b/src/auth/userdb-passwd.c @@ -9,7 +9,6 @@ #include "ipwd.h" #include "time-util.h" -#define USER_CACHE_KEY "%u" #define PASSWD_SLOW_WARN_MSECS (10*1000) #define PASSWD_SLOW_MASTER_WARN_MSECS 50 #define PASSDB_SLOW_MASTER_WARN_COUNT_INTERVAL 100 @@ -225,7 +224,7 @@ static int passwd_preinit(pool_t pool, struct event *event ATTR_UNUSED, struct passwd_userdb_module *module = p_new(pool, struct passwd_userdb_module, 1); - module->module.default_cache_key = USER_CACHE_KEY; + module->module.default_cache_key = AUTH_CACHE_KEY_USER; *module_r = &module->module; return 0; }