Mercurial > dovecot > core-2.2
changeset 13571:695e9d58ed17
auth: Lazily load authdb_* and mech_* plugins only when they're needed.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sat, 01 Oct 2011 17:34:39 +0300 |
parents | f53cf5670adf |
children | 967a53c3ef5e |
files | src/auth/auth-common.h src/auth/main.c src/auth/mech.c src/auth/passdb.c src/auth/userdb.c |
diffstat | 5 files changed, 46 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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;
--- 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); }
--- 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) {
--- 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) {