From: Timo Sirainen Date: Thu, 6 Nov 2025 12:48:47 +0000 (+0200) Subject: auth: Don't initialize cache key if caching is disabled for the userdb X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fefaf8cf848be0aafec7b82b4cd1835759216c7d;p=thirdparty%2Fdovecot%2Fcore.git auth: Don't initialize cache key if caching is disabled for the userdb --- diff --git a/src/auth/auth.c b/src/auth/auth.c index e301e6a344..3486b4c18e 100644 --- a/src/auth/auth.c +++ b/src/auth/auth.c @@ -187,7 +187,8 @@ auth_userdb_preinit(struct auth *auth, const struct auth_userdb_settings *_set) for (dest = &auth->userdbs; *dest != NULL; dest = &(*dest)->next) ; *dest = auth_userdb; - auth_userdb->userdb = userdb_preinit(auth->pool, event, set); + auth_userdb->userdb = userdb_preinit(auth->pool, event, set, + auth->protocol_set->cache_size > 0); if (auth_userdb->userdb->default_cache_key != NULL && set->use_cache) { auth_userdb->cache_key = auth_userdb->userdb->default_cache_key; } else { diff --git a/src/auth/userdb-ldap.c b/src/auth/userdb-ldap.c index 3f0d3824a0..7d6d2bc38a 100644 --- a/src/auth/userdb-ldap.c +++ b/src/auth/userdb-ldap.c @@ -314,7 +314,7 @@ static int userdb_ldap_iterate_deinit(struct userdb_iterate_context *_ctx) static int userdb_ldap_preinit(pool_t pool, struct event *event, - const struct userdb_parameters *userdb_params ATTR_UNUSED, + const struct userdb_parameters *userdb_params, struct userdb_module **module_r, const char **error_r ATTR_UNUSED) { @@ -343,10 +343,11 @@ userdb_ldap_preinit(pool_t pool, struct event *event, db_ldap_get_attribute_names(pool, &ldap_post->iterate_fields, &module->iterate_attributes, NULL, NULL); - module->module.default_cache_key = auth_cache_parse_key_and_fields( - pool, t_strconcat(ldap_pre->ldap_base, - ldap_pre->userdb_ldap_filter, NULL), - &auth_post->fields, NULL); + module->module.default_cache_key = !userdb_params->use_cache ? NULL : + auth_cache_parse_key_and_fields(pool, + t_strconcat(ldap_pre->ldap_base, + ldap_pre->userdb_ldap_filter, NULL), + &auth_post->fields, NULL); *module_r = &module->module; ret = 0; diff --git a/src/auth/userdb-sql.c b/src/auth/userdb-sql.c index bbf5e0dded..74972b4ecd 100644 --- a/src/auth/userdb-sql.c +++ b/src/auth/userdb-sql.c @@ -292,7 +292,7 @@ static int userdb_sql_iterate_deinit(struct userdb_iterate_context *_ctx) static int userdb_sql_preinit(pool_t pool, struct event *event, - const struct userdb_parameters *userdb_params ATTR_UNUSED, + const struct userdb_parameters *userdb_params, struct userdb_module **module_r, const char **error_r) { struct sql_userdb_module *module; @@ -319,7 +319,7 @@ userdb_sql_preinit(pool_t pool, struct event *event, return -1; } - module->module.default_cache_key = + module->module.default_cache_key = !userdb_params->use_cache ? NULL : auth_cache_parse_key_and_fields(pool, set->query, &post_set->fields, "sql"); settings_free(set); diff --git a/src/auth/userdb.c b/src/auth/userdb.c index 09873d33c1..930f660f9f 100644 --- a/src/auth/userdb.c +++ b/src/auth/userdb.c @@ -100,7 +100,7 @@ gid_t userdb_parse_gid(struct auth_request *request, const char *str) struct userdb_module * userdb_preinit(pool_t pool, struct event *event, - const struct auth_userdb_settings *set) + const struct auth_userdb_settings *set, bool use_cache) { static unsigned int auth_userdb_id = 0; struct userdb_module_interface *iface; @@ -121,8 +121,9 @@ userdb_preinit(pool_t pool, struct event *event, } if (iface->preinit != NULL) { - struct userdb_parameters params; - i_zero(¶ms); + struct userdb_parameters params = { + .use_cache = use_cache && set->use_cache, + }; if (iface->preinit(pool, event, ¶ms, &userdb, &error) < 0) i_fatal("userdb %s: %s", set->name, error); userdb->blocking = set->use_worker; diff --git a/src/auth/userdb.h b/src/auth/userdb.h index 96410f4af2..cb4226fcc9 100644 --- a/src/auth/userdb.h +++ b/src/auth/userdb.h @@ -45,6 +45,8 @@ struct userdb_iterate_context { }; struct userdb_parameters { + /* Enable cache for the userdb */ + bool use_cache; }; struct userdb_module_interface { @@ -78,7 +80,7 @@ gid_t userdb_parse_gid(struct auth_request *request, const char *str) struct userdb_module * userdb_preinit(pool_t pool, struct event *event, - const struct auth_userdb_settings *set); + const struct auth_userdb_settings *set, bool use_cache); void userdb_init(struct userdb_module *userdb); void userdb_deinit(struct userdb_module *userdb);