Mercurial > dovecot > original-hg > dovecot-1.2
changeset 6189:968430741daf HEAD
Changed plugin handling. We'll just load and call _init() functions for all
plugins in $moduledir/auth/.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 06 Aug 2007 23:43:28 +0300 |
parents | e609b4e3a35c |
children | 141c3abcac56 |
files | src/auth/Makefile.am src/auth/auth-module.c src/auth/auth-module.h src/auth/auth.h src/auth/main.c src/auth/passdb.c src/auth/password-scheme.c src/auth/userdb.c |
diffstat | 8 files changed, 9 insertions(+), 184 deletions(-) [+] |
line wrap: on
line diff
--- a/src/auth/Makefile.am Mon Aug 06 23:36:43 2007 +0300 +++ b/src/auth/Makefile.am Mon Aug 06 23:43:28 2007 +0300 @@ -40,7 +40,6 @@ auth-client-connection.c \ auth-master-connection.c \ auth-master-listener.c \ - auth-module.c \ auth-request.c \ auth-request-handler.c \ auth-stream.c \ @@ -97,7 +96,6 @@ auth-master-interface.h \ auth-master-connection.h \ auth-master-listener.h \ - auth-module.h \ auth-request.h \ auth-request-handler.h \ auth-stream.h \
--- a/src/auth/auth-module.c Mon Aug 06 23:36:43 2007 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,111 +0,0 @@ -/* Copyright (C) 2003 Timo Sirainen */ - -#include "lib.h" - -#ifdef HAVE_MODULES - -#include "auth-module.h" - -#include <sys/stat.h> -#include <dlfcn.h> - -#ifndef RTLD_GLOBAL -# define RTLD_GLOBAL 0 -#endif - -#ifndef RTLD_NOW -# define RTLD_NOW 0 -#endif - -struct auth_module { - struct auth_module *next; - - int refcount; - char *name; - void *handle; -}; - -static struct auth_module *auth_modules = NULL; - -static struct auth_module *auth_module_find(const char *name) -{ - struct auth_module *module; - - for (module = auth_modules; module != NULL; module = module->next) { - if (strcmp(module->name, name) == 0) - return module; - } - - return NULL; -} - -struct auth_module *auth_module_open(const char *name) -{ - struct auth_module *module; - const char *path; - struct stat st; - void *handle; - - module = auth_module_find(name); - if (module != NULL) { - module->refcount++; - return module; - } - - path = t_strconcat(AUTH_MODULE_DIR"/", name, ".so", NULL); - if (stat(path, &st) < 0) { - if (errno != ENOENT) - i_error("stat(%s) failed: %m", path); - return NULL; - } - - handle = dlopen(path, RTLD_GLOBAL | RTLD_NOW); - if (handle == NULL) - i_error("dlopen(%s) failed: %s", path, dlerror()); - - module = i_new(struct auth_module, 1); - module->refcount = 1; - module->name = i_strdup(name); - module->handle = handle; - - module->next = auth_modules; - auth_modules = module; - return module; -} - -void auth_module_close(struct auth_module **_module) -{ - struct auth_module *module = *_module; - struct auth_module **pos; - - *_module = NULL; - if (--module->refcount > 0) - return; - - for (pos = &auth_modules; *pos != NULL; pos = &(*pos)->next) { - if (*pos == module) { - *pos = module->next; - break; - } - } - - if (dlclose(module->handle) != 0) - i_error("dlclose() failed: %s", dlerror()); - i_free(module->name); - i_free(module); -} - -void *auth_module_sym(struct auth_module *module, const char *name) -{ - const char *error; - void *ret; - - ret = dlsym(module->handle, name); - - error = dlerror(); - if (error != NULL) - i_error("dlsym(%s) failed: %s", name, error); - return ret; -} - -#endif
--- a/src/auth/auth-module.h Mon Aug 06 23:36:43 2007 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,9 +0,0 @@ -#ifndef __AUTH_MODULE_H -#define __AUTH_MODULE_H - -struct auth_module *auth_module_open(const char *name); -void auth_module_close(struct auth_module **module); - -void *auth_module_sym(struct auth_module *module, const char *name); - -#endif
--- a/src/auth/auth.h Mon Aug 06 23:36:43 2007 +0300 +++ b/src/auth/auth.h Mon Aug 06 23:43:28 2007 +0300 @@ -11,9 +11,7 @@ unsigned int id; const char *args; struct passdb_module *passdb; -#ifdef HAVE_MODULES - struct auth_module *module; -#endif + /* if user is found from this passdb, deny authentication immediately */ unsigned int deny:1; /* after a successful lookup, continue to next passdb */ @@ -27,9 +25,6 @@ unsigned int num; const char *args; struct userdb_module *userdb; -#ifdef HAVE_MODULES - struct auth_module *module; -#endif }; struct auth {
--- a/src/auth/main.c Mon Aug 06 23:36:43 2007 +0300 +++ b/src/auth/main.c Mon Aug 06 23:43:28 2007 +0300 @@ -8,6 +8,7 @@ #include "restrict-access.h" #include "fd-close-on-exec.h" #include "sql-api.h" +#include "module-dir.h" #include "randgen.h" #include "password-scheme.h" #include "mech.h" @@ -32,6 +33,7 @@ bool standalone = FALSE, worker = FALSE; time_t process_start_time; +static struct module *modules = NULL; static struct auth *auth; static struct auth_worker_client *worker_client; @@ -194,8 +196,8 @@ only by root. Also load all modules here. */ passdbs_init(); userdbs_init(); + modules = module_dir_load(AUTH_MODULE_DIR, NULL, TRUE, PACKAGE_VERSION); auth = auth_preinit(); - password_schemes_init(); auth_master_listeners_init(); if (!worker) @@ -229,7 +231,10 @@ lib_signals_ignore(SIGHUP, TRUE); lib_signals_ignore(SIGUSR2, TRUE); + module_dir_init(modules); + mech_init(); + password_schemes_init(); auth_init(auth); auth_request_handler_init(); @@ -285,6 +290,8 @@ auth_worker_server_deinit(); auth_master_listeners_deinit(); + + module_dir_unload(&modules); auth_deinit(&auth); userdbs_deinit(); passdbs_deinit();
--- a/src/auth/passdb.c Mon Aug 06 23:36:43 2007 +0300 +++ b/src/auth/passdb.c Mon Aug 06 23:43:28 2007 +0300 @@ -2,7 +2,6 @@ #include "common.h" #include "array.h" -#include "auth-module.h" #include "password-scheme.h" #include "auth-worker-server.h" #include "passdb.h" @@ -133,15 +132,6 @@ auth_passdb->id = id; iface = passdb_interface_find(driver); -#ifdef HAVE_MODULES - if (iface == NULL) - auth_passdb->module = auth_module_open(driver); - if (auth_passdb->module != NULL) { - iface = auth_module_sym(auth_passdb->module, - t_strconcat("passdb_", driver, NULL)); - } -#endif - if (iface == NULL) { i_fatal("Unknown passdb driver '%s' " "(typo, or Dovecot was built without support for it? " @@ -178,10 +168,6 @@ { if (passdb->passdb->iface.deinit != NULL) passdb->passdb->iface.deinit(passdb->passdb); -#ifdef HAVE_MODULES - if (passdb->module != NULL) - auth_module_close(&passdb->module); -#endif } extern struct passdb_module_interface passdb_passwd;
--- a/src/auth/password-scheme.c Mon Aug 06 23:36:43 2007 +0300 +++ b/src/auth/password-scheme.c Mon Aug 06 23:43:28 2007 +0300 @@ -8,7 +8,6 @@ #include "md5.h" #include "hmac-md5.h" #include "ntlm.h" -#include "module-dir.h" #include "mycrypt.h" #include "randgen.h" #include "sha1.h" @@ -21,9 +20,6 @@ "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; ARRAY_TYPE(password_scheme_p) password_schemes; -#ifdef HAVE_MODULES -static struct module *scheme_modules; -#endif static const struct password_scheme * password_scheme_lookup_name(const char *name) @@ -619,37 +615,14 @@ void password_schemes_init(void) { - const struct password_scheme *s; -#ifdef HAVE_MODULES - struct module *mod; - const char *symbol; -#endif unsigned int i; i_array_init(&password_schemes, N_ELEMENTS(builtin_schemes) + 4); for (i = 0; i < N_ELEMENTS(builtin_schemes); i++) password_scheme_register(&builtin_schemes[i]); - -#ifdef HAVE_MODULES - scheme_modules = module_dir_load(AUTH_MODULE_DIR"/password", - NULL, FALSE, PACKAGE_VERSION); - module_dir_init(scheme_modules); - for (mod = scheme_modules; mod != NULL; mod = mod->next) { - t_push(); - symbol = t_strconcat(mod->name, "_scheme", NULL); - s = module_get_symbol(mod, symbol); - if (s != NULL) - password_scheme_register(s); - t_pop(); - } -#endif } void password_schemes_deinit(void) { -#ifdef HAVE_MODULES - module_dir_unload(&scheme_modules); -#endif - array_free(&password_schemes); }
--- a/src/auth/userdb.c Mon Aug 06 23:36:43 2007 +0300 +++ b/src/auth/userdb.c Mon Aug 06 23:43:28 2007 +0300 @@ -2,7 +2,6 @@ #include "common.h" #include "array.h" -#include "auth-module.h" #include "auth-worker-server.h" #include "userdb.h" @@ -117,15 +116,6 @@ *dest = auth_userdb; iface = userdb_interface_find(driver); -#ifdef HAVE_MODULES - if (auth_userdb->userdb == NULL) - auth_userdb->module = auth_module_open(driver); - if (auth_userdb->module != NULL) { - iface = auth_module_sym(auth_userdb->module, - t_strconcat("userdb_", driver, NULL)); - } -#endif - if (iface == NULL) { i_fatal("Unknown userdb driver '%s' " "(typo, or Dovecot was built without support for it? " @@ -158,10 +148,6 @@ { if (userdb->userdb->iface->deinit != NULL) userdb->userdb->iface->deinit(userdb->userdb); -#ifdef HAVE_MODULES - if (userdb->module != NULL) - auth_module_close(&userdb->module); -#endif } extern struct userdb_module_interface userdb_prefetch;