]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: db-lua - Support passing arguments to auth_passdb/userdb_init()
authorAki Tuomi <aki.tuomi@open-xchange.com>
Tue, 9 May 2023 07:56:41 +0000 (10:56 +0300)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Fri, 19 May 2023 09:25:44 +0000 (09:25 +0000)
src/auth/db-lua.c
src/auth/db-lua.h

index 0f1519371b786c34208ea7c78c6c3c2328b03d7b..e086307c2ece1830c1c38b1ee845bb661cde95a9 100644 (file)
@@ -449,9 +449,21 @@ int auth_lua_script_init(const struct auth_lua_script_parameters *params,
        }
        if (!dlua_script_has_function(script, fn))
                return 0;
+       i_assert(params->arguments == NULL ||
+                (str_array_length(params->arguments) % 2 == 0));
+       if (params->arguments != NULL) {
+               /* prepare a table for arguments */
+               lua_createtable(script->L, 0, str_array_length(params->arguments) / 2);
+               for (const char *const *p = params->arguments; *p != NULL; p += 2) {
+                       lua_pushstring(script->L, p[1]);
+                       lua_setfield(script->L, -2, p[0]);
+               }
+       } else {
+               lua_newtable(script->L);
+       }
 
        /* call the function */
-       if (dlua_pcall(script->L, fn, 0, 0, error_r) < 0)
+       if (dlua_pcall(script->L, fn, 1, 0, error_r) < 0)
                return -1;
 
        i_assert(lua_gettop(script->L) == 0);
index 8188eadfdc4d932a7c27ec06bec3299cc40565b7..cccc8d59c7371c09ba0e49a3b40e7f77b2228ff9 100644 (file)
@@ -17,6 +17,7 @@ enum auth_lua_script_type {
 struct auth_lua_script_parameters {
        enum auth_lua_script_type stype;
        struct dlua_script *script;
+       const char *const *arguments;
 };
 
 int auth_lua_script_init(const struct auth_lua_script_parameters *params,