]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Use config checksum for unique tag.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 28 Aug 2015 16:06:48 +0000 (17:06 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 28 Aug 2015 16:06:48 +0000 (17:06 +0100)
src/libserver/cfg_file.h
src/libserver/cfg_rcl.c
src/libserver/symbols_cache.c
src/libserver/symbols_cache.h
src/lua/lua_util.c
src/main.c

index a889987faedbf1c0dfa814e0158f65ed0cefc9ed..3a1e01bfb5cd1b6a43cf3349cc4b961cc122250c 100644 (file)
@@ -449,19 +449,19 @@ gboolean rspamd_config_is_module_enabled (struct rspamd_config *cfg,
                const gchar *module_name);
 
 #define msg_err_config(...) rspamd_default_log_function (G_LOG_LEVEL_CRITICAL, \
-        cfg->cfg_pool->tag.tagname, cfg->cfg_pool->tag.uid, \
+        cfg->cfg_pool->tag.tagname, cfg->checksum, \
         G_STRFUNC, \
         __VA_ARGS__)
 #define msg_warn_config(...)   rspamd_default_log_function (G_LOG_LEVEL_WARNING, \
-        cfg->cfg_pool->tag.tagname, cfg->cfg_pool->tag.uid, \
+        cfg->cfg_pool->tag.tagname, cfg->checksum, \
         G_STRFUNC, \
         __VA_ARGS__)
 #define msg_info_config(...)   rspamd_default_log_function (G_LOG_LEVEL_INFO, \
-        cfg->cfg_pool->tag.tagname, cfg->cfg_pool->tag.uid, \
+        cfg->cfg_pool->tag.tagname, cfg->checksum, \
         G_STRFUNC, \
         __VA_ARGS__)
 #define msg_debug_config(...)  rspamd_default_log_function (G_LOG_LEVEL_DEBUG, \
-        cfg->cfg_pool->tag.tagname, cfg->cfg_pool->tag.uid, \
+        cfg->cfg_pool->tag.tagname, cfg->checksum, \
         G_STRFUNC, \
         __VA_ARGS__)
 
index be0243dc24c11684acb045e5fc88a3d57a433e67..cddf044a9b6310a534b3e2201ddc75c9fb365117 100644 (file)
@@ -21,6 +21,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <blake2.h>
 #include "cfg_rcl.h"
 #include "main.h"
 #include "uthash_strcase.h"
@@ -2386,6 +2387,7 @@ rspamd_config_read (struct rspamd_config *cfg, const gchar *filename,
        GError *err = NULL;
        struct rspamd_rcl_section *top, *logger;
        struct ucl_parser *parser;
+       unsigned char cksumbuf[BLAKE2B_OUTBYTES];
 
        if (stat (filename, &st) == -1) {
                msg_err_config ("cannot stat %s: %s", filename, strerror (errno));
@@ -2405,15 +2407,20 @@ rspamd_config_read (struct rspamd_config *cfg, const gchar *filename,
        }
        close (fd);
 
+       blake2b (cksumbuf, data, NULL, sizeof (cksumbuf), st.st_size, 0);
+       cfg->checksum = rspamd_encode_base32 (cksumbuf, sizeof (cksumbuf));
+
        parser = ucl_parser_new (0);
        rspamd_ucl_add_conf_variables (parser, vars);
        rspamd_ucl_add_conf_macros (parser, cfg);
+
        if (!ucl_parser_add_chunk (parser, data, st.st_size)) {
                msg_err_config ("ucl parser error: %s", ucl_parser_get_error (parser));
                ucl_parser_free (parser);
                munmap (data, st.st_size);
                return FALSE;
        }
+
        munmap (data, st.st_size);
        cfg->rcl_obj = ucl_parser_get_object (parser);
        ucl_parser_free (parser);
index aef6b9cd055cbd224d7826f5e4faf38b68c9064e..5cfa4cff3656062ad4adb7b85cd0203be18278ce 100644 (file)
 #include "lua/lua_common.h"
 
 #define msg_err_cache(...) rspamd_default_log_function (G_LOG_LEVEL_CRITICAL, \
-        cache->static_pool->tag.tagname, cache->static_pool->tag.uid, \
+        cache->static_pool->tag.tagname, cache->cfg->checksum, \
         G_STRFUNC, \
         __VA_ARGS__)
 #define msg_warn_cache(...)   rspamd_default_log_function (G_LOG_LEVEL_WARNING, \
-        cache->static_pool->tag.tagname, cache->static_pool->tag.uid, \
+        cache->static_pool->tag.tagname, cache->cfg->checksum, \
         G_STRFUNC, \
         __VA_ARGS__)
 #define msg_info_cache(...)   rspamd_default_log_function (G_LOG_LEVEL_INFO, \
