]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Fix plugins intialisation in configwizard
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 31 May 2018 14:52:18 +0000 (15:52 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 31 May 2018 14:52:18 +0000 (15:52 +0100)
lualib/rspamadm/configwizard.lua
src/lua/lua_config.c
src/rspamadm/configdump.c
src/rspamadm/rspamadm.c

index a71c6f2365e35c0f546618cb05d687a540299988..10134c57562ffcfb485c31c9d4ef27989450afe1 100644 (file)
@@ -625,6 +625,11 @@ return {
       os.exit(1)
     end
 
+    if not rspamd_config:init_modules() then
+      rspamd_logger.errx('cannot init modules when parsing %s', opts['config'])
+      os.exit(1)
+    end
+
     if #args > 0 then
       interactive_start = false
 
index f54411e8871cd62a93a7e7d896f10c0bae82c438..37d122402c886a2b1f04d953fbe7d9168cf2adb1 100644 (file)
@@ -696,13 +696,20 @@ LUA_FUNCTION_DEF (config, experimental_enabled);
 LUA_FUNCTION_DEF (config, load_ucl);
 
 /***
- * @method rspamd_config:parce_rcl([skip_sections])
+ * @method rspamd_config:parse_rcl([skip_sections])
  * Parses RCL using loaded ucl file
  * @param {table|string} sections to skip
  * @return true or false + error message
  */
 LUA_FUNCTION_DEF (config, parse_rcl);
 
+/***
+ * @method rspamd_config:init_modules()
+ * Initialize lua and internal modules
+ * @return true or false
+ */
+LUA_FUNCTION_DEF (config, init_modules);
+
 static const struct luaL_reg configlib_m[] = {
        LUA_INTERFACE_DEF (config, get_module_opt),
        LUA_INTERFACE_DEF (config, get_mempool),
@@ -763,6 +770,7 @@ static const struct luaL_reg configlib_m[] = {
        LUA_INTERFACE_DEF (config, experimental_enabled),
        LUA_INTERFACE_DEF (config, load_ucl),
        LUA_INTERFACE_DEF (config, parse_rcl),
+       LUA_INTERFACE_DEF (config, init_modules),
        {"__tostring", rspamd_lua_class_tostring},
        {"__newindex", lua_config_newindex},
        {NULL, NULL}
@@ -3387,6 +3395,22 @@ lua_config_parse_rcl (lua_State *L)
        return 1;
 }
 
+static gint
+lua_config_init_modules (lua_State *L)
+{
+       struct rspamd_config *cfg = lua_check_config (L, 1);
+
+       if (cfg != NULL) {
+               rspamd_lua_post_load_config (cfg);
+               lua_pushboolean (L, rspamd_init_filters (cfg, FALSE));
+       }
+       else {
+               return luaL_error (L, "invalid arguments");
+       }
+
+       return 1;
+}
+
 static gint
 lua_monitored_alive (lua_State *L)
 {
index bd776e586f88534ed0453e76603a92499b39c08e..cd9f6d378db4a8f73e349379aa70e8f448889680 100644 (file)
@@ -278,6 +278,7 @@ rspamadm_configdump (gint argc, gchar **argv, const struct rspamadm_command *cmd
                (void) g_quark_from_static_string ((*pworker)->name);
                pworker++;
        }
+
        cfg->cache = rspamd_symbols_cache_new (cfg);
        cfg->compiled_modules = modules;
        cfg->compiled_workers = workers;
index a804d0059d08ef143b11f06a69248f77c214d196..eff27c1e9479ad1a8c70e2c55bb7fc4fb62f4147 100644 (file)
@@ -33,6 +33,10 @@ GHashTable *ucl_vars = NULL;
 struct rspamd_main *rspamd_main = NULL;
 lua_State *L = NULL;
 
+/* Defined in modules.c */
+extern module_t *modules[];
+extern worker_t *workers[];
+
 static void rspamadm_help (gint argc, gchar **argv, const struct rspamadm_command *);
 static const char* rspamadm_help_help (gboolean full_help, const struct rspamadm_command *);
 
@@ -291,6 +295,7 @@ main (gint argc, gchar **argv, gchar **env)
        const struct rspamadm_command *cmd;
        GPtrArray *all_commands = g_ptr_array_new (); /* Discovered during check */
        gint i, nargc, targc;
+       worker_t **pworker;
 
        ucl_vars = g_hash_table_new_full (rspamd_strcase_hash,
                rspamd_strcase_equal, g_free, g_free);
@@ -325,6 +330,16 @@ main (gint argc, gchar **argv, gchar **env)
        rspamd_config_post_load (cfg,
                        RSPAMD_CONFIG_INIT_LIBS|RSPAMD_CONFIG_INIT_URL|RSPAMD_CONFIG_INIT_NO_TLD);
 
+       pworker = &workers[0];
+       while (*pworker) {
+               /* Init string quarks */
+               (void) g_quark_from_static_string ((*pworker)->name);
+               pworker++;
+       }
+
+       cfg->compiled_modules = modules;
+       cfg->compiled_workers = workers;
+
        gperf_profiler_init (cfg, "rspamadm");
        setproctitle ("rspamdadm");