]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Use tmpl_attr_list_from_substr() to parse list names
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 9 Feb 2023 16:45:54 +0000 (10:45 -0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 9 Feb 2023 16:45:54 +0000 (10:45 -0600)
src/bin/unit_test_attribute.c
src/lib/server/map.c
src/lib/server/tmpl_tokenize.c
src/lib/unlang/compile.c

index 762d03d9c36c76ecd5bf9fdaddf1406a3a8eb8d3..ae50e5ff86e10a4cae778910b2d45257dc9ce212 100644 (file)
@@ -2619,13 +2619,13 @@ static ssize_t command_tmpl_rule_list_def(UNUSED TALLOC_CTX *ctx, tmpl_rules_t *
 {
        ssize_t slen;
 
-       fr_sbuff_out_by_longest_prefix(&slen, &rules->attr.list_def, pair_list_table, value, PAIR_LIST_UNKNOWN);
+       slen = tmpl_attr_list_from_substr(&rules->attr.list_def, value);
 
-       if (rules->attr.list_def == PAIR_LIST_UNKNOWN) {
+       if (slen == 0) {
                fr_strerror_printf("Invalid list specifier \"%pV\"",
                                   fr_box_strvalue_len(fr_sbuff_current(value), fr_sbuff_remaining(value)));
        }
-       
+
        return slen;
 }
 
index 7f909d26094ba77aa980908078c3caf5858c92d1..fe3c0b79edb4f5381ebb57ace6d8e9d65c16e8de 100644 (file)
@@ -758,8 +758,8 @@ static int _map_afrom_cs(TALLOC_CTX *ctx, map_list_t *out, map_t *parent, CONF_S
                }
                p += slen;
 
-               our_lhs_rules.attr.list_def = fr_table_value_by_str(pair_list_table, p, PAIR_LIST_UNKNOWN);
-               if (our_lhs_rules.attr.list_def == PAIR_LIST_UNKNOWN) {
+               slen = tmpl_attr_list_from_substr(&our_lhs_rules.attr.list_def, &FR_SBUFF_IN(p, strlen(p)));
+               if (slen == 0) {
                        cf_log_err(ci, "Default list \"%s\" specified in mapping section is invalid", p);
                        talloc_free(tmp_ctx);
                        return -1;
index 89e1c91d793b85ae8a922f5678ff2a85df2fd0ca..cc9775b21995fe0a546e06ce18193d2ddd04cad6 100644 (file)
@@ -443,6 +443,7 @@ size_t tmpl_pair_list_name(tmpl_pair_list_t *out, char const *name, tmpl_pair_li
 {
        char const *p = name;
        char const *q;
+       size_t ret = 0;
 
        /*
         *      Try and determine the end of the token
@@ -457,8 +458,8 @@ size_t tmpl_pair_list_name(tmpl_pair_list_t *out, char const *name, tmpl_pair_li
         *      anything.
         */
        case '\0':
-               *out = fr_table_value_by_substr(pair_list_table, p, (q - p), PAIR_LIST_UNKNOWN);
-               if (*out != PAIR_LIST_UNKNOWN) return q - p;
+               ret = tmpl_attr_list_from_substr(out, &FR_SBUFF_IN(p, (q - p)));
+               if (ret > 0) return ret;
                *out = def;
                return 0;
 
@@ -478,8 +479,8 @@ size_t tmpl_pair_list_name(tmpl_pair_list_t *out, char const *name, tmpl_pair_li
                        }
                }
 
-               *out = fr_table_value_by_substr(pair_list_table, p, (q - p), PAIR_LIST_UNKNOWN);
-               if (*out == PAIR_LIST_UNKNOWN) return 0;
+               ret = tmpl_attr_list_from_substr(out, &FR_SBUFF_IN(p, (q - p)));
+               if (ret == 0) return 0;
 
                return (q + 1) - name; /* Consume the list and delimiter */
        }
@@ -2119,8 +2120,8 @@ ssize_t tmpl_afrom_attr_substr(TALLOC_CTX *ctx, tmpl_attr_error_t *err,
                 *      This code should be removed when lists
                 *      are integrated into attribute references.
                 */
-               fr_sbuff_out_by_longest_prefix(&list_len, &vpt->data.attribute.list, pair_list_table,
-                                              &our_name, at_rules->list_def);
+               list_len = tmpl_attr_list_from_substr(&vpt->data.attribute.list, &our_name);
+               if (list_len == 0) vpt->data.attribute.list = at_rules->list_def;
 
                /*
                 *      Check if we need to backtrack
index 29ba1b48346cf1e1c4e3c7eeaf0fd41d411ea165..9505b8ec424a127c7884891666a087fd68ad7b1d 100644 (file)
@@ -1405,6 +1405,7 @@ static unlang_t *compile_update_to_edit(unlang_t *parent, unlang_compile_t *unla
                 */
                {
                        char const *p, *q;
+                       fr_dict_attr_t const *tmpl_list;
 
                        p = attr;
 
@@ -1430,7 +1431,7 @@ static unlang_t *compile_update_to_edit(unlang_t *parent, unlang_compile_t *unla
                         *
                         *      @todo - add support for &config?
                         */
-                       if (fr_table_value_by_substr(pair_list_table, p, q - p, PAIR_LIST_UNKNOWN) != PAIR_LIST_UNKNOWN) {
+                       if (tmpl_attr_list_from_substr(&tmpl_list, &FR_SBUFF_IN(p, (q - p))) > 0) {
                                if (*q) {
                                        p = q + 1;
                                } else {