From 62cc91ffb8af40cca3dc82037d87bab8ff270524 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 10 May 2016 15:29:05 +0100 Subject: [PATCH] [Feature] Adopt plugins for new maps API --- src/controller.c | 43 ++++++++++++++++++++++----------------- src/plugins/dkim_check.c | 9 ++++---- src/plugins/fuzzy_check.c | 4 ++-- src/plugins/spf.c | 4 ++-- src/plugins/surbl.c | 6 +++--- 5 files changed, 36 insertions(+), 30 deletions(-) diff --git a/src/controller.c b/src/controller.c index 62e2e8dd5..8b16eda19 100644 --- a/src/controller.c +++ b/src/controller.c @@ -145,7 +145,7 @@ struct rspamd_controller_worker_ctx { /* SSL private key */ gchar *ssl_key; /* A map of secure IP */ - GList *secure_ip; + const ucl_object_t *secure_ip; radix_compressed_t *secure_map; /* Static files dir */ @@ -2490,7 +2490,7 @@ init_controller_worker (struct rspamd_config *cfg) rspamd_rcl_register_worker_option (cfg, type, "secure_ip", - rspamd_rcl_parse_struct_string_list, + rspamd_rcl_parse_struct_ucl, ctx, G_STRUCT_OFFSET (struct rspamd_controller_worker_ctx, secure_ip), 0, @@ -2499,7 +2499,7 @@ init_controller_worker (struct rspamd_config *cfg) rspamd_rcl_register_worker_option (cfg, type, "trusted_ips", - rspamd_rcl_parse_struct_string_list, + rspamd_rcl_parse_struct_ucl, ctx, G_STRUCT_OFFSET (struct rspamd_controller_worker_ctx, secure_ip), 0, @@ -2545,12 +2545,12 @@ void start_controller_worker (struct rspamd_worker *worker) { struct rspamd_controller_worker_ctx *ctx = worker->ctx; - GList *cur; struct module_ctx *mctx; GHashTableIter iter; gpointer key, value; struct rspamd_keypair_cache *cache; - gchar *secure_ip; + const ucl_object_t *cur; + ucl_object_iter_t it = NULL; gpointer m; ctx->ev_base = rspamd_prepare_worker (worker, @@ -2565,26 +2565,31 @@ start_controller_worker (struct rspamd_worker *worker) ctx->custom_commands = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal); if (ctx->secure_ip != NULL) { - cur = ctx->secure_ip; - while (cur) { - secure_ip = cur->data; - - /* Try map syntax */ - 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); + 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 { - rspamd_map_add (worker->srv->cfg, secure_ip, + } + 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); - } - cur = g_list_next (cur); } } diff --git a/src/plugins/dkim_check.c b/src/plugins/dkim_check.c index 9cf89674e..3ea31485f 100644 --- a/src/plugins/dkim_check.c +++ b/src/plugins/dkim_check.c @@ -271,13 +271,14 @@ dkim_module_config (struct rspamd_config *cfg) } if ((value = rspamd_config_get_module_opt (cfg, "dkim", "whitelist")) != NULL) { + str = ucl_obj_tostring (value); - if (!rspamd_map_is_map (str)) { + if (str && !rspamd_map_is_map (str)) { radix_add_generic_iplist (str, &dkim_module_ctx->whitelist_ip); } else { - rspamd_map_add (cfg, str, + rspamd_map_add_from_ucl (cfg, value, "DKIM whitelist", rspamd_radix_read, rspamd_radix_fin, (void **)&dkim_module_ctx->whitelist_ip); @@ -285,7 +286,7 @@ dkim_module_config (struct rspamd_config *cfg) } if ((value = rspamd_config_get_module_opt (cfg, "dkim", "domains")) != NULL) { - if (!rspamd_map_add (cfg, ucl_obj_tostring (value), + if (!rspamd_map_add_from_ucl (cfg, value, "DKIM domains", rspamd_kv_list_read, rspamd_kv_list_fin, (void **)&dkim_module_ctx->dkim_domains)) { msg_warn_config ("cannot load dkim domains list from %s", @@ -297,7 +298,7 @@ dkim_module_config (struct rspamd_config *cfg) } if (!got_trusted && (value = rspamd_config_get_module_opt (cfg, "dkim", "trusted_domains")) != NULL) { - if (!rspamd_map_add (cfg, ucl_obj_tostring (value), + if (!rspamd_map_add_from_ucl (cfg, value, "DKIM domains", rspamd_kv_list_read, rspamd_kv_list_fin, (void **)&dkim_module_ctx->dkim_domains)) { msg_warn_config ("cannot load dkim domains list from %s", diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c index 385b8aadc..a5b62875e 100644 --- a/src/plugins/fuzzy_check.c +++ b/src/plugins/fuzzy_check.c @@ -832,12 +832,12 @@ fuzzy_check_module_config (struct rspamd_config *cfg) str = ucl_obj_tostring (value); - if (!rspamd_map_is_map (str)) { + if (str && !rspamd_map_is_map (str)) { radix_add_generic_iplist (str, &fuzzy_module_ctx->whitelist); } else { - rspamd_map_add (cfg, str, + rspamd_map_add_from_ucl (cfg, value, "Fuzzy whitelist", rspamd_radix_read, rspamd_radix_fin, (void **)&fuzzy_module_ctx->whitelist); diff --git a/src/plugins/spf.c b/src/plugins/spf.c index 153422f51..67c8732e7 100644 --- a/src/plugins/spf.c +++ b/src/plugins/spf.c @@ -213,12 +213,12 @@ spf_module_config (struct rspamd_config *cfg) str = ucl_obj_tostring (value); - if (!rspamd_map_is_map (str)) { + if (str && !rspamd_map_is_map (str)) { radix_add_generic_iplist (str, &spf_module_ctx->whitelist_ip); } else { - rspamd_map_add (cfg, str, + rspamd_map_add_from_ucl (cfg, value, "SPF whitelist", rspamd_radix_read, rspamd_radix_fin, (void **)&spf_module_ctx->whitelist_ip); diff --git a/src/plugins/surbl.c b/src/plugins/surbl.c index 35383c829..87b8effa7 100644 --- a/src/plugins/surbl.c +++ b/src/plugins/surbl.c @@ -528,7 +528,7 @@ surbl_module_config (struct rspamd_config *cfg) if ((value = rspamd_config_get_module_opt (cfg, "surbl", "redirector_hosts_map")) != NULL) { - if (!rspamd_map_add (cfg, ucl_obj_tostring (value), + if (!rspamd_map_add_from_ucl (cfg, value, "SURBL redirectors list", read_redirectors_list, fin_redirectors_list, (void **)&surbl_module_ctx->redirector_map_data)) { @@ -546,7 +546,7 @@ surbl_module_config (struct rspamd_config *cfg) } if ((value = rspamd_config_get_module_opt (cfg, "surbl", "exceptions")) != NULL) { - if (rspamd_map_add (cfg, ucl_obj_tostring (value), + if (rspamd_map_add_from_ucl (cfg, value, "SURBL exceptions list", read_exceptions_list, fin_exceptions_list, (void **)&surbl_module_ctx->exceptions)) { surbl_module_ctx->tld2_file = rspamd_mempool_strdup ( @@ -556,7 +556,7 @@ surbl_module_config (struct rspamd_config *cfg) } if ((value = rspamd_config_get_module_opt (cfg, "surbl", "whitelist")) != NULL) { - if (rspamd_map_add (cfg, ucl_obj_tostring (value), + if (rspamd_map_add_from_ucl (cfg, value, "SURBL whitelist", rspamd_hosts_read, rspamd_hosts_fin, (void **)&surbl_module_ctx->whitelist)) { surbl_module_ctx->whitelist_file = rspamd_mempool_strdup ( -- 2.39.5