-        cache->static_pool->tag.tagname, cache->static_pool->tag.uid, \
+        cache->static_pool->tag.tagname, cache->cfg->checksum, \
         G_STRFUNC, \
         __VA_ARGS__)
 #define msg_debug_cache(...)  rspamd_default_log_function (G_LOG_LEVEL_DEBUG, \
-        cache->static_pool->tag.tagname, cache->static_pool->tag.uid, \
+        cache->static_pool->tag.tagname, cache->cfg->checksum, \
         G_STRFUNC, \
         __VA_ARGS__)
 
@@ -605,7 +605,7 @@ rspamd_symbols_cache_destroy (struct symbols_cache *cache)
 }
 
 struct symbols_cache*
-rspamd_symbols_cache_new (void)
+rspamd_symbols_cache_new (struct rspamd_config *cfg)
 {
        struct symbols_cache *cache;
 
@@ -620,27 +620,27 @@ rspamd_symbols_cache_new (void)
        cache->reload_time = CACHE_RELOAD_TIME;
        cache->total_freq = 1;
        cache->max_weight = 1.0;
+       cache->cfg = cfg;
 
        return cache;
 }
 
 gboolean
-rspamd_symbols_cache_init (struct symbols_cache* cache,
-               struct rspamd_config *cfg)
+rspamd_symbols_cache_init (struct symbols_cache* cache)
 {
        gboolean res;
 
        g_assert (cache != NULL);
-       cache->cfg = cfg;
+
 
        /* Just in-memory cache */
-       if (cfg->cache_filename == NULL) {
+       if (cache->cfg->cache_filename == NULL) {
                post_cache_init (cache);
                return TRUE;
        }
 
        /* Copy saved cache entries */
-       res = rspamd_symbols_cache_load_items (cache, cfg->cache_filename);
+       res = rspamd_symbols_cache_load_items (cache, cache->cfg->cache_filename);
 
        return res;
 }
index 2f4e2865708293a63d07c6aeb7af0b38390b8e24..64d1f911f2244844f9018aea59879b9f63a6be73 100644 (file)
@@ -50,7 +50,7 @@ enum rspamd_symbol_type {
  * Creates new cache structure
  * @return
  */
-struct symbols_cache* rspamd_symbols_cache_new (void);
+struct symbols_cache* rspamd_symbols_cache_new (struct rspamd_config *cfg);
 
 /**
  * Remove the cache structure syncing data if needed
@@ -61,8 +61,7 @@ void rspamd_symbols_cache_destroy (struct symbols_cache *cache);
 /**
  * Load symbols cache from file, must be called _after_ init_symbols_cache
  */
-gboolean rspamd_symbols_cache_init (struct symbols_cache* cache,
-       struct rspamd_config *cfg);
+gboolean rspamd_symbols_cache_init (struct symbols_cache* cache);
 
 /**
  * Generic function to register a symbol
index 260ec7b302ee3e22454c1909c8ae5dff72b7bd88..4655399b47614fb4426f79ceff96f310b8b47016 100644 (file)
@@ -151,7 +151,7 @@ lua_util_load_rspamd_config (lua_State *L)
        if (cfg_name) {
                cfg = g_malloc0 (sizeof (struct rspamd_config));
                rspamd_init_cfg (cfg, FALSE);
-               cfg->cache = rspamd_symbols_cache_new ();
+               cfg->cache = rspamd_symbols_cache_new (cfg);
 
                if (rspamd_config_read (cfg, cfg_name, NULL, NULL, NULL, NULL)) {
                        msg_err ("cannot load config from %s", cfg_name);
@@ -159,7 +159,7 @@ lua_util_load_rspamd_config (lua_State *L)
                }
                else {
                        rspamd_config_post_load (cfg);
-                       rspamd_symbols_cache_init (cfg->cache, cfg);
+                       rspamd_symbols_cache_init (cfg->cache);
                        pcfg = lua_newuserdata (L, sizeof (struct rspamd_config *));
                        rspamd_lua_setclass (L, "rspamd{config}", -1);
                        *pcfg = cfg;
@@ -184,7 +184,7 @@ lua_util_config_from_ucl (lua_State *L)
                rspamd_init_cfg (cfg, FALSE);
                cfg->lua_state = L;
                cfg->rcl_obj = obj;
-               cfg->cache = rspamd_symbols_cache_new ();
+               cfg->cache = rspamd_symbols_cache_new (cfg);
                top = rspamd_rcl_config_init ();
 
                if (!rspamd_rcl_parse (top, cfg, cfg->cfg_pool, cfg->rcl_obj, &err)) {
@@ -194,7 +194,7 @@ lua_util_config_from_ucl (lua_State *L)
                }
                else {
                        rspamd_config_post_load (cfg);
-                       rspamd_symbols_cache_init (cfg->cache, cfg);
+                       rspamd_symbols_cache_init (cfg->cache);
                        pcfg = lua_newuserdata (L, sizeof (struct rspamd_config *));
                        rspamd_lua_setclass (L, "rspamd{config}", -1);
                        *pcfg = cfg;
index 93bc5d06a6403f636f5ac926dbc77382e2f2e992..8191982b5fc9b75c05b4e5be93842eb7f75cb8c9 100644 (file)
@@ -392,7 +392,7 @@ reread_config (struct rspamd_main *rspamd)
        rspamd_init_cfg (tmp_cfg, TRUE);
        cfg_file = rspamd_mempool_strdup (tmp_cfg->cfg_pool,
                        rspamd->cfg->cfg_name);
-       tmp_cfg->cache = rspamd_symbols_cache_new ();
+       tmp_cfg->cache = rspamd_symbols_cache_new (tmp_cfg);
        /* Save some variables */
        tmp_cfg->cfg_name = cfg_file;
 
@@ -416,7 +416,7 @@ reread_config (struct rspamd_main *rspamd)
                }
 
                rspamd_init_filters (rspamd->cfg, TRUE);
-               rspamd_symbols_cache_init (rspamd->cfg->cache, rspamd->cfg);
+               rspamd_symbols_cache_init (rspamd->cfg->cache);
                msg_info_main ("config has been reread successfully");
        }
 }
