From: Aki Tuomi Date: Mon, 4 Dec 2017 17:05:55 +0000 (+0200) Subject: auth: Set cache key for lua auth database X-Git-Tag: 2.3.0.rc1~288 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=208b68bb91609f44d2d013ac8a163e0ca89034db;p=thirdparty%2Fdovecot%2Fcore.git auth: Set cache key for lua auth database --- diff --git a/src/auth/db-lua.h b/src/auth/db-lua.h index c9b622bc82..ebb697ac1d 100644 --- a/src/auth/db-lua.h +++ b/src/auth/db-lua.h @@ -3,6 +3,8 @@ #include "dlua-script.h" +#define DB_LUA_CACHE_KEY "%u" + #define AUTH_LUA_PASSWORD_VERIFY "auth_password_verify" struct dlua_script; diff --git a/src/auth/passdb-lua.c b/src/auth/passdb-lua.c index 032f4eafef..57e0a3b25b 100644 --- a/src/auth/passdb-lua.c +++ b/src/auth/passdb-lua.c @@ -2,6 +2,7 @@ #include "auth-common.h" #include "passdb.h" +#include "auth-cache.h" #if defined(BUILTIN_LUA) || defined(PLUGIN_BUILD) @@ -100,6 +101,8 @@ passdb_lua_verify_plain(struct auth_request *request, const char *password, static struct passdb_module * passdb_lua_preinit(pool_t pool, const char *args) { + const char *cache_key = "%u"; + const char *scheme = "PLAIN"; struct dlua_passdb_module *module; bool blocking = TRUE; @@ -119,6 +122,13 @@ passdb_lua_preinit(pool_t pool, const char *args) "Field blocking must be yes or no", value); } + } else if (strncmp(*fields, "cache_key=", 10) == 0) { + if (*((*fields)+10) != '\0') + cache_key = (*fields)+10; + else /* explicitly disable auth caching for lua */ + cache_key = NULL; + } else if (strncmp(*fields, "scheme=", 7) == 0) { + scheme = p_strdup(pool, (*fields)+7); } else { i_fatal("Unsupported parameter %s", *fields); } @@ -129,6 +139,9 @@ passdb_lua_preinit(pool_t pool, const char *args) i_fatal("passdb-lua: Missing mandatory file= parameter"); module->module.blocking = blocking; + module->module.default_cache_key = + auth_cache_parse_key(pool, cache_key); + module->module.default_pass_scheme = scheme; return &module->module; } diff --git a/src/auth/userdb-lua.c b/src/auth/userdb-lua.c index de7031b4a4..0774b39f3b 100644 --- a/src/auth/userdb-lua.c +++ b/src/auth/userdb-lua.c @@ -2,6 +2,7 @@ #include "auth-common.h" #include "userdb.h" +#include "auth-cache.h" #if defined(BUILTIN_LUA) || defined(PLUGIN_BUILD) @@ -32,6 +33,7 @@ static struct userdb_module * userdb_lua_preinit(pool_t pool, const char *args) { struct dlua_userdb_module *module; + const char *cache_key = "%u"; bool blocking = TRUE; module = p_new(pool, struct dlua_userdb_module, 1); @@ -50,6 +52,11 @@ userdb_lua_preinit(pool_t pool, const char *args) "Field blocking must be yes or no", value); } + } else if (strncmp(*fields, "cache_key=", 10) == 0) { + if (*((*fields)+10) != '\0') + cache_key = (*fields)+10; + else /* explicitly disable auth caching for lua */ + cache_key = NULL; } else { i_fatal("Unsupported parameter %s", *fields); } @@ -60,6 +67,10 @@ userdb_lua_preinit(pool_t pool, const char *args) i_fatal("userdb-lua: Missing mandatory file= parameter"); module->module.blocking = blocking; + if (cache_key != NULL) { + module->module.default_cache_key = + auth_cache_parse_key(pool, cache_key); + } return &module->module; }