]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Fix lua exports from plugins during reload
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 2 Mar 2017 14:50:50 +0000 (14:50 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 2 Mar 2017 14:50:50 +0000 (14:50 +0000)
src/plugins/dkim_check.c
src/plugins/fuzzy_check.c
src/plugins/surbl.c

index d36f13e3978d847b611d68314d7bfcbb77252076..11d6f2c9ac2f1c8095cc1aed7110474a29c751e1 100644 (file)
@@ -275,7 +275,18 @@ dkim_module_init (struct rspamd_config *cfg, struct module_ctx **ctx)
                        NULL,
                        0);
 
-        /* Register global methods */
+       return 0;
+}
+
+gint
+dkim_module_config (struct rspamd_config *cfg)
+{
+       const ucl_object_t *value;
+       gint res = TRUE, cb_id = -1, check_id = -1;
+       guint cache_size;
+       gboolean got_trusted = FALSE;
+
+       /* Register global methods */
        lua_getglobal (cfg->lua_state, "rspamd_plugins");
 
        if (lua_type (cfg->lua_state, -1) == LUA_TTABLE) {
@@ -285,22 +296,16 @@ dkim_module_init (struct rspamd_config *cfg, struct module_ctx **ctx)
                lua_pushstring (cfg->lua_state, "sign");
                lua_pushcfunction (cfg->lua_state, lua_dkim_sign_handler);
                lua_settable (cfg->lua_state, -3);
-                /* Finish dkim key */
+               /* Finish dkim key */
                lua_settable (cfg->lua_state, -3);
        }
 
        lua_pop (cfg->lua_state, 1); /* Remove global function */
 
-       return 0;
-}
-
-gint
-dkim_module_config (struct rspamd_config *cfg)
-{
-       const ucl_object_t *value;
-       gint res = TRUE, cb_id = -1, check_id = -1;
-       guint cache_size;
-       gboolean got_trusted = FALSE;
+       dkim_module_ctx->dkim_sign_hash = rspamd_lru_hash_new (
+                       128,
+                       g_free, /* Keys are just C-strings */
+                       (GDestroyNotify)rspamd_dkim_sign_key_unref);
 
        if (!rspamd_config_is_module_enabled (cfg, "dkim")) {
                return TRUE;
@@ -308,8 +313,8 @@ dkim_module_config (struct rspamd_config *cfg)
 
        dkim_module_ctx->whitelist_ip = radix_create_compressed ();
 
-        if ((value =
-               rspamd_config_get_module_opt (cfg, "options", "check_local")) != NULL) {
+       if ((value =
+                       rspamd_config_get_module_opt (cfg, "options", "check_local")) != NULL) {
                dkim_module_ctx->check_local = ucl_obj_toboolean (value);
        }
        else {
@@ -506,10 +511,6 @@ dkim_module_config (struct rspamd_config *cfg)
                                                        dkim_module_ctx->dkim_pool,
                                                        dkim_module_ctx->sign_condition_ref);
 
-                                       dkim_module_ctx->dkim_sign_hash = rspamd_lru_hash_new (
-                                                                       128,
-                                                                       g_free, /* Keys are just C-strings */
-                                                                       (GDestroyNotify)rspamd_dkim_sign_key_unref);
                                        check_id = rspamd_symbols_cache_add_symbol (cfg->cache,
                                                        "DKIM_SIGN",
                                                        0,
index 38456f4ca074099bfbf29cd9e17092390472c047..9d4e611216671fd563d6f35832b28f137240e409 100644 (file)
@@ -649,8 +649,6 @@ fuzzy_parse_rule (struct rspamd_config *cfg, const ucl_object_t *obj,
 gint
 fuzzy_check_module_init (struct rspamd_config *cfg, struct module_ctx **ctx)
 {
-       lua_State *L = cfg->lua_state;
-
        if (fuzzy_module_ctx == NULL) {
                fuzzy_module_ctx = g_malloc0 (sizeof (struct fuzzy_ctx));
 
@@ -885,25 +883,6 @@ fuzzy_check_module_init (struct rspamd_config *cfg, struct module_ctx **ctx)
                        NULL,
                        0);
 
-       /* Register global methods */
-       lua_getglobal (L, "rspamd_plugins");
-
-       if (lua_type (L, -1) == LUA_TTABLE) {
-               lua_pushstring (L, "fuzzy_check");
-               lua_createtable (L, 0, 2);
-               /* Set methods */
-               lua_pushstring (L, "unlearn");
-               lua_pushcfunction (L, fuzzy_lua_unlearn_handler);
-               lua_settable (L, -3);
-               lua_pushstring (L, "learn");
-               lua_pushcfunction (L, fuzzy_lua_learn_handler);
-               lua_settable (L, -3);
-               /* Finish fuzzy_check key */
-               lua_settable (L, -3);
-       }
-
-       lua_pop (L, 1); /* Remove global function */
-
        return 0;
 }
 
@@ -913,6 +892,7 @@ fuzzy_check_module_config (struct rspamd_config *cfg)
        const ucl_object_t *value, *cur, *elt;
        ucl_object_iter_t it;
        gint res = TRUE, cb_id, nrules = 0;
+       lua_State *L = cfg->lua_state;
 
        if (!rspamd_config_is_module_enabled (cfg, "fuzzy_check")) {
                return TRUE;
@@ -1049,6 +1029,25 @@ fuzzy_check_module_config (struct rspamd_config *cfg)
        msg_info_config ("init internal fuzzy_check module, %d rules loaded",
                        nrules);
 
+       /* Register global methods */
+       lua_getglobal (L, "rspamd_plugins");
+
+       if (lua_type (L, -1) == LUA_TTABLE) {
+               lua_pushstring (L, "fuzzy_check");
+               lua_createtable (L, 0, 2);
+               /* Set methods */
+               lua_pushstring (L, "unlearn");
+               lua_pushcfunction (L, fuzzy_lua_unlearn_handler);
+               lua_settable (L, -3);
+               lua_pushstring (L, "learn");
+               lua_pushcfunction (L, fuzzy_lua_learn_handler);
+               lua_settable (L, -3);
+               /* Finish fuzzy_check key */
+               lua_settable (L, -3);
+       }
+
+       lua_pop (L, 1); /* Remove global function */
+
        return res;
 }
 
index 91ff3ac9ce8d86cff8208e26759fdead758f9437..f079be4456113ea6ca4e02841dd31a127bf8b6ad 100644 (file)
@@ -277,8 +277,6 @@ fin_redirectors_list (struct map_cb_data *data)
 gint
 surbl_module_init (struct rspamd_config *cfg, struct module_ctx **ctx)
 {
-       lua_State *L;
-
        surbl_module_ctx = g_malloc0 (sizeof (struct surbl_ctx));
 
        surbl_module_ctx->use_redirector = 0;
@@ -453,26 +451,6 @@ surbl_module_init (struct rspamd_config *cfg, struct module_ctx **ctx)
                        NULL,
                        0);
 
-       /* Register global methods */
-       L = cfg->lua_state;
-       lua_getglobal (L, "rspamd_plugins");
-
-       if (lua_type (L, -1) == LUA_TTABLE) {
-               lua_pushstring (L, "surbl");
-               lua_createtable (L, 0, 2);
-               /* Set methods */
-               lua_pushstring (L, "register_redirect");
-               lua_pushcfunction (L, surbl_register_redirect_handler);
-               lua_settable (L, -3);
-               lua_pushstring (L, "continue_process");
-               lua_pushcfunction (L, surbl_continue_process_handler);
-               lua_settable (L, -3);
-               /* Finish fuzzy_check key */
-               lua_settable (L, -3);
-       }
-
-               lua_pop (L, 1); /* Remove global function */
-
        return 0;
 }
 
@@ -726,6 +704,27 @@ surbl_module_config (struct rspamd_config *cfg)
        const gchar *redir_val;
        gint nrules = 0;
        ucl_object_t *monitored_opts;
+       lua_State *L;
+
+       /* Register global methods */
+       L = cfg->lua_state;
+       lua_getglobal (L, "rspamd_plugins");
+
+       if (lua_type (L, -1) == LUA_TTABLE) {
+               lua_pushstring (L, "surbl");
+               lua_createtable (L, 0, 2);
+               /* Set methods */
+               lua_pushstring (L, "register_redirect");
+               lua_pushcfunction (L, surbl_register_redirect_handler);
+               lua_settable (L, -3);
+               lua_pushstring (L, "continue_process");
+               lua_pushcfunction (L, surbl_continue_process_handler);
+               lua_settable (L, -3);
+               /* Finish fuzzy_check key */
+               lua_settable (L, -3);
+       }
+
+       lua_pop (L, 1); /* Remove global function */
 
        if (!rspamd_config_is_module_enabled (cfg, "surbl")) {
                return TRUE;