From: Alan T. DeKok Date: Tue, 20 Feb 2024 14:55:02 +0000 (-0500) Subject: add <<= and >>= along with tests X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6972833b7d2668b1cd2be92d76a4bb9f51eb684b;p=thirdparty%2Ffreeradius-server.git add <<= and >>= along with tests the underlying calc.c code supported it, but it wasn't exposed (or tested) through unlang --- diff --git a/src/lib/server/cf_file.c b/src/lib/server/cf_file.c index 254acbec35f..51d54f65af2 100644 --- a/src/lib/server/cf_file.c +++ b/src/lib/server/cf_file.c @@ -2418,10 +2418,10 @@ check_for_eol: case T_OP_AND_EQ: case T_OP_OR_EQ: case T_OP_NE: - case T_RSHIFT: + case T_OP_RSHIFT_EQ: case T_OP_GE: case T_OP_GT: - case T_LSHIFT: + case T_OP_LSHIFT_EQ: case T_OP_LE: case T_OP_LT: case T_OP_CMP_EQ: diff --git a/src/lib/server/map.c b/src/lib/server/map.c index 531ecad8512..bcf451c5a9c 100644 --- a/src/lib/server/map.c +++ b/src/lib/server/map.c @@ -197,7 +197,11 @@ int map_afrom_cp(TALLOC_CTX *ctx, map_t **out, map_t *parent, CONF_PAIR *cp, } rhs_rules = &my_rhs_rules; - if (edit) my_rhs_rules.enumv = tmpl_attr_tail_da(map->lhs); + if (edit) { + if ((map->op != T_OP_RSHIFT_EQ) && (map->op != T_OP_LSHIFT_EQ)) { + my_rhs_rules.enumv = tmpl_attr_tail_da(map->lhs); + } + } break; } @@ -293,9 +297,17 @@ int map_afrom_cp(TALLOC_CTX *ctx, map_t **out, map_t *parent, CONF_PAIR *cp, * If we know that the assignment is forbidden, then fail early. */ if (tmpl_is_attr(map->lhs) && tmpl_is_data(map->rhs)) { - da = tmpl_attr_tail_da(map->lhs); + fr_type_t cast_type; + + if ((map->op != T_OP_RSHIFT_EQ) && (map->op != T_OP_LSHIFT_EQ)) { + da = tmpl_attr_tail_da(map->lhs); + cast_type = da->type; + } else { + da = NULL; + cast_type = FR_TYPE_UINT32; + } - if (tmpl_cast_in_place(map->rhs, da->type, da) < 0) { + if (tmpl_cast_in_place(map->rhs, cast_type, da) < 0) { cf_log_err(cp, "Invalid assignment - %s", fr_strerror()); goto error; } diff --git a/src/lib/util/token.c b/src/lib/util/token.c index fb58cb9b0e6..c7fa61e9893 100644 --- a/src/lib/util/token.c +++ b/src/lib/util/token.c @@ -52,10 +52,10 @@ fr_table_num_ordered_t const fr_tokens_table[] = { { L("="), T_OP_EQ }, { L("!="), T_OP_NE }, { L("!=="), T_OP_CMP_NE_TYPE }, - { L(">>="), T_RSHIFT }, + { L(">>="), T_OP_RSHIFT_EQ }, { L(">="), T_OP_GE }, { L(">"), T_OP_GT }, - { L("<<="), T_LSHIFT }, + { L("<<="), T_OP_LSHIFT_EQ }, { L("<="), T_OP_LE }, { L("<"), T_OP_LT }, { L("#"), T_HASH }, diff --git a/src/tests/keywords/edit-shift b/src/tests/keywords/edit-shift new file mode 100644 index 00000000000..926b450b846 --- /dev/null +++ b/src/tests/keywords/edit-shift @@ -0,0 +1,23 @@ +octets foo + +# +# left shift octets +# +&foo := 0xabcdef +&foo <<= 2 + +if (&foo != 0xef) { + test_fail +} + +# +# And right shift +# +&foo := 0xabcdef + + +&foo >>= 2 +if (&foo != 0xab) { + test_fail +} +success