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 <module name>_init
+and <module name>_deinit functions which are called.
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)"
-])
-AM_CONDITIONAL(AUTH_MODULES, test "$auth_modules" = "yes")
+ MODULE_LIBS="-export-dynamic -ldl"
+ AC_SUBST(MODULE_LIBS)
+])
AC_SUBST(AUTH_CFLAGS)
AC_SUBST(AUTH_LIBS)
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
# 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
##
# 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
##
../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 \
#include "lib.h"
-#ifdef AUTH_MODULES
+#ifdef HAVE_MODULES
#include "auth-module.h"
-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 \
../lib-imap/libimap.a \
../lib-mail/libmail.a \
../lib-charset/libcharset.a \
- ../lib/liblib.a \
- $(LIBICONV)
+ ../lib/liblib.a
+
+imap_LDADD = \
+ $(libs) \
+ $(LIBICONV) \
+ $(MODULE_LIBS)
-imap_DEPENDENCIES = $(imap_LDADD)
+imap_DEPENDENCIES = $(libs)
cmds = \
cmd-append.c \
#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"
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__)
mail_storage_init();
mail_storage_register_all();
- commands_init();
clients_init();
+ commands_init();
+
+ modules = getenv("MODULE_DIR") == NULL ? NULL :
+ module_dir_load(getenv("MODULE_DIR"));
mail = getenv("MAIL");
if (mail == NULL) {
if (lib_signal_kill != 0 && lib_signal_kill != 2)
i_warning("Killed with signal %d", lib_signal_kill);
- clients_deinit();
+ module_dir_unload(modules);
+
commands_deinit();
+ clients_deinit();
mail_storage_deinit();
closelog();
mempool-system.c \
mmap-anon.c \
mmap-util.c \
+ module-dir.c \
network.c \
ostream.c \
ostream-file.c \
md5.h \
mempool.h \
mmap-util.h \
+ module-dir.h \
network.h \
ostream.h \
ostream-internal.h \
-DSYSCONFDIR=\""$(sysconfdir)"\" \
-DPKG_RUNDIR=\""$(localstatedir)/run/$(PACKAGE)"\" \
-DPKG_LIBEXECDIR=\""$(pkglibexecdir)"\" \
+ -DPKG_LIBDIR=\""$(libdir)/$(PACKAGE)"\" \
-DSSLDIR=\""$(ssldir)\""
dovecot_LDADD = \
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;
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);
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 */
}
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;
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. */
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);
/* 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 }
};
/* 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,
/* 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;
-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 \
../lib-imap/libimap.a \
../lib-mail/libmail.a \
../lib-charset/libcharset.a \
- ../lib/liblib.a \
- $(LIBICONV)
+ ../lib/liblib.a
+
+pop3_LDADD = \
+ $(libs) \
+ $(LIBICONV) \
+ $(MODULE_LIBS)
-pop3_DEPENDENCIES = $(pop3_LDADD)
+pop3_DEPENDENCIES = $(libs)
pop3_SOURCES = \
client.c \
#include "restrict-access.h"
#include "fd-close-on-exec.h"
#include "process-title.h"
+#include "module-dir.h"
#include "mail-storage.h"
#include <stdlib.h>
(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__)
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 */
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();