From: Markus Valentin Date: Fri, 16 Feb 2024 10:54:12 +0000 (+0100) Subject: auth: userdb-lua - Convert args to settings X-Git-Tag: 2.4.1~932 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f55e6621ef3ef8e6c42eb3c02b92d2b282817e6b;p=thirdparty%2Fdovecot%2Fcore.git auth: userdb-lua - Convert args to settings This changes userdb args based initialization to use actual settings: * file -> lua_file (global) * generic args -> auth_lua_config * blocking -> userdb_use_worker * cache_key is removed --- diff --git a/src/auth/userdb-lua.c b/src/auth/userdb-lua.c index d8351c974a..66ac75fa2f 100644 --- a/src/auth/userdb-lua.c +++ b/src/auth/userdb-lua.c @@ -3,6 +3,7 @@ #include "auth-common.h" #include "userdb.h" #include "auth-cache.h" +#include "settings.h" #if defined(BUILTIN_LUA) || defined(PLUGIN_BUILD) @@ -11,7 +12,7 @@ struct dlua_userdb_module { struct userdb_module module; struct dlua_script *script; - const char *file; + const struct auth_lua_settings *set; const char *const *arguments; }; @@ -22,6 +23,11 @@ static void userdb_lua_lookup(struct auth_request *auth_request, struct dlua_userdb_module *module = (struct dlua_userdb_module *)_module; const char *error; + + if (auth_request_set_userdb_fields(auth_request, NULL) < 0) { + callback(USERDB_RESULT_INTERNAL_FAILURE, auth_request); + return; + } enum userdb_result result = auth_lua_call_userdb_lookup(module->script, auth_request, &error); if (result == USERDB_RESULT_INTERNAL_FAILURE) @@ -30,62 +36,28 @@ static void userdb_lua_lookup(struct auth_request *auth_request, callback(result, auth_request); } -static struct userdb_module * -userdb_lua_preinit(pool_t pool, const char *args) +static int +userdb_lua_preinit(pool_t pool, struct event *event, + struct userdb_module **module_r, const char **error_r) { + unsigned int count; + const struct auth_lua_settings *set; struct dlua_userdb_module *module; - const char *cache_key = DB_LUA_CACHE_KEY; - bool blocking = TRUE; - module = p_new(pool, struct dlua_userdb_module, 1); - const char *const *fields = t_strsplit_spaces(args, " "); - ARRAY_TYPE(const_string) arguments; - t_array_init(&arguments, 8); - - while(*fields != NULL) { - const char *key, *value; - if (!t_split_key_value_eq(*fields, &key, &value)) { - /* pass */ - } else if (strcmp(key, "file") == 0) { - module->file = p_strdup(pool, value); - } else if (strcmp(key, "blocking") == 0) { - if (strcmp(value, "yes") == 0) { - blocking = TRUE; - } else if (strcmp(value, "no") == 0) { - blocking = FALSE; - } else { - i_fatal("Invalid value %s. " - "Field blocking must be yes or no", - value); - } - } else if (strcmp(key, "cache_key") == 0) { - if (value[0] != '\0') - cache_key = value; - else /* explicitly disable auth caching for lua */ - cache_key = NULL; - } - - /* Catch arguments for lua initialization */ - const char **argument = array_append_space(&arguments); - *argument = key; - argument = array_append_space(&arguments); - *argument = value; - fields++; + if (settings_get(event, &auth_lua_setting_parser_info, 0, &set, + error_r) < 0) { + event_unref(&event); + return -1; } - if (module->file == NULL) - i_fatal("userdb-lua: Missing mandatory file= parameter"); + module = p_new(pool, struct dlua_userdb_module, 1); + module->set = set; - module->module.blocking = blocking; - if (cache_key != NULL) { - module->module.default_cache_key = - auth_cache_parse_key(pool, cache_key); - } - if (array_count(&arguments) > 0) { - array_append_zero(&arguments); - module->arguments = array_front(&arguments); - } - return &module->module; + if (!array_is_empty(&set->auth_lua_config)) + module->arguments = array_get(&set->auth_lua_config, &count); + + *module_r = &module->module; + return 0; } static void userdb_lua_init(struct userdb_module *_module) @@ -94,8 +66,10 @@ 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) - i_fatal("userdb-lua: failed to load '%s': %s", module->file, 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, @@ -111,6 +85,7 @@ static void userdb_lua_deinit(struct userdb_module *_module) struct dlua_userdb_module *module = (struct dlua_userdb_module *)_module; dlua_script_unref(&module->script); + settings_free(module->set); } static struct userdb_iterate_context * @@ -143,7 +118,7 @@ struct userdb_module_interface userdb_lua_plugin = { .name = "lua", - .preinit_legacy = userdb_lua_preinit, + .preinit = userdb_lua_preinit, .init = userdb_lua_init, .deinit = userdb_lua_deinit,