]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Use new ip parsing API
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 25 Jun 2016 12:40:00 +0000 (13:40 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 25 Jun 2016 12:40:00 +0000 (13:40 +0100)
12 files changed:
src/controller.c
src/fuzzy_storage.c
src/libserver/cfg_file.h
src/libserver/cfg_rcl.c
src/libutil/addr.c
src/libutil/addr.h
src/libutil/logger.c
src/libutil/util.c
src/plugins/dkim_check.c
src/plugins/fuzzy_check.c
src/plugins/spf.c
src/rspamd.h

index f2352e514ac54918dc402b96a3c3b438181ed632..1021939aea9ed656e04767b78901c73c3923bfdc 100644 (file)
@@ -2565,8 +2565,6 @@ start_controller_worker (struct rspamd_worker *worker)
        GHashTableIter iter;
        gpointer key, value;
        struct rspamd_keypair_cache *cache;
-       const ucl_object_t *cur;
-       ucl_object_iter_t it = NULL;
        gpointer m;
 
        ctx->ev_base = rspamd_prepare_worker (worker,
@@ -2582,44 +2580,9 @@ start_controller_worker (struct rspamd_worker *worker)
                        rspamd_strcase_equal);
 
        if (ctx->secure_ip != NULL) {
-               if (ucl_object_type (ctx->secure_ip) == UCL_ARRAY) {
-
-                       while ((cur = ucl_object_iterate (ctx->secure_ip, &it, true)) != NULL) {
-                               /* Try map syntax */
-                               if (ucl_object_type (cur) == UCL_STRING &&
-                                               !rspamd_map_is_map (ucl_object_tostring (cur))) {
-                                       if (!radix_add_generic_iplist (ucl_object_tostring (cur),
-                                                       &ctx->secure_map)) {
-                                               msg_warn_ctx ("cannot load or parse ip list from '%s'",
-                                                               ucl_object_tostring (cur));
-                                       }
-                               }
-                               else {
-                                       rspamd_map_add_from_ucl (worker->srv->cfg, cur,
-                                                       "Allow webui access from the specified IP",
-                                                       rspamd_radix_read, rspamd_radix_fin,
-                                                       (void **)&ctx->secure_map);
-                               }
-                       }
-               }
-               else {
-                       LL_FOREACH (ctx->secure_ip, cur) {
-                               if (ucl_object_type (cur) == UCL_STRING &&
-                                               !rspamd_map_is_map (ucl_object_tostring (cur))) {
-                                       if (!radix_add_generic_iplist (ucl_object_tostring (cur),
-                                                       &ctx->secure_map)) {
-                                               msg_warn_ctx ("cannot load or parse ip list from '%s'",
-                                                               ucl_object_tostring (cur));
-                                       }
-                               }
-                               else {
-                                       rspamd_map_add_from_ucl (worker->srv->cfg, ctx->secure_ip,
-                                                       "Allow webui access from the specified IP",
-                                                       rspamd_radix_read, rspamd_radix_fin,
-                                                       (void **)&ctx->secure_map);
-                               }
-                       }
-               }
+               rspamd_config_radix_from_ucl (ctx->cfg, ctx->secure_ip,
+                               "Allow unauthenticated requests from these addresses",
+                               &ctx->secure_map, NULL);
        }
 
        if (ctx->saved_stats_path == NULL) {
index ece17113578e77cf5713d9abfa394f3286e277eb..04292e3633ea0de763b460703229482652d205f8 100644 (file)
@@ -108,8 +108,8 @@ struct rspamd_fuzzy_storage_ctx {
        struct timeval master_io_tv;
        gdouble master_timeout;
        GPtrArray *mirrors;
-       gchar *update_map;
-       gchar *masters_map;
+       const ucl_object_t *update_map;
+       const ucl_object_t *masters_map;
        guint keypair_cache_size;
        struct event_base *ev_base;
        gint peer_fd;
@@ -1863,7 +1863,7 @@ init_fuzzy (struct rspamd_config *cfg)
        rspamd_rcl_register_worker_option (cfg,
                        type,
                        "allow_update",
-                       rspamd_rcl_parse_struct_string,
+                       rspamd_rcl_parse_struct_ucl,
                        ctx,
                        G_STRUCT_OFFSET (struct rspamd_fuzzy_storage_ctx, update_map),
                        0,
@@ -1919,7 +1919,7 @@ init_fuzzy (struct rspamd_config *cfg)
        rspamd_rcl_register_worker_option (cfg,
                        type,
                        "masters",
-                       rspamd_rcl_parse_struct_string,
+                       rspamd_rcl_parse_struct_ucl,
                        ctx,
                        G_STRUCT_OFFSET (struct rspamd_fuzzy_storage_ctx, masters_map),
                        0,
@@ -2094,36 +2094,14 @@ start_fuzzy (struct rspamd_worker *worker)
                                rspamd_fuzzy_storage_sync, ctx);
        /* Create radix trees */
        if (ctx->update_map != NULL) {
-               if (!rspamd_map_is_map (ctx->update_map)) {
-                       if (!radix_add_generic_iplist (ctx->update_map,
-                                       &ctx->update_ips)) {
-                               msg_warn ("cannot load or parse ip list from '%s'",
-                                               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);
-
-               }
+               rspamd_config_radix_from_ucl (worker->srv->cfg, ctx->update_map,
+                               "Allow fuzzy updates from specified addresses",
+                               &ctx->update_ips, NULL);
        }
        if (ctx->masters_map != NULL) {
-               if (!rspamd_map_is_map (ctx->masters_map)) {
-                       if (!radix_add_generic_iplist (ctx->masters_map,
-                                       &ctx->master_ips)) {
-                               msg_warn ("cannot load or parse ip list from '%s'",
-                                               ctx->masters_map);
-                       }
-               }
-               else {
-                       rspamd_map_add (worker->srv->cfg, ctx->masters_map,
-                                       "Allow fuzzy master/slave updates from specified addresses",
-                                       rspamd_radix_read, rspamd_radix_fin,
-                                       (void **)&ctx->master_ips);
-
-               }
+               rspamd_config_radix_from_ucl (worker->srv->cfg, ctx->masters_map,
+                               "Allow fuzzy master/slave updates from specified addresses",
+                               &ctx->master_ips, NULL);
        }
 
        /* Maps events */
index 4a0c170627c2bb1b6d015f94fbe81027ddd4651e..86aad511722912b9ae0e38fc30b7910c45064bdf 100644 (file)
@@ -306,7 +306,7 @@ struct rspamd_config {
        gchar *log_file;                                /**< path to logfile in case of file logging                    */
        gboolean log_buffered;                          /**< whether logging is buffered                                                */
        guint32 log_buf_size;                           /**< length of log buffer                                                               */
-       gchar *debug_ip_map;                            /**< turn on debugging for specified ip addresses       */
+       const ucl_object_t *debug_ip_map;               /**< turn on debugging for specified ip addresses       */
        gboolean log_urls;                              /**< whether we should log URLs                         */
        GList *debug_symbols;                           /**< symbols to debug                                                                   */
        GHashTable *debug_modules;                      /**< logging modules to debug                                                   */
index 976198b9bc5e5d26b67c2c939e00a261894aec7a..849ec92c0287898e3f273fe72ad8efac98b6a898 100644 (file)
@@ -1616,7 +1616,7 @@ rspamd_rcl_config_init (struct rspamd_config *cfg)
                        "Write statistics of regexp processing to log (useful for hyperscan)");
        rspamd_rcl_add_default_handler (sub,
                        "debug_ip",
-                       rspamd_rcl_parse_struct_string,
+                       rspamd_rcl_parse_struct_ucl,
                        G_STRUCT_OFFSET (struct rspamd_config, debug_ip_map),
                        0,
                        "Enable debugging log for the specified IP addresses");
index 3fee0b4bc2ffbc2393ddb3299c74621e64c03a08..5d96472a00132f3f7f116a84bb9dd1608fc8f4ce 100644 (file)
@@ -1506,10 +1506,10 @@ rspamd_inet_address_is_local (const rspamd_inet_addr_t *addr)
        return FALSE;
 }
 
-void **
+radix_compressed_t **
 rspamd_inet_library_init (void)
 {
-       return (void **)&local_addrs;
+       return &local_addrs;
 }
 
 void
index 200543d6f76f04fa15f9df6aa2443caba629c9a2..1d400c5e496b70c96f6a7c670ab747525a9a99ed 100644 (file)
@@ -39,8 +39,9 @@
  * Opaque structure
  */
 typedef struct rspamd_inet_addr_s rspamd_inet_addr_t;
+struct radix_tree_compressed;
 
-void **rspamd_inet_library_init (void);
+struct radix_tree_compressed **rspamd_inet_library_init (void);
 void rspamd_inet_library_destroy (void);
 
 /**
index 7f46c2a503b6e493638f302dfeece15ba39ea3e1..4f6da0c62049576f7d40a14c6efac7445dd1aa45 100644 (file)
@@ -355,18 +355,12 @@ rspamd_set_logger (struct rspamd_config *cfg,
                        radix_destroy_compressed (rspamd->logger->debug_ip);
                }
 
-               rspamd->logger->debug_ip = radix_create_compressed ();
+               rspamd->logger->debug_ip = NULL;
 
-               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,
+               rspamd_config_radix_from_ucl (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);
-               }
+                               &rspamd->logger->debug_ip, NULL);
        }
        else if (rspamd->logger->debug_ip) {
                radix_destroy_compressed (rspamd->logger->debug_ip);
index f3effe5cf5f4cc7d1915794d1ae92e92bcc4d4e3..196c5422266b3af3799e1d0be4bd5e7af8e77751 100644 (file)
@@ -2085,16 +2085,8 @@ rspamd_config_libs (struct rspamd_external_libs_ctx *ctx,
 
        if (ctx != NULL) {
                if (cfg->local_addrs) {
-                       if (ucl_object_type (cfg->local_addrs) == UCL_STRING &&
-                                       !rspamd_map_is_map (ucl_object_tostring (cfg->local_addrs))) {
-                               radix_add_generic_iplist (ucl_object_tostring (cfg->local_addrs),
-                                               (radix_compressed_t **)ctx->local_addrs);
-                       }
-                       else {
-                               rspamd_map_add_from_ucl (cfg, cfg->local_addrs,
-                                       "Local addresses", rspamd_radix_read, rspamd_radix_fin,
-                                       (void **) ctx->local_addrs);
-                       }
+                       rspamd_config_radix_from_ucl (cfg, cfg->local_addrs, "Local addresses",
+                                       ctx->local_addrs, NULL);
                }
 
                if (cfg->ssl_ca_path) {
index 3ea31485fe20ba912ba9ccc807f19187b076d9e3..a7e09aa539c150f2189e5f7c82b6361361401829 100644 (file)
@@ -220,7 +220,6 @@ gint
 dkim_module_config (struct rspamd_config *cfg)
 {
        const ucl_object_t *value;
-       const gchar *str;
        gint res = TRUE, cb_id;
        guint cache_size;
        gboolean got_trusted = FALSE;
@@ -272,17 +271,8 @@ dkim_module_config (struct rspamd_config *cfg)
        if ((value =
                rspamd_config_get_module_opt (cfg, "dkim", "whitelist")) != NULL) {
 
-               str = ucl_obj_tostring (value);
-               if (str && !rspamd_map_is_map (str)) {
-                       radix_add_generic_iplist (str,
-                                       &dkim_module_ctx->whitelist_ip);
-               }
-               else {
-                       rspamd_map_add_from_ucl (cfg, value,
-                                       "DKIM whitelist", rspamd_radix_read, rspamd_radix_fin,
-                                       (void **)&dkim_module_ctx->whitelist_ip);
-
-               }
+               rspamd_config_radix_from_ucl (cfg, value, "DKIM whitelist",
+                               &dkim_module_ctx->whitelist_ip, NULL);
        }
        if ((value =
                rspamd_config_get_module_opt (cfg, "dkim", "domains")) != NULL) {
index 595df53fc80d42ee448872cc73179ac590a4f0e2..caf894bf3fbaa33c8d5d52478cb20fb1392bca4b 100644 (file)
@@ -828,7 +828,6 @@ 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;
-       const gchar *str;
 
        if (!rspamd_config_is_module_enabled (cfg, "fuzzy_check")) {
                return TRUE;
@@ -895,21 +894,8 @@ fuzzy_check_module_config (struct rspamd_config *cfg)
        if ((value =
                rspamd_config_get_module_opt (cfg, "fuzzy_check",
                "whitelist")) != NULL) {
-               fuzzy_module_ctx->whitelist = radix_create_compressed ();
-               ucl_obj_tostring (value);
-
-               str = ucl_obj_tostring (value);
-
-               if (str && !rspamd_map_is_map (str)) {
-                       radix_add_generic_iplist (str,
-                                       &fuzzy_module_ctx->whitelist);
-               }
-               else {
-                       rspamd_map_add_from_ucl (cfg, value,
-                                       "Fuzzy whitelist", rspamd_radix_read, rspamd_radix_fin,
-                                       (void **)&fuzzy_module_ctx->whitelist);
-
-               }
+               rspamd_config_radix_from_ucl (cfg, value, "Fuzzy whitelist",
+                               &fuzzy_module_ctx->whitelist, NULL);
        }
        else {
                fuzzy_module_ctx->whitelist = NULL;
index 67c8732e7c52613d48e65601653785e770171709..ec75408958564bc5a86453b7ae6ac4b3ae2fa489 100644 (file)
@@ -164,7 +164,6 @@ spf_module_config (struct rspamd_config *cfg)
        const ucl_object_t *value;
        gint res = TRUE, cb_id;
        guint cache_size;
-       const gchar *str;
 
        if (!rspamd_config_is_module_enabled (cfg, "spf")) {
                return TRUE;
@@ -211,18 +210,8 @@ spf_module_config (struct rspamd_config *cfg)
        if ((value =
                rspamd_config_get_module_opt (cfg, "spf", "whitelist")) != NULL) {
 
-               str = ucl_obj_tostring (value);
-
-               if (str && !rspamd_map_is_map (str)) {
-                       radix_add_generic_iplist (str,
-                                       &spf_module_ctx->whitelist_ip);
-               }
-               else {
-                       rspamd_map_add_from_ucl (cfg, value,
-                                       "SPF whitelist", rspamd_radix_read, rspamd_radix_fin,
-                                       (void **)&spf_module_ctx->whitelist_ip);
-
-               }
+               rspamd_config_radix_from_ucl (cfg, value, "SPF whitelist",
+                               &spf_module_ctx->whitelist_ip, NULL);
        }
 
        cb_id = rspamd_symbols_cache_add_symbol (cfg->cache,
index 6a24370aa25e56522cd57d4df90020b7d0ee8e44..0e32bcdcf6013cfa004f6e9bf36243e7062b1f65 100644 (file)
@@ -13,6 +13,7 @@
 #include "libutil/logger.h"
 #include "libutil/http.h"
 #include "libutil/upstream.h"
+#include "libutil/radix.h"
 #include "libserver/url.h"
 #include "libserver/protocol.h"
 #include "libserver/buffer.h"
@@ -293,7 +294,7 @@ struct controller_session {
 
 struct rspamd_external_libs_ctx {
        magic_t libmagic;
-       void **local_addrs;
+       radix_compressed_t **local_addrs;
        struct rspamd_cryptobox_library_ctx *crypto_ctx;
        struct ottery_config *ottery_cfg;
        SSL_CTX *ssl_ctx;