]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: [user|pass]db-lua: Call auth_lua_script_get_default_cache_key() from preinit
authorMarkus Valentin <markus.valentin@open-xchange.com>
Wed, 21 Feb 2024 12:31:42 +0000 (13:31 +0100)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Fri, 17 Jan 2025 08:39:58 +0000 (10:39 +0200)
Try to get the default_cache_key from the lua-[user|pass]db when running
the preinit. This allows the lua script to set the default_cache_key
themselves.

src/auth/passdb-lua.c
src/auth/userdb-lua.c

index e7892bcfda3475722bdbf2f2c31a7152ff62ef15..9cdc81a7bf871d12ca39b6ecd9e57e13d2900441 100644 (file)
@@ -132,6 +132,24 @@ passdb_lua_preinit(pool_t pool, struct event *event,
        if (!array_is_empty(&set->auth_lua_config))
                module->arguments = array_get(&set->auth_lua_config, &count);
 
+       if (dlua_script_create_file(module->set->auth_lua_file, &module->script,
+                                   event, error_r) < 0)
+               i_fatal("passdb-lua: failed to load '%s': %s",
+                       module->set->auth_lua_file, *error_r);
+
+       const struct auth_lua_script_parameters params = {
+               .script = module->script,
+               .stype = AUTH_LUA_SCRIPT_TYPE_PASSDB,
+               .arguments = module->arguments,
+               .passdb_module = &module->module,
+               .pool = pool,
+       };
+       if (auth_lua_script_init(&params, error_r) < 0)
+               i_fatal("passdb-lua: script_init() failed: %s", *error_r);
+       if (auth_lua_script_get_default_cache_key(&params, error_r) < 0)
+               i_fatal("passdb-lua: auth_passdb_get_cache_key() failed: %s",
+                       *error_r);
+
        *module_r = &module->module;
        return 0;
 }
@@ -142,18 +160,11 @@ static void passdb_lua_init(struct passdb_module *_module)
                (struct dlua_passdb_module *)_module;
        const char *error;
 
-       if (dlua_script_create_file(module->set->auth_lua_file, &module->script,
-                                   auth_event, &error) < 0)
-               i_fatal("passdb-lua: failed to load '%s': %s",
-                       module->set->auth_lua_file, error);
-
        const struct auth_lua_script_parameters params = {
                .script = module->script,
                .stype = AUTH_LUA_SCRIPT_TYPE_PASSDB,
                .arguments = module->arguments,
        };
-       if (auth_lua_script_init(&params, &error) < 0)
-               i_fatal("passdb-lua: script_init() failed: %s", error);
        if (auth_lua_script_auth_db_init(&params, &error) < 0)
                i_fatal("passdb-lua: auth_passdb_init() failed: %s", error);
 
index 6138ab726d92fae84726c4c53c6bd45aba7beb47..b5a5a159bb33db9ae1fcddf2ef073ac05fae1f82 100644 (file)
@@ -56,6 +56,24 @@ userdb_lua_preinit(pool_t pool, struct event *event,
        if (!array_is_empty(&set->auth_lua_config))
                module->arguments = array_get(&set->auth_lua_config, &count);
 
+       if (dlua_script_create_file(module->set->auth_lua_file, &module->script,
+                                   event, error_r) < 0)
+               i_fatal("userdb-lua: failed to load '%s': %s",
+                       module->set->auth_lua_file, *error_r);
+
+       const struct auth_lua_script_parameters params = {
+               .script = module->script,
+               .stype = AUTH_LUA_SCRIPT_TYPE_USERDB,
+               .userdb_module = &module->module,
+               .arguments = module->arguments,
+               .pool = pool,
+       };
+       if (auth_lua_script_init(&params, error_r) < 0)
+               i_fatal("userdb-lua: script_init() failed: %s", *error_r);
+       if (auth_lua_script_get_default_cache_key(&params, error_r) < 0)
+               i_fatal("userdb-lua: auth_userdb_get_cache_key() failed: %s",
+                       *error_r);
+
        *module_r = &module->module;
        return 0;
 }
@@ -66,18 +84,11 @@ static void userdb_lua_init(struct userdb_module *_module)
                (struct dlua_userdb_module *)_module;
        const char *error;
 
-       if (dlua_script_create_file(module->set->auth_lua_file, &module->script,
-                               auth_event, &error) < 0)
-               i_fatal("userdb-lua: failed to load '%s': %s",
-                       module->set->auth_lua_file, error);
-
        const struct auth_lua_script_parameters params = {
                .script = module->script,
                .stype = AUTH_LUA_SCRIPT_TYPE_USERDB,
                .arguments = module->arguments,
        };
-       if (auth_lua_script_init(&params, &error) < 0)
-               i_fatal("userdb-lua: script_init() failed: %s", error);
        if (auth_lua_script_auth_db_init(&params, &error) < 0)
                i_fatal("userdb-lua: auth_userdb_init() failed: %s", error);
 }