]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
updates for new parsing
authorAlan T. DeKok <aland@freeradius.org>
Sun, 26 Jan 2025 16:38:00 +0000 (11:38 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Sun, 26 Jan 2025 16:38:00 +0000 (11:38 -0500)
map_afrom_cp() now requires that the RHS of !* and =* are ANY,
as with map_afrom_fields()

update the keyword tests to use quoted strings or ::NAME in more
places, which helps with migration away from &

src/lib/server/map.c
src/tests/keywords/map
src/tests/keywords/pap-ssha2

index 80349503b5d0f60d4d09c65bf91d5bff4894c821..d592280d06a6b55510fc8e630bc1c8f31705af78 100644 (file)
@@ -116,7 +116,7 @@ int map_afrom_cp(TALLOC_CTX *ctx, map_t **out, map_t *parent, CONF_PAIR *cp,
        char            *unescaped_value = NULL;
        fr_sbuff_parse_rules_t const *p_rules;
        ssize_t         slen;
-       fr_token_t      type;
+       fr_token_t      quote;
        fr_dict_attr_t const *da;
        tmpl_rules_t    my_rhs_rules = {};
        tmpl_rules_t const *rhs_rules = input_rhs_rules;
@@ -148,14 +148,14 @@ int map_afrom_cp(TALLOC_CTX *ctx, map_t **out, map_t *parent, CONF_PAIR *cp,
         *      LHS may be an expansion (that expands to an attribute reference)
         *      or an attribute reference. Quoting determines which it is.
         */
-       type = cf_pair_attr_quote(cp);
-       switch (type) {
+       quote = cf_pair_attr_quote(cp);
+       switch (quote) {
        case T_DOUBLE_QUOTED_STRING:
        case T_BACK_QUOTED_STRING:
                slen = tmpl_afrom_substr(ctx, &map->lhs,
                                         &FR_SBUFF_IN(attr, talloc_array_length(attr) - 1),
-                                        type,
-                                        value_parse_rules_unquoted[type],      /* We're not searching for quotes */
+                                        quote,
+                                        value_parse_rules_unquoted[quote],     /* We're not searching for quotes */
                                         lhs_rules);
                if (slen <= 0) {
                        char *spaces, *text;
@@ -222,9 +222,9 @@ int map_afrom_cp(TALLOC_CTX *ctx, map_t **out, map_t *parent, CONF_PAIR *cp,
        /*
         *      RHS might be an attribute reference.
         */
-       type = cf_pair_value_quote(cp);
-       p_rules = value_parse_rules_unquoted[type]; /* We're not searching for quotes */
-       if (type == T_DOUBLE_QUOTED_STRING || type == T_BACK_QUOTED_STRING) {
+       quote = cf_pair_value_quote(cp);
+       p_rules = value_parse_rules_unquoted[quote]; /* We're not searching for quotes */
+       if (quote == T_DOUBLE_QUOTED_STRING || quote == T_BACK_QUOTED_STRING) {
                slen = fr_sbuff_out_aunescape_until(child_ctx, &unescaped_value,
                                &FR_SBUFF_IN(value, talloc_array_length(value) - 1), SIZE_MAX, p_rules->terminals, p_rules->escapes);
                if (slen < 0) {
@@ -234,7 +234,7 @@ int map_afrom_cp(TALLOC_CTX *ctx, map_t **out, map_t *parent, CONF_PAIR *cp,
                value = unescaped_value;
                p_rules = NULL;
 
-       } else if (edit && (type == T_HASH)) {
+       } else if (edit && (quote == T_HASH)) {
                fr_slen_t slent;
                xlat_exp_head_t *head;
 
@@ -261,6 +261,18 @@ int map_afrom_cp(TALLOC_CTX *ctx, map_t **out, map_t *parent, CONF_PAIR *cp,
                tmpl_set_xlat(map->rhs, head);
                goto verify;
 
+       } else if ((map->op == T_OP_CMP_TRUE) || (map->op == T_OP_CMP_FALSE)) {
+               /*
+                *      These operators require a hard-coded string on the RHS.
+                */
+               if (strcmp(value, "ANY") != 0) {
+                       fr_strerror_printf("Invalid value for %s", fr_tokens[map->op]);
+                       goto error;
+               }
+
+               (void) tmpl_afrom_value_box(map, &map->rhs, fr_box_strvalue("ANY"), false);
+               goto verify;
+
        } else {
                slen = talloc_array_length(value) - 1;
        }
@@ -272,13 +284,13 @@ int map_afrom_cp(TALLOC_CTX *ctx, map_t **out, map_t *parent, CONF_PAIR *cp,
         *      pairs, and work on that.
         */
        if (edit && (rhs_rules == &my_rhs_rules) && my_rhs_rules.enumv && fr_type_is_structural(my_rhs_rules.enumv->type) &&
-           ((type == T_DOUBLE_QUOTED_STRING) || (type == T_BACK_QUOTED_STRING) || (type == T_SINGLE_QUOTED_STRING))) {
+           ((quote == T_DOUBLE_QUOTED_STRING) || (quote == T_BACK_QUOTED_STRING) || (quote == T_SINGLE_QUOTED_STRING))) {
                my_rhs_rules.enumv = NULL;
        }
 
        slen = tmpl_afrom_substr(map, &map->rhs,
                                 &FR_SBUFF_IN(value, slen),
-                                type,
+                                quote,
                                 p_rules,
                                 rhs_rules);
        if (slen < 0) {
index 6d90e35edd5a747b2d16c998ea07226973091eb8..4b0c464af44eafb1d8acd7c72b65bd408b40b46e 100644 (file)
@@ -3,8 +3,8 @@ string CSV-Result
 #
 #  PRE: map-2arg-error map-empty-error map-module-error map-field-error
 #
-map csv User-Name {
-       CSV-Result := field3
+map csv &User-Name {
+       CSV-Result := 'field3'
 }
 
 if (!(CSV-Result == "success")) {
index b955a6db3119a99b8913e63e621c83bb36bdbb96..38330a2233592b073f43b52ef56fec353b67f07e 100644 (file)
@@ -13,7 +13,7 @@ octets result_octets
 #  Skip if the server wasn't built with openssl
 #
 if (!('${feature.tls}' == 'yes')) {
-       reply.Packet-Type := Access-Accept
+       reply.Packet-Type := ::Access-Accept
        handled
 }