# HG changeset patch # User Timo Sirainen # Date 1052936584 -10800 # Node ID 03dd87873a8142b253da013ae8d3bc1054bf98e9 # Parent bd489d13479eb3a5cf66a6d169d46aaca30c16ce Added support for dynamically loadable imap/pop3 modules. diff -r bd489d13479e -r 03dd87873a81 INSTALL --- a/INSTALL Wed May 14 20:23:11 2003 +0300 +++ b/INSTALL Wed May 14 21:23:04 2003 +0300 @@ -103,18 +103,27 @@ vpopmail). There's no standard way to build them as modules currently, but something like this should work: -gcc -shared -fPIC -DUSERDB_LDAP -DPASSDB_LDAP \ +gcc -shared -fPIC -DHAVE_CONFIG_H -DUSERDB_LDAP -DPASSDB_LDAP \ -I../.. -I../lib -I../lib-settings \ db-ldap.c userdb-ldap.c passdb-ldap.c -o ldap.so \ ../lib-settings/libsettings.a -lldap -gcc -shared -fPIC -DUSERDB_PGSQL -DPASSDB_PGSQL \ +gcc -shared -fPIC -DHAVE_CONFIG_H -DUSERDB_PGSQL -DPASSDB_PGSQL \ -I../.. -I../lib -I../lib-settings -I/usr/include/postgresql \ db-pgsql.c userdb-pgsql.c passdb-pgsql.c -o pgsql.so \ ../lib-settings/libsettings.a -L/usr/lib/postgresql -lpq -gcc -shared -fPIC -DUSERDB_VPOPMAIL -DPASSDB_VPOPMAIL -I../.. -I../lib \ -userdb-vpopmail.c passdb-vpopmail.c -o vpopmail.so -lvpopmail +gcc -shared -fPIC -DHAVE_CONFIG_H -DUSERDB_VPOPMAIL -DPASSDB_VPOPMAIL \ +-I../.. -I../lib userdb-vpopmail.c passdb-vpopmail.c -o vpopmail.so \ +-lvpopmail Including libsettings.a in ldap.so and pgsql.so is kind of annoying, but it's not needed elsewhere in dovecot-auth. + +Dynamic IMAP and POP3 Modules +----------------------------- + +If imap_use_modules or pop3_use_modules is set to yes, Dovecot will load all +*.so modules from directory pointed by imap_modules or pop3_modules. These +modules can do anything, they're only expected to contain _init +and _deinit functions which are called. diff -r bd489d13479e -r 03dd87873a81 configure.in --- a/configure.in Wed May 14 20:23:11 2003 +0300 +++ b/configure.in Wed May 14 21:23:04 2003 +0300 @@ -910,15 +910,14 @@ dnl * dynamic modules? AC_CHECK_LIB(dl, dlopen, [ - AUTH_LIBS="$AUTH_LIBS -ldl" - AC_DEFINE(AUTH_MODULES,, Define if you want to build with dynamic auth modules) - auth_modules=yes + AC_DEFINE(HAVE_MODULES,, Define if you have dynamic module support) userdb="$userdb (modules)" passdb="$passdb (modules)" + + MODULE_LIBS="-export-dynamic -ldl" + AC_SUBST(MODULE_LIBS) ]) -AM_CONDITIONAL(AUTH_MODULES, test "$auth_modules" = "yes") - AC_SUBST(AUTH_CFLAGS) AC_SUBST(AUTH_LIBS) @@ -1004,6 +1003,7 @@ src/lib-storage/index/maildir/Makefile src/lib-storage/index/mbox/Makefile src/lib-storage/subscription-file/Makefile +src/lib-storage/oracle/Makefile src/lib-storage/register/Makefile src/auth/Makefile src/imap/Makefile diff -r bd489d13479e -r 03dd87873a81 dovecot-example.conf --- a/dovecot-example.conf Wed May 14 20:23:11 2003 +0300 +++ b/dovecot-example.conf Wed May 14 21:23:04 2003 +0300 @@ -316,6 +316,10 @@ # files, so it shouldn't harm much even if this limit is set pretty high. #imap_process_size = 256 +# Support for dynamically loadable modules. +#imap_use_modules = no +#imap_modules = /usr/lib/dovecot/imap + ## ## POP3 process ## @@ -327,6 +331,10 @@ # files, so it shouldn't harm much even if this limit is set pretty high. #pop3_process_size = 256 +# Support for dynamically loadable modules. +#pop3_use_modules = no +#pop3_modules = /usr/lib/dovecot/pop3 + ## ## Authentication processes ## diff -r bd489d13479e -r 03dd87873a81 src/auth/Makefile.am --- a/src/auth/Makefile.am Wed May 14 20:23:11 2003 +0300 +++ b/src/auth/Makefile.am Wed May 14 21:23:04 2003 +0300 @@ -12,11 +12,8 @@ ../lib-settings/libsettings.a \ ../lib/liblib.a \ $(AUTH_LIBS) \ - $(RAND_LIBS) - -if AUTH_MODULES -dovecot_auth_LDFLAGS = -export-dynamic -endif + $(RAND_LIBS) \ + $(MODULE_LIBS) dovecot_auth_SOURCES = \ auth-module.c \ diff -r bd489d13479e -r 03dd87873a81 src/auth/auth-module.c --- a/src/auth/auth-module.c Wed May 14 20:23:11 2003 +0300 +++ b/src/auth/auth-module.c Wed May 14 21:23:04 2003 +0300 @@ -2,7 +2,7 @@ #include "lib.h" -#ifdef AUTH_MODULES +#ifdef HAVE_MODULES #include "auth-module.h" diff -r bd489d13479e -r 03dd87873a81 src/imap/Makefile.am --- a/src/imap/Makefile.am Wed May 14 20:23:11 2003 +0300 +++ b/src/imap/Makefile.am Wed May 14 21:23:04 2003 +0300 @@ -8,7 +8,7 @@ -I$(top_srcdir)/src/lib-imap \ -I$(top_srcdir)/src/lib-storage -imap_LDADD = \ +libs = \ ../lib-storage/register/libstorage-register.a \ $(STORAGE_LIBS) \ ../lib-storage/libstorage.a \ @@ -16,10 +16,14 @@ ../lib-imap/libimap.a \ ../lib-mail/libmail.a \ ../lib-charset/libcharset.a \ - ../lib/liblib.a \ - $(LIBICONV) + ../lib/liblib.a -imap_DEPENDENCIES = $(imap_LDADD) +imap_LDADD = \ + $(libs) \ + $(LIBICONV) \ + $(MODULE_LIBS) + +imap_DEPENDENCIES = $(libs) cmds = \ cmd-append.c \ diff -r bd489d13479e -r 03dd87873a81 src/imap/main.c --- a/src/imap/main.c Wed May 14 20:23:11 2003 +0300 +++ b/src/imap/main.c Wed May 14 21:23:04 2003 +0300 @@ -7,6 +7,7 @@ #include "restrict-access.h" #include "fd-close-on-exec.h" #include "process-title.h" +#include "module-dir.h" #include "mail-storage.h" #include "commands.h" @@ -20,6 +21,7 @@ struct ioloop *ioloop; unsigned int max_custom_flag_length, mailbox_check_interval; +static struct module *modules; static char log_prefix[128]; /* syslog() needs this to be permanent */ static void sig_quit(int signo __attr_unused__) @@ -88,8 +90,11 @@ mail_storage_init(); mail_storage_register_all(); + clients_init(); commands_init(); - clients_init(); + + modules = getenv("MODULE_DIR") == NULL ? NULL : + module_dir_load(getenv("MODULE_DIR")); mail = getenv("MAIL"); if (mail == NULL) { @@ -144,8 +149,10 @@ if (lib_signal_kill != 0 && lib_signal_kill != 2) i_warning("Killed with signal %d", lib_signal_kill); + module_dir_unload(modules); + + commands_deinit(); clients_deinit(); - commands_deinit(); mail_storage_deinit(); closelog(); diff -r bd489d13479e -r 03dd87873a81 src/lib/Makefile.am --- a/src/lib/Makefile.am Wed May 14 20:23:11 2003 +0300 +++ b/src/lib/Makefile.am Wed May 14 21:23:04 2003 +0300 @@ -34,6 +34,7 @@ mempool-system.c \ mmap-anon.c \ mmap-util.c \ + module-dir.c \ network.c \ ostream.c \ ostream-file.c \ @@ -85,6 +86,7 @@ md5.h \ mempool.h \ mmap-util.h \ + module-dir.h \ network.h \ ostream.h \ ostream-internal.h \ diff -r bd489d13479e -r 03dd87873a81 src/master/Makefile.am --- a/src/master/Makefile.am Wed May 14 20:23:11 2003 +0300 +++ b/src/master/Makefile.am Wed May 14 21:23:04 2003 +0300 @@ -8,6 +8,7 @@ -DSYSCONFDIR=\""$(sysconfdir)"\" \ -DPKG_RUNDIR=\""$(localstatedir)/run/$(PACKAGE)"\" \ -DPKG_LIBEXECDIR=\""$(pkglibexecdir)"\" \ + -DPKG_LIBDIR=\""$(libdir)/$(PACKAGE)"\" \ -DSSLDIR=\""$(ssldir)\"" dovecot_LDADD = \ diff -r bd489d13479e -r 03dd87873a81 src/master/login-process.c --- a/src/master/login-process.c Wed May 14 20:23:11 2003 +0300 +++ b/src/master/login-process.c Wed May 14 21:23:04 2003 +0300 @@ -30,6 +30,7 @@ struct login_process *newest_nonlisten_process; const char *executable; + const char *module_dir; unsigned int process_size; int process_type; int *listen_fd, *ssl_listen_fd; @@ -88,12 +89,16 @@ group->process_type = PROCESS_TYPE_IMAP; group->listen_fd = &mail_fd[FD_IMAP]; group->ssl_listen_fd = &mail_fd[FD_IMAPS]; + group->module_dir = set->imap_use_modules ? NULL : + set->imap_modules; } else if (strcmp(login_set->name, "pop3") == 0) { group->executable = set->pop3_executable; group->process_size = set->pop3_process_size; group->process_type = PROCESS_TYPE_POP3; group->listen_fd = &mail_fd[FD_POP3]; group->ssl_listen_fd = &mail_fd[FD_POP3S]; + group->module_dir = set->pop3_use_modules ? NULL : + set->pop3_modules; } else i_panic("Unknown login group name '%s'", login_set->name); @@ -120,9 +125,10 @@ master_reply.success = create_mail_process(request->fd, &request->ip, group->executable, + group->module_dir, group->process_size, - group->process_type, reply, - (const char *) data); + group->process_type, + reply, (const char *) data); } /* reply to login */ diff -r bd489d13479e -r 03dd87873a81 src/master/mail-process.c --- a/src/master/mail-process.c Wed May 14 20:23:11 2003 +0300 +++ b/src/master/mail-process.c Wed May 14 21:23:04 2003 +0300 @@ -100,9 +100,9 @@ } int create_mail_process(int socket, struct ip_addr *ip, - const char *executable, unsigned int process_size, - int process_type, struct auth_master_reply *reply, - const char *data) + const char *executable, const char *module_dir, + unsigned int process_size, int process_type, + struct auth_master_reply *reply, const char *data) { static const char *argv[] = { NULL, NULL, NULL }; const char *host, *mail, *chroot_dir, *home_dir, *full_home_dir; @@ -200,6 +200,8 @@ if (set->mbox_read_dotlock) env_put("MBOX_READ_DOTLOCK=1"); + env_put(t_strconcat("MODULE_DIR=", module_dir, NULL)); + /* user given environment - may be malicious. virtual_user comes from auth process, but don't trust that too much either. Some auth mechanism might allow leaving extra data there. */ diff -r bd489d13479e -r 03dd87873a81 src/master/mail-process.h --- a/src/master/mail-process.h Wed May 14 20:23:11 2003 +0300 +++ b/src/master/mail-process.h Wed May 14 21:23:04 2003 +0300 @@ -4,9 +4,9 @@ struct auth_master_reply; int create_mail_process(int socket, struct ip_addr *ip, - const char *executable, unsigned int process_size, - int process_type, struct auth_master_reply *reply, - const char *data); + const char *executable, const char *module_dir, + unsigned int process_size, int process_type, + struct auth_master_reply *reply, const char *data); void mail_process_destroyed(pid_t pid); diff -r bd489d13479e -r 03dd87873a81 src/master/master-settings.c --- a/src/master/master-settings.c Wed May 14 20:23:11 2003 +0300 +++ b/src/master/master-settings.c Wed May 14 21:23:04 2003 +0300 @@ -73,10 +73,14 @@ /* imap */ DEF(SET_STR, imap_executable), DEF(SET_INT, imap_process_size), + DEF(SET_BOOL, imap_use_modules), + DEF(SET_STR, imap_modules), /* pop3 */ DEF(SET_STR, pop3_executable), DEF(SET_INT, pop3_process_size), + DEF(SET_BOOL, pop3_use_modules), + DEF(SET_STR, pop3_modules), { 0, NULL, 0 } }; @@ -182,10 +186,14 @@ /* imap */ MEMBER(imap_executable) PKG_LIBEXECDIR"/imap", MEMBER(imap_process_size) 256, + MEMBER(imap_use_modules) FALSE, + MEMBER(imap_modules) PKG_LIBDIR"/imap", /* pop3 */ MEMBER(pop3_executable) PKG_LIBEXECDIR"/pop3", MEMBER(pop3_process_size) 256, + MEMBER(pop3_use_modules) FALSE, + MEMBER(pop3_modules) PKG_LIBDIR"/imap", MEMBER(login_gid) 0, MEMBER(auths) NULL, diff -r bd489d13479e -r 03dd87873a81 src/master/master-settings.h --- a/src/master/master-settings.h Wed May 14 20:23:11 2003 +0300 +++ b/src/master/master-settings.h Wed May 14 21:23:04 2003 +0300 @@ -57,10 +57,14 @@ /* imap */ const char *imap_executable; unsigned int imap_process_size; + int imap_use_modules; + const char *imap_modules; /* pop3 */ const char *pop3_executable; unsigned int pop3_process_size; + int pop3_use_modules; + const char *pop3_modules; /* .. */ gid_t login_gid; diff -r bd489d13479e -r 03dd87873a81 src/pop3/Makefile.am --- a/src/pop3/Makefile.am Wed May 14 20:23:11 2003 +0300 +++ b/src/pop3/Makefile.am Wed May 14 21:23:04 2003 +0300 @@ -8,7 +8,7 @@ -I$(top_srcdir)/src/lib-imap \ -I$(top_srcdir)/src/lib-storage -pop3_LDADD = \ +libs = \ ../lib-storage/register/libstorage-register.a \ $(STORAGE_LIBS) \ ../lib-storage/libstorage.a \ @@ -16,10 +16,14 @@ ../lib-imap/libimap.a \ ../lib-mail/libmail.a \ ../lib-charset/libcharset.a \ - ../lib/liblib.a \ - $(LIBICONV) + ../lib/liblib.a -pop3_DEPENDENCIES = $(pop3_LDADD) +pop3_LDADD = \ + $(libs) \ + $(LIBICONV) \ + $(MODULE_LIBS) + +pop3_DEPENDENCIES = $(libs) pop3_SOURCES = \ client.c \ diff -r bd489d13479e -r 03dd87873a81 src/pop3/main.c --- a/src/pop3/main.c Wed May 14 20:23:11 2003 +0300 +++ b/src/pop3/main.c Wed May 14 21:23:04 2003 +0300 @@ -6,6 +6,7 @@ #include "restrict-access.h" #include "fd-close-on-exec.h" #include "process-title.h" +#include "module-dir.h" #include "mail-storage.h" #include @@ -15,6 +16,8 @@ (getenv("LOGGED_IN") == NULL) struct ioloop *ioloop; + +static struct module *modules; static char log_prefix[128]; /* syslog() needs this to be permanent */ static void sig_quit(int signo __attr_unused__) @@ -69,6 +72,9 @@ mail_storage_register_all(); clients_init(); + modules = getenv("MODULE_DIR") == NULL ? NULL : + module_dir_load(getenv("MODULE_DIR")); + mail = getenv("MAIL"); if (mail == NULL) { /* support also maildir-specific environment */ @@ -103,6 +109,8 @@ if (lib_signal_kill != 0 && lib_signal_kill != 2) i_warning("Killed with signal %d", lib_signal_kill); + module_dir_unload(modules); + clients_deinit(); mail_storage_deinit();