From: Alan T. DeKok Date: Fri, 19 Dec 2025 07:20:19 +0000 (+0100) Subject: allow cast to 'attribute' from 'string' X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ead5ff610e4d5e4ac772feb40d2336606002bdcf;p=thirdparty%2Ffreeradius-server.git allow cast to 'attribute' from 'string' update the test framework to set the correct enumvs, and add tests --- diff --git a/src/bin/unit_test_attribute.c b/src/bin/unit_test_attribute.c index 64952dc060c..912364efc29 100644 --- a/src/bin/unit_test_attribute.c +++ b/src/bin/unit_test_attribute.c @@ -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(); } diff --git a/src/lib/util/value.c b/src/lib/util/value.c index 2f86f21b57a..0048feb801b 100644 --- a/src/lib/util/value.c +++ b/src/lib/util/value.c @@ -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) diff --git a/src/tests/unit/cast.txt b/src/tests/unit/cast.txt index 63115293469..72cb20b5b46 100644 --- a/src/tests/unit/cast.txt +++ b/src/tests/unit/cast.txt @@ -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