summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-04-07 13:43:09 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-04-07 13:43:09 +0100
commit93e08dc6e00459b2fda6119bfc630b0fb996758c (patch)
treea87580f5a57c28a4fc2540932223167c0d8e77d7
parentd5bd63254fb2df011b1499c27bc3741890c8ed9f (diff)
downloadrspamd-93e08dc6e00459b2fda6119bfc630b0fb996758c.tar.gz
rspamd-93e08dc6e00459b2fda6119bfc630b0fb996758c.zip
[Feature] Add magic for callback data in rspamd rules
-rw-r--r--src/libserver/symbols_cache.h8
-rw-r--r--src/lua/lua_config.c14
-rw-r--r--src/plugins/regexp.c10
-rw-r--r--src/plugins/surbl.c4
-rw-r--r--src/plugins/surbl.h1
5 files changed, 35 insertions, 2 deletions
diff --git a/src/libserver/symbols_cache.h b/src/libserver/symbols_cache.h
index 0874ac475..0d94a77a3 100644
--- a/src/libserver/symbols_cache.h
+++ b/src/libserver/symbols_cache.h
@@ -39,6 +39,14 @@ enum rspamd_symbol_type {
};
/**
+ * Abstract structure for saving callback data for symbols
+ */
+struct rspamd_abstract_callback_data {
+ guint64 magic;
+ char data[];
+};
+
+/**
* Creates new cache structure
* @return
*/
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c
index aa4327b27..5c4acf02c 100644
--- a/src/lua/lua_config.c
+++ b/src/lua/lua_config.c
@@ -446,6 +446,8 @@ static const struct luaL_reg configlib_m[] = {
{NULL, NULL}
};
+static const guint64 rspamd_lua_callback_magic = 0x32c118af1e3263c7ULL;
+
struct rspamd_config *
lua_check_config (lua_State * L, gint pos)
{
@@ -588,13 +590,15 @@ lua_config_get_classifier (lua_State * L)
}
struct lua_callback_data {
+ guint64 magic;
+ lua_State *L;
+ gchar *symbol;
+
union {
gchar *name;
gint ref;
} callback;
gboolean cb_is_ref;
- lua_State *L;
- gchar *symbol;
};
/*
@@ -666,6 +670,8 @@ lua_config_register_post_filter (lua_State *L)
cd =
rspamd_mempool_alloc (cfg->cfg_pool,
sizeof (struct lua_callback_data));
+ cd->magic = rspamd_lua_callback_magic;
+
if (lua_type (L, 2) == LUA_TSTRING) {
cd->callback.name = rspamd_mempool_strdup (cfg->cfg_pool,
luaL_checkstring (L, 2));
@@ -677,6 +683,7 @@ lua_config_register_post_filter (lua_State *L)
cd->callback.ref = luaL_ref (L, LUA_REGISTRYINDEX);
cd->cb_is_ref = TRUE;
}
+
cd->L = L;
cfg->post_filters = g_list_prepend (cfg->post_filters, cd);
rspamd_mempool_add_destructor (cfg->cfg_pool,
@@ -735,6 +742,8 @@ lua_config_register_pre_filter (lua_State *L)
cd =
rspamd_mempool_alloc (cfg->cfg_pool,
sizeof (struct lua_callback_data));
+ cd->magic = rspamd_lua_callback_magic;
+
if (lua_type (L, 2) == LUA_TSTRING) {
cd->callback.name = rspamd_mempool_strdup (cfg->cfg_pool,
luaL_checkstring (L, 2));
@@ -877,6 +886,7 @@ rspamd_register_symbol_fromlua (lua_State *L,
cd = rspamd_mempool_alloc0 (cfg->cfg_pool,
sizeof (struct lua_callback_data));
+ cd->magic = rspamd_lua_callback_magic;
cd->cb_is_ref = TRUE;
cd->callback.ref = ref;
cd->L = L;
diff --git a/src/plugins/regexp.c b/src/plugins/regexp.c
index d80b11f1f..deb5adab5 100644
--- a/src/plugins/regexp.c
+++ b/src/plugins/regexp.c
@@ -25,7 +25,10 @@
#include "libutil/map.h"
#include "lua/lua_common.h"
+static const guint64 rspamd_regexp_cb_magic = 0xca9d9649fc3e2659ULL;
+
struct regexp_module_item {
+ guint64 magic;
struct rspamd_expression *expr;
const gchar *symbol;
struct ucl_lua_funcdata *lua_function;
@@ -151,6 +154,8 @@ regexp_module_config (struct rspamd_config *cfg)
cur_item = rspamd_mempool_alloc0 (regexp_module_ctx->regexp_pool,
sizeof (struct regexp_module_item));
cur_item->symbol = ucl_object_key (value);
+ cur_item->magic = rspamd_regexp_cb_magic;
+
if (!read_regexp_expression (regexp_module_ctx->regexp_pool,
cur_item, ucl_object_key (value),
ucl_obj_tostring (value), cfg)) {
@@ -170,8 +175,10 @@ regexp_module_config (struct rspamd_config *cfg)
/* Just a lua function */
cur_item = rspamd_mempool_alloc0 (regexp_module_ctx->regexp_pool,
sizeof (struct regexp_module_item));
+ cur_item->magic = rspamd_regexp_cb_magic;
cur_item->symbol = ucl_object_key (value);
cur_item->lua_function = ucl_object_toclosure (value);
+
rspamd_symbols_cache_add_symbol (cfg->cache,
cur_item->symbol,
0,
@@ -199,6 +206,8 @@ regexp_module_config (struct rspamd_config *cfg)
cur_item = rspamd_mempool_alloc0 (regexp_module_ctx->regexp_pool,
sizeof (struct regexp_module_item));
cur_item->symbol = ucl_object_key (value);
+ cur_item->magic = rspamd_regexp_cb_magic;
+
if (!read_regexp_expression (regexp_module_ctx->regexp_pool,
cur_item, ucl_object_key (value),
ucl_obj_tostring (elt), cfg)) {
@@ -221,6 +230,7 @@ regexp_module_config (struct rspamd_config *cfg)
cur_item = rspamd_mempool_alloc0 (
regexp_module_ctx->regexp_pool,
sizeof (struct regexp_module_item));
+ cur_item->magic = rspamd_regexp_cb_magic;
cur_item->symbol = ucl_object_key (value);
cur_item->lua_function = ucl_object_toclosure (value);
}
diff --git a/src/plugins/surbl.c b/src/plugins/surbl.c
index ad2c3be9c..3034a9f47 100644
--- a/src/plugins/surbl.c
+++ b/src/plugins/surbl.c
@@ -43,6 +43,7 @@
#include "unix-std.h"
static struct surbl_ctx *surbl_module_ctx = NULL;
+static const guint64 rspamd_surbl_cb_magic = 0xe09b8536f80de0d1ULL;
static void surbl_test_url (struct rspamd_task *task, void *user_data);
static void surbl_dns_callback (struct rdns_reply *reply, gpointer arg);
@@ -57,6 +58,7 @@ static void process_dns_results (struct rspamd_task *task,
#define WHITELIST_ERROR 0
#define CONVERSION_ERROR 1
#define DUPLICATE_ERROR 1
+
GQuark
surbl_error_quark (void)
{
@@ -600,8 +602,10 @@ surbl_module_config (struct rspamd_config *cfg)
"definition");
continue;
}
+
new_suffix = rspamd_mempool_alloc0 (surbl_module_ctx->surbl_pool,
sizeof (struct suffix_item));
+ new_suffix->magic = rspamd_surbl_cb_magic;
new_suffix->suffix = rspamd_mempool_strdup (
surbl_module_ctx->surbl_pool,
ucl_obj_tostring (cur));
diff --git a/src/plugins/surbl.h b/src/plugins/surbl.h
index 68b27c3f0..69d7d6166 100644
--- a/src/plugins/surbl.h
+++ b/src/plugins/surbl.h
@@ -41,6 +41,7 @@ struct surbl_ctx {
};
struct suffix_item {
+ guint64 magic;
const gchar *suffix;
const gchar *symbol;
guint32 options;