@@ -790,7 +790,7 @@ reopen_log_handler (gpointer key, gpointer value, gpointer unused)
 static gboolean
 load_rspamd_config (struct rspamd_config *cfg, gboolean init_modules)
 {
-       cfg->cache = rspamd_symbols_cache_new ();
+       cfg->cache = rspamd_symbols_cache_new (cfg);
        cfg->compiled_modules = modules;
        cfg->compiled_workers = workers;
 
@@ -1179,7 +1179,7 @@ main (gint argc, gchar **argv, gchar **env)
 
                res = TRUE;
 
-               rspamd_symbols_cache_init (rspamd_main->cfg->cache, rspamd_main->cfg);
+               rspamd_symbols_cache_init (rspamd_main->cfg->cache);
 
                if (!rspamd_init_filters (rspamd_main->cfg, FALSE)) {
                        res = FALSE;
@@ -1247,7 +1247,7 @@ main (gint argc, gchar **argv, gchar **env)
        setproctitle ("main process");
 
        /* Init config cache */
-       rspamd_symbols_cache_init (rspamd_main->cfg->cache, rspamd_main->cfg);
+       rspamd_symbols_cache_init (rspamd_main->cfg->cache);
 
        /* Validate cache */
        (void)rspamd_symbols_cache_validate (rspamd_main->cfg->cache, rspamd_main->cfg, FALSE);