From: Arran Cudbard-Bell Date: Thu, 9 Feb 2023 16:45:54 +0000 (-0600) Subject: Use tmpl_attr_list_from_substr() to parse list names X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=94b020eeab14491a274edbc960a1af384569ed11;p=thirdparty%2Ffreeradius-server.git Use tmpl_attr_list_from_substr() to parse list names --- diff --git a/src/bin/unit_test_attribute.c b/src/bin/unit_test_attribute.c index 762d03d9c36..ae50e5ff86e 100644 --- a/src/bin/unit_test_attribute.c +++ b/src/bin/unit_test_attribute.c @@ -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; } diff --git a/src/lib/server/map.c b/src/lib/server/map.c index 7f909d26094..fe3c0b79edb 100644 --- a/src/lib/server/map.c +++ b/src/lib/server/map.c @@ -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; diff --git a/src/lib/server/tmpl_tokenize.c b/src/lib/server/tmpl_tokenize.c index 89e1c91d793..cc9775b2199 100644 --- a/src/lib/server/tmpl_tokenize.c +++ b/src/lib/server/tmpl_tokenize.c @@ -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 diff --git a/src/lib/unlang/compile.c b/src/lib/unlang/compile.c index 29ba1b48346..9505b8ec424 100644 --- a/src/lib/unlang/compile.c +++ b/src/lib/unlang/compile.c @@ -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 {