From: Vsevolod Stakhov Date: Sat, 25 Jun 2016 12:40:00 +0000 (+0100) Subject: [Feature] Use new ip parsing API X-Git-Tag: 1.3.0~253 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9919068fcd7e999502ec62cc1fd2b794e5ced55b;p=thirdparty%2Frspamd.git [Feature] Use new ip parsing API --- diff --git a/src/controller.c b/src/controller.c index f2352e514a..1021939aea 100644 --- a/src/controller.c +++ b/src/controller.c @@ -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) { diff --git a/src/fuzzy_storage.c b/src/fuzzy_storage.c index ece1711357..04292e3633 100644 --- a/src/fuzzy_storage.c +++ b/src/fuzzy_storage.c @@ -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 */ diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h index 4a0c170627..86aad51172 100644 --- a/src/libserver/cfg_file.h +++ b/src/libserver/cfg_file.h @@ -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 */ diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c index 976198b9bc..849ec92c02 100644 --- a/src/libserver/cfg_rcl.c +++ b/src/libserver/cfg_rcl.c @@ -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"); diff --git a/src/libutil/addr.c b/src/libutil/addr.c index 3fee0b4bc2..5d96472a00 100644 --- a/src/libutil/addr.c +++ b/src/libutil/addr.c @@ -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 diff --git a/src/libutil/addr.h b/src/libutil/addr.h index 200543d6f7..1d400c5e49 100644 --- a/src/libutil/addr.h +++ b/src/libutil/addr.h @@ -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); /** diff --git a/src/libutil/logger.c b/src/libutil/logger.c index 7f46c2a503..4f6da0c620 100644 --- a/src/libutil/logger.c +++ b/src/libutil/logger.c @@ -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); diff --git a/src/libutil/util.c b/src/libutil/util.c index f3effe5cf5..196c542226 100644 --- a/src/libutil/util.c +++ b/src/libutil/util.c @@ -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) { diff --git a/src/plugins/dkim_check.c b/src/plugins/dkim_check.c index 3ea31485fe..a7e09aa539 100644 --- a/src/plugins/dkim_check.c +++ b/src/plugins/dkim_check.c @@ -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) { diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c index 595df53fc8..caf894bf3f 100644 --- a/src/plugins/fuzzy_check.c +++ b/src/plugins/fuzzy_check.c @@ -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; diff --git a/src/plugins/spf.c b/src/plugins/spf.c index 67c8732e7c..ec75408958 100644 --- a/src/plugins/spf.c +++ b/src/plugins/spf.c @@ -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, diff --git a/src/rspamd.h b/src/rspamd.h index 6a24370aa2..0e32bcdcf6 100644 --- a/src/rspamd.h +++ b/src/rspamd.h @@ -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;