]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Fix static IP maps
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 24 Nov 2016 13:30:01 +0000 (13:30 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 24 Nov 2016 13:30:01 +0000 (13:30 +0000)
src/libutil/radix.c
src/lua/lua_map.c

index fcc6b1cf615dcd94617ddcf04b32f2ee7bf9c709..ebfd0319726b49da0e826067bbcaa54b0c4f57a3 100644 (file)
@@ -315,12 +315,14 @@ gboolean
 radix_add_generic_iplist (const gchar *ip_list, radix_compressed_t **tree,
                gboolean resolve)
 {
+       static const char fill_ptr[] = "1";
+
        if (*tree == NULL) {
                *tree = radix_create_compressed ();
        }
 
        return (rspamd_radix_add_iplist (ip_list, ",; ", *tree,
-                       GINT_TO_POINTER (1), resolve) > 0);
+                       fill_ptr, resolve) > 0);
 }
 
 
index 796c74e14e88d8956efa2b52f45c09fbca250ab0..1ed4aff7d02fdc458e96fefa9c31b887e58fc704 100644 (file)
@@ -158,6 +158,7 @@ lua_config_radix_from_config (lua_State *L)
        const gchar *mname, *optname;
        const ucl_object_t *obj;
        struct rspamd_lua_map *map, **pmap;
+       static const char fill_ptr[] = "1";
 
        if (!cfg) {
                return luaL_error (L, "invalid arguments");
@@ -174,8 +175,25 @@ lua_config_radix_from_config (lua_State *L)
                        map->type = RSPAMD_LUA_MAP_RADIX;
                        map->data.radix = radix_create_compressed ();
                        map->flags |= RSPAMD_LUA_MAP_FLAG_EMBEDDED;
-                       radix_add_generic_iplist (ucl_obj_tostring (obj), &map->data.radix,
-                                       TRUE);
+
+                       if (ucl_object_type (obj) == UCL_STRING) {
+                               radix_add_generic_iplist (ucl_obj_tostring (obj), &map->data.radix,
+                                               TRUE);
+                       }
+                       else {
+                               ucl_object_iter_t it = NULL;
+                               const ucl_object_t *cur;
+
+                               map->data.radix = radix_create_compressed ();
+
+                               while ((cur = ucl_object_iterate (obj, &it, true)) != NULL) {
+                                       if (ucl_object_type (cur) == UCL_STRING) {
+                                               rspamd_radix_add_iplist (ucl_object_tostring (cur),
+                                                               ",;", map->data.radix, fill_ptr, TRUE);
+                                       }
+                               }
+                       }
+
                        pmap = lua_newuserdata (L, sizeof (void *));
                        *pmap = map;
                        rspamd_lua_setclass (L, "rspamd{map}", -1);