]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add enums, too
authorAlan T. DeKok <aland@freeradius.org>
Mon, 20 Sep 2021 15:43:21 +0000 (11:43 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 20 Sep 2021 15:43:21 +0000 (11:43 -0400)
src/lib/util/dict_fixup.c
src/tests/unit/protocols/radius/enum.txt

index b69fe896d3305e67f952430d3899b13edbf9e60e..eef6db26ac3c37e597e0f3ef6a7fad85b61f30f9 100644 (file)
@@ -450,15 +450,18 @@ static inline CC_HINT(always_inline) int dict_fixup_clone_apply(UNUSED dict_fixu
        }
 
        /*
-        *      We can only clone attributes of the same data type.
-        *
-        *      @todo - for ENUMs, we have to _manually_ clone the
-        *      values if the types are different.  This means looping
+        *      If the attributes are of different types, then we have
+        *      to _manually_ clone the values.  This means looping
         *      over the ref da, and _casting_ the values to the new
         *      data type.  If the cast succeeds, we add the value.
-        *      Otherwise we don't.
+        *      Otherwise we don't
+        *
+        *      We do this if the source type is a leaf node, AND the
+        *      types are different, or the destination has no
+        *      children.
         */
-       if (da->type != fixup->da->type) {
+       if (!fr_type_is_non_leaf(fixup->da->type) &&
+           ((da->type != fixup->da->type) || !dict_attr_children(da))) {
                int copied;
 
                /*
@@ -502,6 +505,14 @@ static inline CC_HINT(always_inline) int dict_fixup_clone_apply(UNUSED dict_fixu
                return 0;
        }
 
+       /*
+        *      Can't clone KEY fields directly, you MUST clone the parent struct.
+        */
+       if (!fr_type_is_non_leaf(da->type) || fr_dict_attr_is_key_field(da) || fr_dict_attr_is_key_field(fixup->da)) {
+               fr_strerror_printf("Invalid reference from '%s' to %s", fixup->ref, da->name);
+               return -1;
+       }
+
        /*
         *      Copy the source attribute, but with a
         *      new name and a new attribute number.
index 96073164d08e152b82116bb41e2ffddcb377e962..4aafb56b67387a37301cb661cb194313d7578fdd 100644 (file)
@@ -14,7 +14,7 @@ match fe 0c 0c 0a 00 00 00 00 00 00 00 01
 #  @todo - find out why this isn't an enum lookup :(
 #
 decode-pair -
-match Unit-TLV = { Test-Enum-Integer64 = 1 }
+match Unit-TLV = { Test-Enum-Integer64 = one }
 
 #
 #  Same enum names, different attribute.