#include "auth-common.h"
#include "userdb.h"
#include "auth-cache.h"
+#include "settings.h"
#if defined(BUILTIN_LUA) || defined(PLUGIN_BUILD)
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;
};
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)
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)
(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,
struct dlua_userdb_module *module =
(struct dlua_userdb_module *)_module;
dlua_script_unref(&module->script);
+ settings_free(module->set);
}
static struct userdb_iterate_context *
{
.name = "lua",
- .preinit_legacy = userdb_lua_preinit,
+ .preinit = userdb_lua_preinit,
.init = userdb_lua_init,
.deinit = userdb_lua_deinit,