Browse Source

[Fix] Fix lua exports from plugins during reload

tags/1.5.1
Vsevolod Stakhov 7 years ago
parent
commit
147ead02c4
3 changed files with 60 additions and 61 deletions
  1. 19
    18
      src/plugins/dkim_check.c
  2. 20
    21
      src/plugins/fuzzy_check.c
  3. 21
    22
      src/plugins/surbl.c

+ 19
- 18
src/plugins/dkim_check.c View 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,

+ 20
- 21
src/plugins/fuzzy_check.c View 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;
}


+ 21
- 22
src/plugins/surbl.c View 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;

Loading…
Cancel
Save