]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Add conditional enabling of modules.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 6 Aug 2015 17:25:15 +0000 (18:25 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 6 Aug 2015 17:25:15 +0000 (18:25 +0100)
src/libserver/cfg_rcl.c
src/libserver/cfg_utils.c
src/lua/lua_common.c
src/plugins/chartable.c
src/plugins/dkim_check.c
src/plugins/fuzzy_check.c
src/plugins/regexp.c
src/plugins/spf.c
src/plugins/surbl.c

index ef2644dd9875e1d01b5e9c156b42e3f98f6558de..bc60bfc66d81efbf3ccb6123d63967aa54ea5e9c 100644 (file)
@@ -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);
                        }
index 96beb0621a6d163da5cfa8d1a11fb35bfca81581..1fe7d1483871717bc09e6b2295410a6e8ae5e14b 100644 (file)
@@ -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;
                }
index a45f3871d25eba2cbd3689e6a3a47c2f5341b8d2..2f1f645ff60d8b86160ed2e7a987d1d59a63d214 100644 (file)
@@ -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));
index cafef6d40a2fc2ce4b4a30bc18cd01e51b0da95e..c0c68f71a48b560eca8171b955867d4ac9b3747f 100644 (file)
@@ -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);
index 477a1bc2909d3c6dd57fc67e4beffbec8b55bc82..e30b9858c14eccdef723633ab91aa6b01403a019 100644 (file)
@@ -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 =
index 5d1ebe316d7088ac32757f0005c135ca95fb4d24..783b9393f51ccc08fa72cfb4773c477136d7591d 100644 (file)
@@ -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);
index da2caab4ade8354d6631b2c8c45d39b6c5ea4636..ed677ce98350c9ca8274fdd8f65ccd0d517574b0 100644 (file)
@@ -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");
index d0998b05d488f4fb7aad9f0272d700dcb137446c..caff118e406b3c85af9d2487bcc31a0d7e7bd3ee 100644 (file)
@@ -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 =
index 23beb1fbc0b8e7701f8db2f2b3965cd900309cca..997115d6d9ad34dd294c09c3f3985ecd88c9d4af 100644 (file)
@@ -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 ();