]> source.dussan.org Git - rspamd.git/commitdiff
Fix logging for embedded maps
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 15 Feb 2016 17:28:06 +0000 (17:28 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 15 Feb 2016 17:28:06 +0000 (17:28 +0000)
src/controller.c
src/fuzzy_storage.c
src/libutil/logger.c
src/libutil/map.c
src/libutil/util.c
src/lua/lua_config.c
src/plugins/dkim_check.c
src/plugins/fuzzy_check.c
src/plugins/spf.c
src/plugins/surbl.c

index 8e230eb0fac594bee3adc3ae640b0afb21c33ab6..7d39be8d45598c85334a8556af032738899e53a4 100644 (file)
@@ -2519,16 +2519,19 @@ start_controller_worker (struct rspamd_worker *worker)
                        secure_ip = cur->data;
 
                        /* Try map syntax */
-                       if (!rspamd_map_add (worker->srv->cfg, secure_ip,
-                                       "Allow webui access from the specified IP",
-                                       rspamd_radix_read, rspamd_radix_fin, (void **)&ctx->secure_map)) {
-                               /* Fallback to the plain IP */
+                       if (!rspamd_map_is_map (secure_ip)) {
                                if (!radix_add_generic_iplist (secure_ip,
                                                &ctx->secure_map)) {
                                        msg_warn_ctx ("cannot load or parse ip list from '%s'",
                                                        secure_ip);
                                }
                        }
+                       else {
+                               rspamd_map_add (worker->srv->cfg, secure_ip,
+                                       "Allow webui access from the specified IP",
+                                       rspamd_radix_read, rspamd_radix_fin,
+                                       (void **)&ctx->secure_map);
+                       }
                        cur = g_list_next (cur);
                }
        }
index b852dbb85edd69584f1a1999646884e6caa8afb0..158cdf187141b926454adecf8309011b9c64ab49 100644 (file)
@@ -1384,15 +1384,20 @@ start_fuzzy (struct rspamd_worker *worker)
                        rspamd_fuzzy_storage_stat, ctx);
        /* Create radix tree */
        if (ctx->update_map != NULL) {
-               if (!rspamd_map_add (worker->srv->cfg, ctx->update_map,
-                       "Allow fuzzy updates from specified addresses",
-                       rspamd_radix_read, rspamd_radix_fin, (void **)&ctx->update_ips)) {
+               if (!rspamd_map_is_map (ctx->update_map)) {
                        if (!radix_add_generic_iplist (ctx->update_map,
-                               &ctx->update_ips)) {
+                                       &ctx->update_ips)) {
                                msg_warn ("cannot load or parse ip list from '%s'",
-                                       ctx->update_map);
+                                               ctx->update_map);
                        }
                }
+               else {
+                       rspamd_map_add (worker->srv->cfg, ctx->update_map,
+                                       "Allow fuzzy updates from specified addresses",
+                                       rspamd_radix_read, rspamd_radix_fin,
+                                       (void **)&ctx->update_ips);
+
+               }
        }
 
        /* Maps events */
