]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
allow cast to 'attribute' from 'string'
authorAlan T. DeKok <aland@freeradius.org>
Fri, 19 Dec 2025 07:20:19 +0000 (08:20 +0100)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 19 Dec 2025 11:57:45 +0000 (12:57 +0100)
update the test framework to set the correct enumvs, and add tests

src/bin/unit_test_attribute.c
src/lib/util/value.c
src/tests/unit/cast.txt

index 64952dc060cdde59a5e75412c129e28a8a8ed7a0..912364efc29124fd889de2629ba65a073fbc1a7b 100644 (file)
@@ -1077,6 +1077,12 @@ static size_t parse_typed_value(command_result_t *result, command_file_ctx_t *cc
        fr_skip_whitespace(p);
        *out = p;
 
+       if (type == FR_TYPE_ATTR) {
+               enumv = cc->tmpl_rules.attr.dict_def ?
+                       fr_dict_root(cc->tmpl_rules.attr.dict_def) :
+                       fr_dict_root(fr_dict_internal());
+       }
+
        /*
         *      As a hack, allow most things to be inside
         *      double-quoted strings.  This is really only for dates,
@@ -1520,6 +1526,7 @@ static size_t command_cast(command_result_t *result, command_file_ctx_t *cc,
        fr_type_t type;
        char const *p, *value, *end;
        size_t slen;
+       fr_dict_attr_t const *enumv = NULL;
 
        a = talloc_zero(cc->tmp_ctx, fr_value_box_t);
 
@@ -1542,7 +1549,13 @@ static size_t command_cast(command_result_t *result, command_file_ctx_t *cc,
        if (type == FR_TYPE_MAX) RETURN_PARSE_ERROR(0);
        fr_value_box_init(out, type, NULL, false);
 
-       if (fr_value_box_cast(out, out, type, NULL, a) < 0) {
+       if (type == FR_TYPE_ATTR) {
+               enumv = cc->tmpl_rules.attr.dict_def ?
+                       fr_dict_root(cc->tmpl_rules.attr.dict_def) :
+                       fr_dict_root(fr_dict_internal());
+       }
+
+       if (fr_value_box_cast(out, out, type, enumv, a) < 0) {
                RETURN_OK_WITH_ERROR();
        }
 
index 2f86f21b57a96eb3f6918b23a4a8bd07c3336524..0048feb801b287f706e49ab6c698f66c2a4efabb 100644 (file)
@@ -3895,6 +3895,10 @@ int fr_value_box_cast(TALLOC_CTX *ctx, fr_value_box_t *dst,
                return fr_value_box_cast_in_place(ctx, dst, dst_type, dst_enumv);
 #else
        case FR_TYPE_ATTR:
+               if (src->type == FR_TYPE_STRING) break;
+
+               FALL_THROUGH;
+
 #endif
        /*
         *      Invalid types for casting (were caught earlier)
index 631152934692ecca96bf93f5c3f42d740f856aaf..72cb20b5b46907765309322e4643758e48f2de16 100644 (file)
@@ -40,5 +40,17 @@ match 691200
 cast time_delta 1.14285714w -> time_delta
 match 691199.998272
 
+#
+#  Attribute tests
+#
+proto-dictionary radius
+tmpl-rules allow_unresolved=no allow_unknown=no
+
+cast attribute ::Vendor-Specific.Cisco.AVPair -> attribute
+match ::Vendor-Specific.Cisco.AVPair
+
+cast string "::26.9.1" -> attribute
+match Vendor-Specific.Cisco.AVPair
+
 count
-match 24
+match 28