aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile18
-rw-r--r--antispam-plugin.c31
-rw-r--r--antispam-plugin.h15
-rw-r--r--crm114-exec.c3
-rw-r--r--dspam-exec.c3
-rw-r--r--pipe.c3
-rw-r--r--signature-log.c3
-rw-r--r--spool2dir.c3
8 files changed, 27 insertions, 52 deletions
diff --git a/Makefile b/Makefile
index 0516a6f..b7a5653 100644
--- a/Makefile
+++ b/Makefile
@@ -7,9 +7,6 @@ INSTALLDIR ?= $(moduledir)/imap
# Kill CFLAGS from dovecot-config
CFLAGS := $(CFLAGSORIG)
-backenddir := /usr/lib/dovecot-antispam
-LOCALCFLAGS += '-DBACKENDDIR="$(backenddir)"'
-
# includes/flags we need for building a dovecot plugin
INCS += -DHAVE_CONFIG_H
INCS += -I$(DOVECOT)/
@@ -41,14 +38,14 @@ ifeq ("$(DEBUG_VERBOSE)", "1")
LOCALCFLAGS += -DCONFIG_DEBUG_VERBOSE
endif
-BACKENDS = dspam-exec.so signature-log.so crm114-exec.so pipe.so spool2dir.so
+objs += dspam-exec.o signature-log.o crm114-exec.o pipe.o spool2dir.o
# main make rules
LOCALCFLAGS += -fPIC -shared -Wall -Wextra -DPLUGINNAME=$(PLUGINNAME)
CC ?= cc
HOSTCC ?= cc
-all: verify_config $(LIBRARY_NAME) $(BACKENDS)
+all: verify_config $(LIBRARY_NAME)
antispam-storage.o: antispam-storage.c antispam-storage-*.c $(CONFIG) antispam-plugin.h dovecot-version.h
$(CC) -c $(CFLAGS) $(LOCALCFLAGS) $(INCS) -o $@ $<
@@ -68,23 +65,12 @@ dovecot-version.h: dovecot-version
antispam-version.h: version.sh
./version.sh > antispam-version.h
-dspam-exec.so: dspam-exec.o signature.o
-signature-log.so: signature-log.o signature.o
-crm114-exec.so: crm114-exec.o signature.o
-pipe.so: pipe.o
-spool2dir.so: spool2dir.o
-
-$(BACKENDS):
- $(CC) $(CFLAGS) $(INCS) $(LOCALCFLAGS) $(LDFLAGS) -o $@ $^
-
clean:
rm -f *.so *.o *~ dovecot-version dovecot-version.h antispam-version.h
install: all
install -p -m 0755 $(LIBRARY_NAME) $(DESTDIR)$(INSTALLDIR)/
- mkdir -p $(DESTDIR)$(backenddir)
- install -p -m 0755 $(BACKENDS) $(DESTDIR)$(backenddir)/
verify_config:
@if [ ! -r $(CONFIG) ]; then \
diff --git a/antispam-plugin.c b/antispam-plugin.c
index 23a61c0..2b4ff93 100644
--- a/antispam-plugin.c
+++ b/antispam-plugin.c
@@ -329,27 +329,20 @@ void PLUGIN_FUNCTION(init)(void)
tmp = get_setting("BACKEND");
if (tmp) {
- void *lib;
-
- if (*tmp != '/')
- tmp = t_strconcat(BACKENDDIR, "/", tmp, ".so", NULL);
-
- lib = dlopen(tmp, RTLD_NOW | RTLD_LOCAL);
- if (!lib) {
- debug("backend failed to load: %s\n", strerror(errno));
+ if (strcmp(tmp, "crm114") == 0)
+ backend = &crm114_backend;
+ else if (strcmp(tmp, "dspam") == 0)
+ backend = &dspam_backend;
+ else if (strcmp(tmp, "pipe") == 0)
+ backend = &pipe_backend;
+ else if (strcmp(tmp, "signature") == 0)
+ backend = &signature_backend;
+ else if (strcmp(tmp, "spool2dir") == 0)
+ backend = &spool2dir_backend;
+ else {
+ debug("selected invalid backend!\n");
exit(3);
}
-
- backend = dlsym(lib, "antispam_backend");
- if (!backend) {
- debug("invalid backend!\n");
- exit(5);
- }
-
- if (backend->api_version != BACKEND_API_VERSION) {
- debug("backend API version mismatch");
- exit(7);
- }
} else {
debug("no backend selected!\n");
exit(2);
diff --git a/antispam-plugin.h b/antispam-plugin.h
index 2caf5a3..728ec1e 100644
--- a/antispam-plugin.h
+++ b/antispam-plugin.h
@@ -29,14 +29,7 @@ enum classification {
CLASS_SPAM,
};
-/* Update whenever the struct below needs to change */
-#define API_CODE 1
-#define BACKEND_API_VERSION ((DOVECOT_VERSION << 8) | API_CODE)
-
struct backend {
- /* Set to BACKEND_API_VERSION */
- unsigned int api_version;
-
void (*init)(pool_t pool);
void (*exit)(void);
/*
@@ -55,8 +48,16 @@ struct backend {
struct antispam_transaction_context *ast);
};
+/* the selected backend */
extern struct backend *backend;
+/* possible backends */
+extern struct backend crm114_backend;
+extern struct backend dspam_backend;
+extern struct backend pipe_backend;
+extern struct backend signature_backend;
+extern struct backend spool2dir_backend;
+
#ifdef CONFIG_DEBUG
void debug(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
void debugv(char **args);
diff --git a/crm114-exec.c b/crm114-exec.c
index 3947dbc..ea0babc 100644
--- a/crm114-exec.c
+++ b/crm114-exec.c
@@ -202,8 +202,7 @@ static void backend_exit(void)
{
}
-struct backend antispam_backend = {
- .api_version = BACKEND_API_VERSION,
+struct backend crm114_backend = {
.init = backend_init,
.exit = backend_exit,
.handle_mail = backend_handle_mail,
diff --git a/dspam-exec.c b/dspam-exec.c
index 4be4af4..a9e0c1d 100644
--- a/dspam-exec.c
+++ b/dspam-exec.c
@@ -267,8 +267,7 @@ static void backend_exit(void)
{
}
-struct backend antispam_backend = {
- .api_version = BACKEND_API_VERSION,
+struct backend dspam_backend = {
.init = backend_init,
.exit = backend_exit,
.handle_mail = backend_handle_mail,
diff --git a/pipe.c b/pipe.c
index 309f8d9..c0853d6 100644
--- a/pipe.c
+++ b/pipe.c
@@ -363,8 +363,7 @@ static void backend_exit(void)
{
}
-struct backend antispam_backend = {
- .api_version = BACKEND_API_VERSION,
+struct backend pipe_backend = {
.init = backend_init,
.exit = backend_exit,
.handle_mail = backend_handle_mail,
diff --git a/signature-log.c b/signature-log.c
index d0ab332..7a9b422 100644
--- a/signature-log.c
+++ b/signature-log.c
@@ -160,8 +160,7 @@ static void backend_exit(void)
{
}
-struct backend antispam_backend = {
- .api_version = BACKEND_API_VERSION,
+struct backend signature_backend = {
.init = backend_init,
.exit = backend_exit,
.handle_mail = backend_handle_mail,
diff --git a/spool2dir.c b/spool2dir.c
index 26fcd3e..2d9691b 100644
--- a/spool2dir.c
+++ b/spool2dir.c
@@ -258,8 +258,7 @@ static void backend_exit(void)
{
}
-struct backend antispam_backend = {
- .api_version = BACKEND_API_VERSION,
+struct backend spool2dir_backend = {
.init = backend_init,
.exit = backend_exit,
.handle_mail = backend_handle_mail,