]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Fix static maps description passing
authorVsevolod Stakhov <vsevolod@rspamd.com>
Mon, 24 Mar 2025 07:29:06 +0000 (07:29 +0000)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Mon, 24 Mar 2025 07:29:06 +0000 (07:29 +0000)
lualib/lua_maps.lua
src/libserver/maps/map.c
src/lua/lua_config.c
src/lua/lua_map.c

index 6dad3b6ad1b6202d3a71b23dd3cd099eef4b08b3..2cf3858c7b63cb4ef8427946a1110af370e7e87d 100644 (file)
@@ -138,7 +138,8 @@ local function query_external_map(map_config, upstreams, key, callback, task)
         local params_table = {}
         for k, v in pairs(key) do
           if type(v) == 'string' then
-            table.insert(params_table, string.format('%s=%s', lua_util.url_encode_string(k), lua_util.url_encode_string(v)))
+            table.insert(params_table,
+                string.format('%s=%s', lua_util.url_encode_string(k), lua_util.url_encode_string(v)))
           end
         end
         url = string.format('%s?%s', url, table.concat(params_table, '&'))
@@ -305,7 +306,7 @@ local function rspamd_map_add_from_ucl(opt, mtype, description, callback)
 
         if string.find(opt[1], '^%d') then
           -- List of numeric stuff (hope it's ipnets definitions)
-          local map = rspamd_config:radix_from_ucl(opt)
+          local map = rspamd_config:radix_from_ucl(opt, description)
 
           if map then
             ret.__data = map
index db40d3675fb6fea22693f03dcd95a202f13ed1c8..bd17138168efd06fca14e7cedffc0dab59447b2e 100644 (file)
@@ -3116,7 +3116,7 @@ rspamd_map_add_from_ucl(struct rspamd_config *cfg,
                goto err;
        }
 
-       gboolean all_local = TRUE;
+       gboolean all_local = TRUE, all_loaded = TRUE;
 
        PTR_ARRAY_FOREACH(map->backends, i, bk)
        {
@@ -3135,9 +3135,8 @@ rspamd_map_add_from_ucl(struct rspamd_config *cfg,
                                map_data = g_string_sized_new(32);
 
                                if (rspamd_map_add_static_string(cfg, elt, map_data)) {
-                                       bk->data.sd->data = map_data->str;
                                        bk->data.sd->len = map_data->len;
-                                       g_string_free(map_data, FALSE);
+                                       bk->data.sd->data = (unsigned char *) g_string_free(map_data, FALSE);
                                }
                                else {
                                        g_string_free(map_data, TRUE);
@@ -3160,13 +3159,16 @@ rspamd_map_add_from_ucl(struct rspamd_config *cfg,
                                }
 
                                ucl_object_iterate_free(it);
-                               bk->data.sd->data = map_data->str;
                                bk->data.sd->len = map_data->len;
-                               g_string_free(map_data, FALSE);
+                               bk->data.sd->data = (unsigned char *) g_string_free(map_data, FALSE);
                        }
                }
                else if (bk->protocol != MAP_PROTO_FILE) {
                        all_local = FALSE;
+                       all_loaded = FALSE; /* Will be loaded later */
+               }
+               else {
+                       all_loaded = FALSE; /* Will be loaded later (even for files) */
                }
        }
 
@@ -3175,6 +3177,11 @@ rspamd_map_add_from_ucl(struct rspamd_config *cfg,
                                                         cfg->map_file_watch_multiplier);
        }
 
+       if (all_loaded) {
+               /* Static map */
+               g_atomic_int_set(&map->shared->loaded, 1);
+       }
+
        rspamd_map_calculate_hash(map);
        msg_debug_map("added map from ucl");
 
index 07ed58ad5c4e3ba602becd05c8772624eb61cee3..f52eae44febdc334f8295ce7a28685350a22b4a0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2024 Vsevolod Stakhov
+ * Copyright 2025 Vsevolod Stakhov
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -118,7 +118,7 @@ local function foo(task)
 end
  */
 /***
-* @method rspamd_config:radix_from_ucl(obj)
+* @method rspamd_config:radix_from_ucl(obj, description)
 * Creates new embedded map of IP/mask addresses from object.
 * @param {ucl} obj object
 * @return {map} radix tree object
index 062613bd72e224229357ede356bf58a76606123c..5f55ece06426860f7175c8c9bbb4056026bf0dc1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2024 Vsevolod Stakhov
+ * Copyright 2025 Vsevolod Stakhov
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -319,6 +319,11 @@ int lua_config_radix_from_ucl(lua_State *L)
                ucl_object_insert_key(fake_obj, ucl_object_fromstring("static"),
                                                          "url", 0, false);
 
+               if (lua_type(L, 3) == LUA_TSTRING) {
+                       ucl_object_insert_key(fake_obj, ucl_object_fromstring(lua_tostring(L, 3)),
+                                                                 "description", 0, false);
+               }
+
                if ((m = rspamd_map_add_from_ucl(cfg, fake_obj, "static radix map",
                                                                                 rspamd_radix_read,
                                                                                 rspamd_radix_fin,