dovecot-2.1: auth: Lazily load authdb_* and mech_* plugins only ...

dovecot at dovecot.org dovecot at dovecot.org
Sat Oct 1 17:26:18 EEST 2011


details:   http://hg.dovecot.org/dovecot-2.1/rev/695e9d58ed17
changeset: 13571:695e9d58ed17
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Oct 01 17:34:39 2011 +0300
description:
auth: Lazily load authdb_* and mech_* plugins only when they're needed.

diffstat:

 src/auth/auth-common.h |   1 +
 src/auth/main.c        |  26 ++++++++++++++++++++++++++
 src/auth/mech.c        |  13 +++++++++----
 src/auth/passdb.c      |   5 +++++
 src/auth/userdb.c      |   5 +++++
 5 files changed, 46 insertions(+), 4 deletions(-)

diffs (120 lines):

diff -r f53cf5670adf -r 695e9d58ed17 src/auth/auth-common.h
--- a/src/auth/auth-common.h	Sat Oct 01 17:24:09 2011 +0300
+++ b/src/auth/auth-common.h	Sat Oct 01 17:34:39 2011 +0300
@@ -9,5 +9,6 @@
 extern struct auth_penalty *auth_penalty;
 
 void auth_refresh_proctitle(void);
+void auth_module_load(const char *names);
 
 #endif
diff -r f53cf5670adf -r 695e9d58ed17 src/auth/main.c
--- a/src/auth/main.c	Sat Oct 01 17:24:09 2011 +0300
+++ b/src/auth/main.c	Sat Oct 01 17:34:39 2011 +0300
@@ -148,6 +148,16 @@
 	}
 }
 
+static bool auth_module_filter(const char *name, void *context ATTR_UNUSED)
+{
+	if (strncmp(name, "authdb_", 7) == 0 ||
+	    strncmp(name, "mech_", 5) == 0) {
+		/* this is lazily loaded */
+		return FALSE;
+	}
+	return TRUE;
+}
+
 static void main_preinit(void)
 {
 	struct module_dir_load_settings mod_set;
@@ -173,6 +183,7 @@
 	mod_set.version = master_service_get_version_string(master_service);
 	mod_set.require_init_funcs = TRUE;
 	mod_set.debug = global_auth_settings->debug;
+	mod_set.filter_callback = auth_module_filter;
 
 	modules = module_dir_load(AUTH_MODULE_DIR, NULL, &mod_set);
 	module_dir_init(modules);
@@ -191,6 +202,21 @@
 	restrict_access_allow_coredumps(TRUE);
 }
 
+void auth_module_load(const char *names)
+{
+	struct module_dir_load_settings mod_set;
+
+	memset(&mod_set, 0, sizeof(mod_set));
+	mod_set.version = master_service_get_version_string(master_service);
+	mod_set.require_init_funcs = TRUE;
+	mod_set.debug = global_auth_settings->debug;
+	mod_set.ignore_missing = TRUE;
+
+	modules = module_dir_load_missing(modules, AUTH_MODULE_DIR, names,
+					  &mod_set);
+	module_dir_init(modules);
+}
+
 static void main_init(void)
 {
         process_start_time = ioloop_time;
diff -r f53cf5670adf -r 695e9d58ed17 src/auth/mech.c
--- a/src/auth/mech.c	Sat Oct 01 17:24:09 2011 +0300
+++ b/src/auth/mech.c	Sat Oct 01 17:34:39 2011 +0300
@@ -127,17 +127,22 @@
 
 	mechanisms = t_strsplit_spaces(set->mechanisms, " ");
 	for (; *mechanisms != NULL; mechanisms++) {
-		if (strcasecmp(*mechanisms, "ANONYMOUS") == 0) {
+		const char *name = *mechanisms;
+
+		if (strcasecmp(name, "ANONYMOUS") == 0) {
 			if (*set->anonymous_username == '\0') {
 				i_fatal("ANONYMOUS listed in mechanisms, "
 					"but anonymous_username not set");
 			}
 		}
-		mech = mech_module_find(*mechanisms);
+		mech = mech_module_find(name);
 		if (mech == NULL) {
-			i_fatal("Unknown authentication mechanism '%s'",
-				*mechanisms);
+			/* maybe it's a plugin. try to load it. */
+			auth_module_load(t_strconcat("mech_", name, NULL));
+			mech = mech_module_find(name);
 		}
+		if (mech == NULL)
+			i_fatal("Unknown authentication mechanism '%s'", name);
 		mech_register_add(reg, mech);
 	}
 
diff -r f53cf5670adf -r 695e9d58ed17 src/auth/passdb.c
--- a/src/auth/passdb.c	Sat Oct 01 17:24:09 2011 +0300
+++ b/src/auth/passdb.c	Sat Oct 01 17:34:39 2011 +0300
@@ -191,6 +191,11 @@
 	unsigned int idx;
 
 	iface = passdb_interface_find(set->driver);
+	if (iface == NULL) {
+		/* maybe it's a plugin. try to load it. */
+		auth_module_load(t_strconcat("authdb_", set->driver, NULL));
+		iface = passdb_interface_find(set->driver);
+	}
 	if (iface == NULL)
 		i_fatal("Unknown passdb driver '%s'", set->driver);
 	if (iface->verify_plain == NULL) {
diff -r f53cf5670adf -r 695e9d58ed17 src/auth/userdb.c
--- a/src/auth/userdb.c	Sat Oct 01 17:24:09 2011 +0300
+++ b/src/auth/userdb.c	Sat Oct 01 17:34:39 2011 +0300
@@ -137,6 +137,11 @@
 	unsigned int idx;
 
 	iface = userdb_interface_find(set->driver);
+	if (iface == NULL) {
+		/* maybe it's a plugin. try to load it. */
+		auth_module_load(t_strconcat("authdb_", set->driver, NULL));
+		iface = userdb_interface_find(set->driver);
+	}
 	if (iface == NULL)
 		i_fatal("Unknown userdb driver '%s'", set->driver);
 	if (iface->lookup == NULL) {


More information about the dovecot-cvs mailing list