]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: db-lua - Use parameters structure to initialize script
authorAki Tuomi <aki.tuomi@open-xchange.com>
Tue, 9 May 2023 07:01:53 +0000 (10:01 +0300)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Fri, 19 May 2023 09:25:44 +0000 (09:25 +0000)
Simplifies next commit.

src/auth/db-lua.c
src/auth/db-lua.h
src/auth/passdb-lua.c
src/auth/test-lua.c
src/auth/userdb-lua.c

index 0c454547c42507438671a88ad8916d387460f168..adfb9c3d50b8fb2a2b1cc9d9fce5eef890bcc948 100644 (file)
@@ -393,8 +393,10 @@ static void auth_lua_dovecot_auth_register(lua_State *L)
        lua_pop(L, 1);
 }
 
-int auth_lua_script_init(struct dlua_script *script, const char **error_r)
+int auth_lua_script_init(const struct auth_lua_script_parameters *params,
+                        const char **error_r)
 {
+       struct dlua_script *script = params->script;
        dlua_dovecot_register(script);
        auth_lua_dovecot_auth_register(script->L);
        auth_lua_auth_request_register(script->L);
index ebb697ac1d9050177d45d69bd2788a7ab1309dfc..be08619224dc822ace672db64a0d70420201d7ca 100644 (file)
@@ -9,7 +9,12 @@
 
 struct dlua_script;
 
-int auth_lua_script_init(struct dlua_script *script, const char **error_r);
+struct auth_lua_script_parameters {
+       struct dlua_script *script;
+};
+
+int auth_lua_script_init(const struct auth_lua_script_parameters *params,
+                        const char **error_r);
 
 int auth_lua_call_password_verify(struct dlua_script *script,
                                  struct auth_request *req, const char *password,
index b67ab0667a45c9ba6f5b9b7e6f051edc2ceed79d..ad56e9983bbb032dd1a9cb5ab27c45c8b6a32f14 100644 (file)
@@ -155,9 +155,15 @@ static void passdb_lua_init(struct passdb_module *_module)
                (struct dlua_passdb_module *)_module;
        const char *error;
 
-       if (dlua_script_create_file(module->file, &module->script, auth_event, &error) < 0 ||
-           auth_lua_script_init(module->script, &error) < 0)
+       if (dlua_script_create_file(module->file, &module->script, auth_event, &error) < 0)
                i_fatal("passdb-lua: initialization failed: %s", error);
+
+       const struct auth_lua_script_parameters params = {
+               .script = module->script,
+       };
+       if (auth_lua_script_init(&params, &error) < 0)
+               i_fatal("passdb-lua: initialization failed: %s", error);
+
        module->has_password_verify =
                dlua_script_has_function(module->script, AUTH_LUA_PASSWORD_VERIFY);
 }
index 0b49f825e8000b60d873d2e419e671766c2d891f..a15915adeccf6026165f0b3e4ab705b44c8e3f9a 100644 (file)
@@ -45,7 +45,10 @@ static void test_db_lua_auth_verify(void)
 
         test_assert(dlua_script_create_string(luascript, &script, NULL, &error) == 0);
         if (script != NULL) {
-               test_assert(auth_lua_script_init(script, &error) == 0);
+               const struct auth_lua_script_parameters params = {
+                       .script = script,
+               };
+               test_assert(auth_lua_script_init(&params, &error) == 0);
                test_assert(auth_lua_call_password_verify(script, req, "password", &error) == 1);
                dlua_script_unref(&script);
        }
@@ -79,7 +82,10 @@ static void test_db_lua_auth_lookup_numberish_value(void)
 
        test_assert(dlua_script_create_string(luascript, &script, NULL, &error) == 0);
        if (script != NULL) {
-               test_assert(auth_lua_script_init(script, &error) == 0);
+               const struct auth_lua_script_parameters params = {
+                       .script = script,
+               };
+               test_assert(auth_lua_script_init(&params, &error) == 0);
                test_assert(auth_lua_call_passdb_lookup(script, req, &scheme, &pass, &error) == 1);
                test_assert(strcmp(req->fields.user, "01234") == 0);
                dlua_script_unref(&script);
@@ -112,7 +118,10 @@ static void test_db_lua_auth_lookup(void)
 
        test_assert(dlua_script_create_string(luascript, &script, NULL, &error) == 0);
        if (script != NULL) {
-               test_assert(auth_lua_script_init(script, &error) == 0);
+               const struct auth_lua_script_parameters params = {
+                       .script = script,
+               };
+               test_assert(auth_lua_script_init(&params, &error) == 0);
                test_assert(auth_lua_call_passdb_lookup(script, req, &scheme, &pass, &error) == 1);
                dlua_script_unref(&script);
                test_assert_strcmp(pass, "pass");
@@ -150,7 +159,10 @@ static void test_db_lua_auth_lookup_bad_keyname(void)
 
        test_assert(dlua_script_create_string(luascript, &script, NULL, &error) == 0);
        if (script != NULL) {
-               test_assert(auth_lua_script_init(script, &error) == 0);
+               const struct auth_lua_script_parameters params = {
+                       .script = script,
+               };
+               test_assert(auth_lua_script_init(&params, &error) == 0);
                test_expect_error_string_n_times("db-lua: Field key", 3);
                test_assert(auth_lua_call_passdb_lookup(script, req, &scheme, &pass, &error) == 1);
                dlua_script_unref(&script);
index 1712f701623bbe1899f303410e448113a0f737be..9453f1e8ebc0a9cd0bde6e416341b31c19a31e76 100644 (file)
@@ -79,8 +79,13 @@ static void userdb_lua_init(struct userdb_module *_module)
                (struct dlua_userdb_module *)_module;
        const char *error;
 
-       if (dlua_script_create_file(module->file, &module->script, auth_event, &error) < 0 ||
-           auth_lua_script_init(module->script, &error) < 0)
+       if (dlua_script_create_file(module->file, &module->script, auth_event, &error) < 0)
+               i_fatal("userdb-lua: initialization failed: %s", error);
+
+       const struct auth_lua_script_parameters params = {
+               .script = module->script,
+       };
+       if (auth_lua_script_init(&params, &error) < 0)
                i_fatal("userdb-lua: initialization failed: %s", error);
 }