]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Fix the case of multiple values keys
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 25 Jun 2016 12:43:21 +0000 (13:43 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 25 Jun 2016 12:43:21 +0000 (13:43 +0100)
src/libserver/cfg_utils.c

index 299a852aa6c9cfdef74b3830641735b93529bc2f..34029664b292dee6bf40c35a0608a15c9611e675 100644 (file)
@@ -1653,69 +1653,72 @@ rspamd_config_radix_from_ucl (struct rspamd_config *cfg,
 {
        ucl_type_t type;
        ucl_object_iter_t it = NULL;
-       const ucl_object_t *cur;
+       const ucl_object_t *cur, *cur_elt;
        const gchar *str;
 
-       type = ucl_object_type (obj);
-
-       switch (type) {
-       case UCL_STRING:
-               /* Either map or a list of IPs */
-               str = ucl_object_tostring (obj);
-
-               if (rspamd_map_is_map (str)) {
-                       if (rspamd_map_add_from_ucl (cfg, cfg->local_addrs,
+       LL_FOREACH (obj, cur_elt) {
+               type = ucl_object_type (cur_elt);
+
+               switch (type) {
+               case UCL_STRING:
+                       /* Either map or a list of IPs */
+                       str = ucl_object_tostring (cur_elt);
+
+                       if (rspamd_map_is_map (str)) {
+                               if (rspamd_map_add_from_ucl (cfg, cur_elt,
+                                               description, rspamd_radix_read, rspamd_radix_fin,
+                                               (void **)target) == NULL) {
+                                       g_set_error (err, g_quark_from_static_string ("rspamd-config"),
+                                                       EINVAL, "bad map definition %s for %s", str,
+                                                       ucl_object_key (obj));
+                                       return FALSE;
+                               }
+                       }
+                       else {
+                               /* Just a list */
+                               if (!radix_add_generic_iplist (str, target)) {
+                                       g_set_error (err, g_quark_from_static_string ("rspamd-config"),
+                                                       EINVAL, "bad map definition %s for %s", str,
+                                                       ucl_object_key (obj));
+                                       return FALSE;
+                               }
+                       }
+                       break;
+               case UCL_OBJECT:
+                       /* Should be a map description */
+                       if (rspamd_map_add_from_ucl (cfg, cur_elt,
                                        description, rspamd_radix_read, rspamd_radix_fin,
                                        (void **)target) == NULL) {
                                g_set_error (err, g_quark_from_static_string ("rspamd-config"),
-                                               EINVAL, "bad map definition %s for %s", str,
-                                               ucl_object_key (obj));
-                               return FALSE;
-                       }
-               }
-               else {
-                       /* Just a list */
-                       if (!radix_add_generic_iplist (str, target)) {
-                               g_set_error (err, g_quark_from_static_string ("rspamd-config"),
-                                               EINVAL, "bad map definition %s for %s", str,
-                                               ucl_object_key (obj));
+                                               EINVAL, "bad map object for %s", ucl_object_key (obj));
                                return FALSE;
                        }
-               }
-               break;
-       case UCL_OBJECT:
-               /* Should be a map description */
-               if (rspamd_map_add_from_ucl (cfg, cfg->local_addrs,
-                               description, rspamd_radix_read, rspamd_radix_fin,
-                               (void **)target) == NULL) {
-                       g_set_error (err, g_quark_from_static_string ("rspamd-config"),
-                                       EINVAL, "bad map object for %s", ucl_object_key (obj));
-                       return FALSE;
-               }
-               break;
-       case UCL_ARRAY:
-               /* List of IP addresses */
-               while ((cur = ucl_iterate_object (obj, &it, true)) != NULL) {
-                       str = ucl_object_tostring (cur);
-
-                       if (str == NULL || !radix_add_generic_iplist (str, target)) {
-                               g_set_error (err, g_quark_from_static_string ("rspamd-config"),
-                                               EINVAL, "bad map element %s for %s", str,
-                                               ucl_object_key (obj));
+                       break;
+               case UCL_ARRAY:
+                       /* List of IP addresses */
+                       while ((cur = ucl_iterate_object (cur_elt, &it, true)) != NULL) {
+                               str = ucl_object_tostring (cur);
+
+                               if (str == NULL || !radix_add_generic_iplist (str, target)) {
+                                       g_set_error (err, g_quark_from_static_string ("rspamd-config"),
+                                                       EINVAL, "bad map element %s for %s", str,
+                                                       ucl_object_key (obj));
+
+                                       if (*target) {
+                                               radix_destroy_compressed (*target);
+                                       }
 
-                               if (*target) {
-                                       radix_destroy_compressed (*target);
+                                       return FALSE;
                                }
-
-                               return FALSE;
                        }
+                       break;
+               default:
+                       g_set_error (err, g_quark_from_static_string ("rspamd-config"),
+                                       EINVAL, "bad map type %s for %s",
+                                       ucl_object_type_to_string (type),
+                                       ucl_object_key (obj));
+                       return FALSE;
                }
-               break;
-       default:
-               g_set_error (err, g_quark_from_static_string ("rspamd-config"),
-                               EINVAL, "bad map type %s for %s", ucl_object_type_to_string (type),
-                               ucl_object_key (obj));
-               return FALSE;
        }
 
        return TRUE;