From: Alan T. DeKok Date: Sat, 11 Dec 2021 14:44:05 +0000 (-0500) Subject: update parser to cast RHS as string for structural types X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7db914a2ef5de90b6e6bb5bf88f2c85bba1acbd8;p=thirdparty%2Ffreeradius-server.git update parser to cast RHS as string for structural types --- diff --git a/src/lib/unlang/compile.c b/src/lib/unlang/compile.c index 17741a119a..e41aa96d9c 100644 --- a/src/lib/unlang/compile.c +++ b/src/lib/unlang/compile.c @@ -1011,12 +1011,21 @@ int unlang_fixup_update(map_t *map, UNUSED void *ctx) * Unless it's a unary operator in which case we * ignore map->rhs. */ - if (tmpl_is_attr(map->lhs)) { + if (tmpl_is_attr(map->lhs) && tmpl_is_unresolved(map->rhs)) { + fr_type_t type = tmpl_da(map->lhs)->type; + + /* + * @todo - allow passing octets to + * FR_TYPE_STRUCT, which can then decode them as + * data? That would be rather powerful. + */ + if (fr_type_is_structural(type)) type = FR_TYPE_STRING; + /* * It's a literal string, just copy it. * Don't escape anything. */ - if (tmpl_cast_in_place(map->rhs, tmpl_da(map->lhs)->type, tmpl_da(map->lhs)) < 0) { + if (tmpl_cast_in_place(map->rhs, type, tmpl_da(map->lhs)) < 0) { cf_log_perr(map->ci, "Cannot convert RHS value (%s) to LHS attribute type (%s)", fr_table_str_by_value(fr_value_box_type_table, FR_TYPE_STRING, ""), fr_table_str_by_value(fr_value_box_type_table, tmpl_da(map->lhs)->type, "")); @@ -1130,11 +1139,20 @@ static int unlang_fixup_filter(map_t *map, UNUSED void *ctx) * ignore map->rhs. */ if (tmpl_is_attr(map->lhs) && tmpl_is_unresolved(map->rhs)) { + fr_type_t type = tmpl_da(map->lhs)->type; + + /* + * @todo - allow passing octets to + * FR_TYPE_STRUCT, which can then decode them as + * data? That would be rather powerful. + */ + if (fr_type_is_structural(type)) type = FR_TYPE_STRING; + /* * It's a literal string, just copy it. * Don't escape anything. */ - if (tmpl_cast_in_place(map->rhs, tmpl_da(map->lhs)->type, tmpl_da(map->lhs)) < 0) { + if (tmpl_cast_in_place(map->rhs, type, tmpl_da(map->lhs)) < 0) { cf_log_perr(map->ci, "Cannot convert RHS value (%s) to LHS attribute type (%s)", fr_table_str_by_value(fr_value_box_type_table, FR_TYPE_STRING, ""), fr_table_str_by_value(fr_value_box_type_table, tmpl_da(map->lhs)->type, ""));