]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: Set cache key for lua auth database
authorAki Tuomi <aki.tuomi@dovecot.fi>
Mon, 4 Dec 2017 17:05:55 +0000 (19:05 +0200)
committerAki Tuomi <aki.tuomi@dovecot.fi>
Mon, 4 Dec 2017 17:35:02 +0000 (19:35 +0200)
src/auth/db-lua.h
src/auth/passdb-lua.c
src/auth/userdb-lua.c

index c9b622bc826e58de7b019425023a1cca42aea60f..ebb697ac1d9050177d45d69bd2788a7ab1309dfc 100644 (file)
@@ -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;
index 032f4eafef4863e66013d0af9d037f21686e2854..57e0a3b25bb07612d5f9ccee1afd61982582a864 100644 (file)
@@ -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;
 }
 
index de7031b4a4212a357316c545fce41fa59c18fbd7..0774b39f3bed3b07395f439ce6c463ac1ccd553e 100644 (file)
@@ -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;
 }