index 53415a8308e72e0aa5d04ec36f630f5122e71ae1..56f7822a5e7b31f113b5d9efdfadd72ad2e05cb0 100644 (file)
@@ -351,13 +351,18 @@ rspamd_set_logger (struct rspamd_config *cfg,
                if (rspamd->logger->debug_ip) {
                        radix_destroy_compressed (rspamd->logger->debug_ip);
                }
+
                rspamd->logger->debug_ip = radix_create_compressed ();
-               if (!rspamd_map_add (rspamd->cfg, rspamd->cfg->debug_ip_map,
+
+               if (!rspamd_map_is_map (rspamd->cfg->debug_ip_map)) {
+                       radix_add_generic_iplist (rspamd->cfg->debug_ip_map,
+                                                               &rspamd->logger->debug_ip);
+               }
+               else {
+                       rspamd_map_add (rspamd->cfg, rspamd->cfg->debug_ip_map,
                                "IP addresses for which debug logs are enabled",
                                rspamd_radix_read, rspamd_radix_fin,
-                               (void **) &rspamd->logger->debug_ip)) {
-                       radix_add_generic_iplist (rspamd->cfg->debug_ip_map,
-                                       &rspamd->logger->debug_ip);
+                               (void **) &rspamd->logger->debug_ip);
                }
        }
        else if (rspamd->logger->debug_ip) {
index 07558c2966e3637245e870c2f8aa8f0bbb5a6dde..33cfc0cd58d2031af26262dcc9a3fa89dc3788df 100644 (file)
@@ -270,6 +270,12 @@ rspamd_map_check_file_sig (const char *fname,
                return FALSE;
        }
 
+       b32_key = rspamd_pubkey_print (pk,
+                                       RSPAMD_KEYPAIR_BASE32|RSPAMD_KEYPAIR_PUBKEY);
+       msg_info_pool ("verified signature in file %s using trusted key %v",
+                       fpath, b32_key);
+       g_string_free (b32_key, TRUE);
+
        rspamd_pubkey_unref (pk);
        munmap (data, len);
 
index 30665dfb895b8122aecd7fcfceaa3f3fef58b1a0..0023a9ba1852ffa0265df95effb128bea896a4ae 100644 (file)
@@ -2019,12 +2019,15 @@ rspamd_config_libs (struct rspamd_external_libs_ctx *ctx,
 
        if (ctx != NULL) {
                if (cfg->local_addrs) {
-                       if (!rspamd_map_add (cfg, cfg->local_addrs,
-                                       "Local addresses", rspamd_radix_read, rspamd_radix_fin,
-                                       (void **) ctx->local_addrs)) {
+                       if (!rspamd_map_is_map (cfg->local_addrs)) {
                                radix_add_generic_iplist (cfg->local_addrs,
                                                (radix_compressed_t **)ctx->local_addrs);
                        }
+                       else {
+                               rspamd_map_add (cfg, cfg->local_addrs,
+                                       "Local addresses", rspamd_radix_read, rspamd_radix_fin,
+                                       (void **) ctx->local_addrs);
+                       }
                }
        }
 }
index 1ab7a746bc04b0a59c1ef75472b0ae609a8a21ce..9cf18fa224df4bbc9d27d5726bc190d4d0e8fd6a 100644 (file)
@@ -756,7 +756,7 @@ lua_config_add_radix_map (lua_State *L)
                *r = radix_create_compressed ();
 
                if (!rspamd_map_add (cfg, map_line, description, rspamd_radix_read,
-                       rspamd_radix_fin, (void **)r)) {
+                               rspamd_radix_fin, (void **)r)) {
                        msg_warn_config ("invalid radix map %s", map_line);
                        radix_destroy_compressed (*r);
                        lua_pushnil (L);
@@ -827,8 +827,10 @@ lua_config_add_hash_map (lua_State *L)
                r = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (GHashTable *));
                *r = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal);
 
-               if (!rspamd_map_add (cfg, map_line, description, rspamd_hosts_read, rspamd_hosts_fin,
-                       (void **)r)) {
+               if (!rspamd_map_add (cfg, map_line, description,
+                               rspamd_hosts_read,
+                               rspamd_hosts_fin,
+                               (void **)r)) {
                        msg_warn ("invalid hash map %s", map_line);
                        g_hash_table_destroy (*r);
                        lua_pushnil (L);
@@ -863,8 +865,10 @@ lua_config_add_kv_map (lua_State *L)
                r = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (GHashTable *));
                *r = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal);
 
-               if (!rspamd_map_add (cfg, map_line, description, rspamd_kv_list_read, rspamd_kv_list_fin,
-                       (void **)r)) {
+               if (!rspamd_map_add (cfg, map_line, description,
+                               rspamd_kv_list_read,
+                               rspamd_kv_list_fin,
+                               (void **)r)) {
                        msg_warn_config ("invalid hash map %s", map_line);
                        g_hash_table_destroy (*r);
                        lua_pushnil (L);
index a30a52e6eea559e82adf4fcaf313c0a334be4695..8147eb27002decbb6053e19a509f8ab36008201c 100644 (file)
@@ -220,6 +220,7 @@ gint
 dkim_module_config (struct rspamd_config *cfg)
 {
        const ucl_object_t *value;
+       const gchar *str;
        gint res = TRUE, cb_id;
        guint cache_size, cache_expire;
        gboolean got_trusted = FALSE;
@@ -277,11 +278,16 @@ dkim_module_config (struct rspamd_config *cfg)
        }
        if ((value =
                rspamd_config_get_module_opt (cfg, "dkim", "whitelist")) != NULL) {
-               if (!rspamd_map_add (cfg, ucl_obj_tostring (value),
-                       "DKIM whitelist", rspamd_radix_read, rspamd_radix_fin,
-                       (void **)&dkim_module_ctx->whitelist_ip)) {
-                       radix_add_generic_iplist (ucl_obj_tostring (value),
-                               &dkim_module_ctx->whitelist_ip);
+               str = ucl_obj_tostring (value);
+               if (!rspamd_map_is_map (str)) {
+                       radix_add_generic_iplist (str,
+                                       &dkim_module_ctx->whitelist_ip);
+               }
+               else {
+                       rspamd_map_add (cfg, str,
+                                       "DKIM whitelist", rspamd_radix_read, rspamd_radix_fin,
+                                       (void **)&dkim_module_ctx->whitelist_ip);
+
                }
        }
        if ((value =
index 85c147a523b8bc17c332fff91acc26fc4a02f6d5..788601f1ea6f8b7d407f3f2adb945f9a5f1dff76 100644 (file)
@@ -757,6 +757,7 @@ fuzzy_check_module_config (struct rspamd_config *cfg)
 {
        const ucl_object_t *value, *cur;
        gint res = TRUE, cb_id, nrules = 0;
+       const gchar *str;
 
        if (!rspamd_config_is_module_enabled (cfg, "fuzzy_check")) {
                return TRUE;
@@ -824,12 +825,20 @@ fuzzy_check_module_config (struct rspamd_config *cfg)
                rspamd_config_get_module_opt (cfg, "fuzzy_check",
                "whitelist")) != NULL) {
                fuzzy_module_ctx->whitelist = radix_create_compressed ();
-               if (!rspamd_map_add (cfg, ucl_obj_tostring (value),
-                       "Fuzzy whitelist", rspamd_radix_read, rspamd_radix_fin,
-                       (void **)&fuzzy_module_ctx->whitelist)) {
-                       radix_add_generic_iplist (ucl_obj_tostring (value),
+               ucl_obj_tostring (value);
+
+               str = ucl_obj_tostring (value);
+
+               if (!rspamd_map_is_map (str)) {
+                       radix_add_generic_iplist (str,
                                        &fuzzy_module_ctx->whitelist);
                }
+               else {
+                       rspamd_map_add (cfg, str,
+                                       "Fuzzy whitelist", rspamd_radix_read, rspamd_radix_fin,
+                                       (void **)&fuzzy_module_ctx->whitelist);
+
+               }
        }
        else {
                fuzzy_module_ctx->whitelist = NULL;
index a02dcc002d7ca51ee143880c4ea2447ed2cb4a0d..edad4bfc9d63e568a6c945fa3350b57c8347dd42 100644 (file)
@@ -173,6 +173,7 @@ spf_module_config (struct rspamd_config *cfg)
        const ucl_object_t *value;
        gint res = TRUE, cb_id;
        guint cache_size, cache_expire;
+       const gchar *str;
 
        if (!rspamd_config_is_module_enabled (cfg, "spf")) {
                return TRUE;
@@ -225,11 +226,18 @@ spf_module_config (struct rspamd_config *cfg)
        }
        if ((value =
                rspamd_config_get_module_opt (cfg, "spf", "whitelist")) != NULL) {
-               if (!rspamd_map_add (cfg, ucl_obj_tostring (value),
-                       "SPF whitelist", rspamd_radix_read, rspamd_radix_fin,
-                       (void **)&spf_module_ctx->whitelist_ip)) {
-                       radix_add_generic_iplist (ucl_obj_tostring (value),
-                               &spf_module_ctx->whitelist_ip);
+
+               str = ucl_obj_tostring (value);
+
+               if (!rspamd_map_is_map (str)) {
+                       radix_add_generic_iplist (str,
+                                       &spf_module_ctx->whitelist_ip);
+               }
+               else {
+                       rspamd_map_add (cfg, str,
+                                       "SPF whitelist", rspamd_radix_read, rspamd_radix_fin,
+                                       (void **)&spf_module_ctx->whitelist_ip);
+
                }
        }
 
index cbd5f0f2bee67e4f161f50031ce5ac8b56250fe1..b49ed8f3c3125b5e383c9f039600e8a840a0310d 100644 (file)
@@ -574,7 +574,7 @@ surbl_module_config (struct rspamd_config *cfg)
                }
        }
        if ((value =
-               rspamd_config_get_module_opt (cfg, "surbl", "whitelist")) != NULL) {
+                       rspamd_config_get_module_opt (cfg, "surbl", "whitelist")) != NULL) {
                if (rspamd_map_add (cfg, ucl_obj_tostring (value),
                        "SURBL whitelist", rspamd_hosts_read, rspamd_hosts_fin,
                        (void **)&surbl_module_ctx->whitelist)) {