From 57cfc0aac9f8cc5d00fa1155367dfd055da27761 Mon Sep 17 00:00:00 2001 From: Daniel Hokka Zakrisson Date: Sun, 27 Feb 2011 01:49:00 +0100 Subject: make backend selection at runtime --- antispam-plugin.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'antispam-plugin.c') diff --git a/antispam-plugin.c b/antispam-plugin.c index 455668d..8a6fb65 100644 --- a/antispam-plugin.c +++ b/antispam-plugin.c @@ -27,6 +27,7 @@ #include #include +#include /* dovecot headers we need */ #include "lib.h" @@ -73,12 +74,15 @@ static char **trash_folders[] = { NULL, NULL, NULL }; static char **spam_folders[] = { default_spam_folders,NULL, NULL }; static char **unsure_folders[] = { NULL, NULL, NULL }; +void (*antispam_next_hook_mail_storage_created)(struct mail_storage *storage); bool antispam_can_append_to_spam = FALSE; static char **spam_keywords = NULL; bool need_keyword_hook; bool need_folder_hook; +struct backend *backend = NULL; + /* lower-case string, but keep modified UTF7 unchanged */ void lowercase_string(const char *in, char *out) { @@ -323,11 +327,32 @@ 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)); + exit(3); + } + backend = dlsym(lib, "antispam_backend"); + if (!backend) { + debug("invalid backend!\n"); + exit(5); + } + } + else { + debug("no backend selected!\n"); + exit(2); + } + /* set spam_folders to empty to only allow keywords */ need_folder_hook = spam_folder_count > 0; need_keyword_hook = !!spam_keywords; - backend_init(global_pool); + backend->init(global_pool); antispam_next_hook_mail_storage_created = hook_mail_storage_created; hook_mail_storage_created = antispam_mail_storage_created; @@ -336,7 +361,7 @@ void PLUGIN_FUNCTION(init)(void) void PLUGIN_FUNCTION(deinit)(void) { hook_mail_storage_created = antispam_next_hook_mail_storage_created; - backend_exit(); + backend->exit(); mempool_unref(&global_pool); } -- cgit v1.2.3 From ca91e1366a57ff45597168592781cdaf35af48a0 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Sun, 27 Feb 2011 11:09:49 +0100 Subject: add an API version to the backend struct Just to make sure nobody loads a backend plugin that isn't suitable for the version of antispam itself. --- antispam-plugin.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'antispam-plugin.c') diff --git a/antispam-plugin.c b/antispam-plugin.c index 8a6fb65..b94481b 100644 --- a/antispam-plugin.c +++ b/antispam-plugin.c @@ -330,20 +330,27 @@ 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)); exit(3); } + backend = dlsym(lib, "antispam_backend"); if (!backend) { debug("invalid backend!\n"); exit(5); } - } - else { + + if (backend->api_version != BACKEND_API_VERSION) { + debug("backend API version mismatch"); + exit(7); + } + } else { debug("no backend selected!\n"); exit(2); } -- cgit v1.2.3 From abaa5d6ecbb4546c51fa42937cc4048373647886 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Sun, 27 Feb 2011 11:43:53 +0100 Subject: make two functions static --- antispam-plugin.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'antispam-plugin.c') diff --git a/antispam-plugin.c b/antispam-plugin.c index b94481b..a620e4e 100644 --- a/antispam-plugin.c +++ b/antispam-plugin.c @@ -84,7 +84,7 @@ bool need_folder_hook; struct backend *backend = NULL; /* lower-case string, but keep modified UTF7 unchanged */ -void lowercase_string(const char *in, char *out) +static void lowercase_string(const char *in, char *out) { char ch; @@ -252,8 +252,8 @@ const char *get_setting(const char *name) return env; } -int parse_folder_setting(const char *setting, char ***strings, - const char *display_name) +static int parse_folder_setting(const char *setting, char ***strings, + const char *display_name) { const char *tmp; int cnt = 0; -- cgit v1.2.3 From 50e2cd6a909000111136cbec1e7a2affd457b31d Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Sun, 27 Feb 2011 13:01:41 +0100 Subject: bugfix: add / when generating plugin path name --- antispam-plugin.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'antispam-plugin.c') diff --git a/antispam-plugin.c b/antispam-plugin.c index a620e4e..23a61c0 100644 --- a/antispam-plugin.c +++ b/antispam-plugin.c @@ -332,7 +332,7 @@ void PLUGIN_FUNCTION(init)(void) void *lib; if (*tmp != '/') - tmp = t_strconcat(BACKENDDIR, tmp, ".so", NULL); + tmp = t_strconcat(BACKENDDIR, "/", tmp, ".so", NULL); lib = dlopen(tmp, RTLD_NOW | RTLD_LOCAL); if (!lib) { -- cgit v1.2.3 From 7a13a04dc0ef562e53097f614e887285965d4659 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Sun, 27 Feb 2011 15:40:03 +0100 Subject: build in all backend plugins --- antispam-plugin.c | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) (limited to 'antispam-plugin.c') 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); -- cgit v1.2.3 From b3d7e7bce03946102ff79aeef225106316b23edc Mon Sep 17 00:00:00 2001 From: Ron Date: Sun, 6 Mar 2011 10:51:42 +1030 Subject: Drop dlfcn.h again now the plugins are builtin --- antispam-plugin.c | 1 - 1 file changed, 1 deletion(-) (limited to 'antispam-plugin.c') diff --git a/antispam-plugin.c b/antispam-plugin.c index 2b4ff93..5260948 100644 --- a/antispam-plugin.c +++ b/antispam-plugin.c @@ -27,7 +27,6 @@ #include #include -#include /* dovecot headers we need */ #include "lib.h" -- cgit v1.2.3 From 27d016eeb4536fdebd89882133fc5daa614ecf17 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Sat, 12 Mar 2011 12:27:23 +0100 Subject: make debugging dynamic --- antispam-plugin.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'antispam-plugin.c') diff --git a/antispam-plugin.c b/antispam-plugin.c index 5260948..bbcc0e6 100644 --- a/antispam-plugin.c +++ b/antispam-plugin.c @@ -300,8 +300,33 @@ void PLUGIN_FUNCTION(init)(void) char * const *iter; int spam_folder_count; + debug_target = ADT_NONE; + verbose_debug = 0; + + tmp = get_setting("DEBUG_TARGET"); + if (tmp) { + if (strcmp(tmp, "syslog") == 0) + debug_target = ADT_SYSLOG; + else if (strcmp(tmp, "stderr") == 0) + debug_target = ADT_STDERR; + else + exit(4); + } + debug("plugin initialising (%s)\n", ANTISPAM_VERSION); + tmp = get_setting("VERBOSE_DEBUG"); + if (tmp) { + char *endp; + unsigned long val = strtoul(tmp, &endp, 10); + if (*endp || val >= 2) { + debug("Invalid verbose_debug setting"); + exit(5); + } + verbose_debug = val; + debug_verbose("verbose debug enabled"); + } + global_pool = pool_alloconly_create("antispam-pool", 1024); parse_folder_setting("TRASH", trash_folders, "trash"); -- cgit v1.2.3