aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-08-06 18:25:15 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-08-06 18:25:15 +0100
commitd9c16b50a4f7607cb5f4887fcc3c988f7c28d181 (patch)
tree4284c8de0a956a30ed70f92c65e24b9da0df5115
parent54becee5b29dfc2cbda278a7f016fa62eceb996a (diff)
downloadrspamd-d9c16b50a4f7607cb5f4887fcc3c988f7c28d181.tar.gz
rspamd-d9c16b50a4f7607cb5f4887fcc3c988f7c28d181.zip
Add conditional enabling of modules.
-rw-r--r--src/libserver/cfg_rcl.c11
-rw-r--r--src/libserver/cfg_utils.c13
-rw-r--r--src/lua/lua_common.c5
-rw-r--r--src/plugins/chartable.c4
-rw-r--r--src/plugins/dkim_check.c4
-rw-r--r--src/plugins/fuzzy_check.c4
-rw-r--r--src/plugins/regexp.c4
-rw-r--r--src/plugins/spf.c4
-rw-r--r--src/plugins/surbl.c4
9 files changed, 42 insertions, 11 deletions
diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c
index ef2644dd9..bc60bfc66 100644
--- a/src/libserver/cfg_rcl.c
+++ b/src/libserver/cfg_rcl.c
@@ -795,7 +795,7 @@ rspamd_rcl_add_module_path (struct rspamd_config *cfg,
struct stat st;
struct script_module *cur_mod;
glob_t globbuf;
- gchar *pattern;
+ gchar *pattern, *ext_pos;
size_t len;
guint i;
@@ -823,6 +823,15 @@ rspamd_rcl_add_module_path (struct rspamd_config *cfg,
sizeof (struct script_module));
cur_mod->path = rspamd_mempool_strdup (cfg->cfg_pool,
globbuf.gl_pathv[i]);
+ cur_mod->name = g_path_get_basename (cur_mod->path);
+ rspamd_mempool_add_destructor (cfg->cfg_pool, g_free,
+ cur_mod->name);
+ ext_pos = strstr (cur_mod->name, ".lua");
+
+ if (ext_pos != NULL) {
+ *ext_pos = '\0';
+ }
+
cfg->script_modules = g_list_prepend (cfg->script_modules,
cur_mod);
}
diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c
index 96beb0621..1fe7d1483 100644
--- a/src/libserver/cfg_utils.c
+++ b/src/libserver/cfg_utils.c
@@ -1059,15 +1059,8 @@ rspamd_config_is_module_enabled (struct rspamd_config *cfg,
conf = ucl_object_find_key (cfg->rcl_obj, module_name);
if (conf == NULL) {
- if (is_c) {
- msg_info ("internal module %s is enabled but has not configured",
- module_name);
- }
- else {
- msg_info ("lua module %s is disabled as it has not configured",
- module_name);
- return FALSE;
- }
+ msg_info ("%s module %s is enabled but has not been configured",
+ is_c ? "internal" : "lua", module_name);
}
else {
enabled = ucl_object_find_key (conf, "enabled");
@@ -1087,7 +1080,7 @@ rspamd_config_is_module_enabled (struct rspamd_config *cfg,
if (gr) {
if (gr->disabled) {
msg_info ("%s module %s is disabled in the configuration as "
- "its group is disabled",
+ "its group has been disabled",
is_c ? "internal" : "lua", module_name);
return FALSE;
}
diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c
index a45f3871d..2f1f645ff 100644
--- a/src/lua/lua_common.c
+++ b/src/lua/lua_common.c
@@ -294,6 +294,11 @@ rspamd_init_lua_filters (struct rspamd_config *cfg)
while (cur) {
module = cur->data;
if (module->path) {
+ if (!rspamd_config_is_module_enabled (cfg, module->name)) {
+ cur = g_list_next (cur);
+ continue;
+ }
+
if (luaL_loadfile (L, module->path) != 0) {
msg_info ("load of %s failed: %s", module->path,
lua_tostring (L, -1));
diff --git a/src/plugins/chartable.c b/src/plugins/chartable.c
index cafef6d40..c0c68f71a 100644
--- a/src/plugins/chartable.c
+++ b/src/plugins/chartable.c
@@ -82,6 +82,10 @@ chartable_module_config (struct rspamd_config *cfg)
const ucl_object_t *value;
gint res = TRUE;
+ if (!rspamd_config_is_module_enabled (cfg, "chartable")) {
+ return TRUE;
+ }
+
if ((value =
rspamd_config_get_module_opt (cfg, "chartable", "symbol")) != NULL) {
chartable_module_ctx->symbol = ucl_obj_tostring (value);
diff --git a/src/plugins/dkim_check.c b/src/plugins/dkim_check.c
index 477a1bc29..e30b9858c 100644
--- a/src/plugins/dkim_check.c
+++ b/src/plugins/dkim_check.c
@@ -116,6 +116,10 @@ dkim_module_config (struct rspamd_config *cfg)
guint cache_size, cache_expire;
gboolean got_trusted = FALSE;
+ if (!rspamd_config_is_module_enabled (cfg, "dkim")) {
+ return TRUE;
+ }
+
dkim_module_ctx->whitelist_ip = radix_create_compressed ();
if ((value =
diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c
index 5d1ebe316..783b9393f 100644
--- a/src/plugins/fuzzy_check.c
+++ b/src/plugins/fuzzy_check.c
@@ -417,6 +417,10 @@ fuzzy_check_module_config (struct rspamd_config *cfg)
const ucl_object_t *value, *cur;
gint res = TRUE, cb_id;
+ if (!rspamd_config_is_module_enabled (cfg, "fuzzy_check")) {
+ return TRUE;
+ }
+
if ((value =
rspamd_config_get_module_opt (cfg, "fuzzy_check", "symbol")) != NULL) {
fuzzy_module_ctx->default_symbol = ucl_obj_tostring (value);
diff --git a/src/plugins/regexp.c b/src/plugins/regexp.c
index da2caab4a..ed677ce98 100644
--- a/src/plugins/regexp.c
+++ b/src/plugins/regexp.c
@@ -114,6 +114,10 @@ regexp_module_config (struct rspamd_config *cfg)
ucl_object_iter_t it = NULL;
gint res = TRUE;
+ if (!rspamd_config_is_module_enabled (cfg, "regexp")) {
+ return TRUE;
+ }
+
sec = ucl_object_find_key (cfg->rcl_obj, "regexp");
if (sec == NULL) {
msg_err ("regexp module enabled, but no rules are defined");
diff --git a/src/plugins/spf.c b/src/plugins/spf.c
index d0998b05d..caff118e4 100644
--- a/src/plugins/spf.c
+++ b/src/plugins/spf.c
@@ -108,6 +108,10 @@ spf_module_config (struct rspamd_config *cfg)
gint res = TRUE, cb_id;
guint cache_size, cache_expire;
+ if (!rspamd_config_is_module_enabled (cfg, "spf")) {
+ return TRUE;
+ }
+
spf_module_ctx->whitelist_ip = radix_create_compressed ();
if ((value =
diff --git a/src/plugins/surbl.c b/src/plugins/surbl.c
index 23beb1fbc..997115d6d 100644
--- a/src/plugins/surbl.c
+++ b/src/plugins/surbl.c
@@ -346,6 +346,10 @@ surbl_module_config (struct rspamd_config *cfg)
gint cb_id;
gboolean has_subsymbols;
+ if (!rspamd_config_is_module_enabled (cfg, "surbl")) {
+ return TRUE;
+ }
+
if ((value =
rspamd_config_get_module_opt (cfg, "surbl", "redirector")) != NULL) {
surbl_module_ctx->redirectors = rspamd_upstreams_create ();