]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add tmpl_list_name() and use it to report list names
authorNick Porter <nick@portercomputing.co.uk>
Fri, 13 Jan 2023 15:47:27 +0000 (15:47 +0000)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 9 Feb 2023 16:44:59 +0000 (10:44 -0600)
12 files changed:
src/lib/ldap/map.c
src/lib/server/cf_parse.c
src/lib/server/map.c
src/lib/server/map_async.c
src/lib/server/tmpl.h
src/lib/server/tmpl_dcursor.c
src/lib/server/tmpl_eval.c
src/lib/server/tmpl_tokenize.c
src/lib/unlang/compile.c
src/lib/unlang/xlat_builtin.c
src/lib/unlang/xlat_tokenize.c
src/modules/rlm_rest/rest.c

index f4d5eda873fa2cef76fea6e34757d1178f2b7ab4..75318545921f5185ccb84aee3d4f9cffdc21cb20 100644 (file)
@@ -135,8 +135,8 @@ int fr_ldap_map_getvalue(TALLOC_CTX *ctx, fr_pair_list_t *out, request_t *reques
                        if ((tmpl_list(attr->lhs) != tmpl_list(map->lhs))) {
                                RWDEBUG("valuepair \"%pV\" has conflicting list qualifier (%s vs %s), skipping...",
                                        fr_box_strvalue_len(self->values[i]->bv_val, self->values[i]->bv_len),
-                                       fr_table_str_by_value(pair_list_table, tmpl_list(attr->lhs), "<INVALID>"),
-                                       fr_table_str_by_value(pair_list_table, tmpl_list(map->lhs), "<INVALID>"));
+                                       tmpl_list_name(tmpl_list(attr->lhs), "<INVALID>"),
+                                       tmpl_list_name(tmpl_list(map->lhs), "<INVALID>"));
                                goto next_pair;
                        }
 
index d3829eac207fa308af9fb3a48ae115ac97ebc61c..750448e225d97de00c0b8b4141bdf3beacba8880 100644 (file)
@@ -222,7 +222,6 @@ int cf_pair_parse_value(TALLOC_CTX *ctx, void *out, UNUSED void *base, CONF_ITEM
                tmpl_t                  *vpt;
                static tmpl_rules_t     rules = {
                                                .attr = {
-                                                       .list_def = PAIR_LIST_REQUEST,
                                                        .allow_unknown = true,
                                                        .allow_unresolved = true,
                                                        .allow_foreign = true
@@ -230,6 +229,7 @@ int cf_pair_parse_value(TALLOC_CTX *ctx, void *out, UNUSED void *base, CONF_ITEM
                                        };
                fr_sbuff_t              sbuff = FR_SBUFF_IN(cp->value, strlen(cp->value));
 
+               rules.attr.list_def = PAIR_LIST_REQUEST;
                /*
                 *      Parse the cast operator for barewords
                 */
index cd831828446da53edf5f88e6fd12e873f042b05b..7f909d26094ba77aa980908078c3caf5858c92d1 100644 (file)
@@ -1831,7 +1831,7 @@ int map_to_request(request_t *request, map_t const *map, radius_map_getvalue_t f
        if (!list) {
                REDEBUG("Mapping \"%.*s\" -> \"%.*s\" cannot be performed due to to invalid list qualifier \"%s\" in left side of map",
                        (int)map->rhs->len, map->rhs->name, (int)map->lhs->len, map->lhs->name,
-                       fr_table_str_by_value(pair_list_table, list_ref, "<INVALID>"));
+                       tmpl_list_name(list_ref, "<INVALID>"));
                rcode = -2;
                goto finish;
        }
index 656426dd19664ebf467f30cf81e4a5f40363926b..256a58f72554439274bb65206098f89062c27319 100644 (file)
@@ -219,7 +219,7 @@ static inline fr_pair_list_t *map_check_src_or_dst(request_t *request, map_t con
        if (!list) {
                REDEBUG("Mapping \"%.*s\" -> \"%.*s\" cannot be performed due to to invalid list qualifier \"%s\"",
                        (int)map->rhs->len, map->rhs->name, (int)map->lhs->len, map->lhs->name,
-                       fr_table_str_by_value(pair_list_table, list_ref, "<INVALID>"));
+                       tmpl_list_name(list_ref, "<INVALID>"));
                return NULL;
        }
 
index 307f0b600d19d463a19043cf4eb254ab4b3df1b9..bd83f28560ae2088da466fd82f3de98971185f26 100644 (file)
@@ -824,6 +824,14 @@ static inline tmpl_pair_list_t tmpl_list(tmpl_t const *vpt)
 }
 /** @} */
 
+/** Return the name of a tmpl list or def if list not provided
+ *
+*/
+static inline char const *tmpl_list_name(fr_dict_attr_t const *list, char const *def)
+{
+       return (list ? list->name : def);
+}
+
 /** @name Field accessors for #TMPL_TYPE_XLAT
  *
  * @{
index a7467f6386bcd2838e6e1c81c2b34d5b1729c6aa..3a9cd7fd5898e0abdffd72a59518a0a514298de6 100644 (file)
@@ -432,7 +432,7 @@ fr_pair_t *_tmpl_dcursor_init(int *err, TALLOC_CTX *ctx, tmpl_dcursor_ctx_t *cc,
                list = tmpl_get_list(request, vpt);
                if (!list) {
                        fr_strerror_printf("List \"%s\" not available in this context",
-                                          fr_table_str_by_value(pair_list_table, tmpl_list(vpt), "<INVALID>"));
+                                          tmpl_list_name(tmpl_list(vpt), "<INVALID>"));
                        if (err) *err = -2;
                        goto error;
                }
@@ -550,7 +550,7 @@ int tmpl_extents_find(TALLOC_CTX *ctx,
                list_head = tmpl_list_head(request, tmpl_list(vpt));
                if (!list_head) {
                        fr_strerror_printf("List \"%s\" not available in this context",
-                                          fr_table_str_by_value(pair_list_table, tmpl_list(vpt), "<INVALID>"));
+                                          tmpl_list_name(tmpl_list(vpt), "<INVALID>"));
                        return -2;
                }
                list_ctx = tmpl_list_ctx(request, tmpl_list(vpt));
index 58935bb73120d655fd0dc164040b949508a8b6ee..806d77b979f907a3b39ee7ab1ddbe8da72ad9958 100644 (file)
@@ -133,7 +133,7 @@ fr_pair_t *tmpl_get_list(request_t *request, tmpl_t const *vpt)
        }
 
        RWDEBUG2("List \"%s\" is not available",
-               fr_table_str_by_value(pair_list_table, list, "<INVALID>"));
+               tmpl_list_name(list, "<INVALID>"));
 
        return NULL;
 }
index 0923cd84a30c783bfce45a4d4288af81e1eb265f..5a99e3e387e442c342bd2efc7e945b022ee10f68 100644 (file)
@@ -95,11 +95,7 @@ TMPL_REQUEST_REF_DEF(tmpl_request_def_parent, REQUEST_PARENT);
  *
  * Defaults are used if a NULL rules pointer is passed to the parsing function.
  */
-static tmpl_rules_t const default_rules = {
-       .attr = {
-               .list_def = PAIR_LIST_REQUEST,
-       },
-};
+#define DEFAULT_RULES tmpl_rules_t const default_rules = { .attr = { .list_def = PAIR_LIST_REQUEST }}
 
 
 /* clang-format off */
@@ -314,7 +310,7 @@ void tmpl_attr_debug(tmpl_t const *vpt)
                i++;
        }
 
-       FR_FAULT_LOG("list: %s", fr_table_str_by_value(pair_list_table, vpt->data.attribute.list, "<INVALID>"));
+       FR_FAULT_LOG("list: %s", tmpl_list_name(vpt->data.attribute.list, "<INVALID>"));
        tmpl_attr_ref_list_debug(tmpl_attr(vpt));
 }
 
@@ -621,6 +617,7 @@ static fr_slen_t tmpl_request_ref_list_from_substr(TALLOC_CTX *ctx, tmpl_attr_er
        tmpl_request_t          *tail = tmpl_request_list_tail(out);
        unsigned int            depth = 0;
        fr_sbuff_marker_t       m;
+       DEFAULT_RULES;
 
        if (!at_rules) at_rules = &default_rules.attr;
 
@@ -2056,6 +2053,7 @@ ssize_t tmpl_afrom_attr_substr(TALLOC_CTX *ctx, tmpl_attr_error_t *err,
        bool                            is_raw = false;
        tmpl_attr_rules_t const         *at_rules;
        fr_sbuff_marker_t               m_l;
+       DEFAULT_RULES;
 
        if (!t_rules) t_rules = &default_rules;
        at_rules = &t_rules->attr;
@@ -2352,6 +2350,7 @@ ssize_t tmpl_afrom_attr_str(TALLOC_CTX *ctx, tmpl_attr_error_t *err,
                            tmpl_t **out, char const *name, tmpl_rules_t const *t_rules)
 {
        ssize_t slen, name_len;
+       DEFAULT_RULES;
 
        if (!t_rules) t_rules = &default_rules; /* Use the defaults */
 
@@ -2949,6 +2948,7 @@ fr_slen_t tmpl_afrom_substr(TALLOC_CTX *ctx, tmpl_t **out,
        char                    *str;
 
        tmpl_t                  *vpt = NULL;
+       DEFAULT_RULES;
 
        if (!t_rules) t_rules = &default_rules; /* Use the defaults */
 
@@ -4392,7 +4392,8 @@ fr_slen_t tmpl_attr_print(fr_sbuff_t *out, tmpl_t const *vpt, tmpl_attr_prefix_t
        if (tmpl_list(vpt) != PAIR_LIST_REQUEST) {      /* Don't print the default list */
                if (printed_rr) FR_SBUFF_IN_CHAR_RETURN(&our_out, '.');
 
-               FR_SBUFF_IN_TABLE_STR_RETURN(&our_out, pair_list_table, tmpl_list(vpt), "<INVALID>");
+               slen = fr_sbuff_in_strcpy(&our_out, tmpl_list_name(tmpl_list(vpt), "<INVALID>"));
+               if (slen < 0) return slen;
                if (tmpl_attr_list_num_elements(tmpl_attr(vpt))) FR_SBUFF_IN_CHAR_RETURN(&our_out, '.');
 
        /*
@@ -4996,8 +4997,9 @@ void tmpl_verify(char const *file, int line, tmpl_t const *vpt)
 
                        if (!vpt->rules.attr.list_as_attr && ((tmpl_list(vpt) == PAIR_LIST_UNKNOWN) || tmpl_list(vpt) > PAIR_LIST_STATE)) {
                                fr_fatal_assert_fail("CONSISTENCY CHECK FAILED %s[%u]: TMPL_TYPE_ATTR "
-                                                    "attribute \"%s\" has invalid list (%i)",
-                                                    file, line, tmpl_attr_tail_da(vpt)->name, tmpl_list(vpt));
+                                                    "attribute \"%s\" has invalid list (%s)",
+                                                    file, line, tmpl_attr_tail_da(vpt)->name,
+                                                    tmpl_list_name(tmpl_list(vpt), "<INVALID>"));
                        }
 
                        tmpl_attr_verify(file, line, vpt);
index a9377a6bf529e2b4a794b06f66a79886dccace39..29ba1b48346cf1e1c4e3c7eeaf0fd41d411ea165 100644 (file)
@@ -1365,7 +1365,7 @@ static unlang_t *compile_update_to_edit(unlang_t *parent, unlang_compile_t *unla
        if (name2) {
                snprintf(list_buffer, sizeof(list_buffer), "&%s", name2);
        } else {
-               snprintf(list_buffer, sizeof(list_buffer), "&%s", fr_table_str_by_value(pair_list_table, unlang_ctx->rules->attr.list_def, "<INVALID>"));
+               snprintf(list_buffer, sizeof(list_buffer), "&%s", tmpl_list_name(unlang_ctx->rules->attr.list_def, "<INVALID>"));
        }
 
        /*
index 86f68218f6a446acbcf10c4db3229863249e2c9d..f59dcb5d247ddf10a88842e95db870f9a58a090c 100644 (file)
@@ -1015,7 +1015,7 @@ void xlat_debug_attr_vp(request_t *request, fr_pair_t *vp, tmpl_t const *vpt)
        case FR_TYPE_STRUCTURAL:
                if (vpt) {
                        RIDEBUG2("&%s.%s = {",
-                                fr_table_str_by_value(pair_list_table, tmpl_list(vpt), "<INVALID>"),
+                                tmpl_list_name(tmpl_list(vpt), "<INVALID>"),
                                 vp->da->name);
                } else {
                        RIDEBUG2("%s = {", vp->da->name);
@@ -1029,7 +1029,7 @@ void xlat_debug_attr_vp(request_t *request, fr_pair_t *vp, tmpl_t const *vpt)
        default:
                if (vpt) {
                        RIDEBUG2("&%s.%s = %pV",
-                                fr_table_str_by_value(pair_list_table, tmpl_list(vpt), "<INVALID>"),
+                                tmpl_list_name(tmpl_list(vpt), "<INVALID>"),
                                 vp->da->name,
                                 &vp->data);
                } else {
index b106deab09c75465e6065a84f9a2925b748a145f..0c2604a0d85dae7cc0b93b76d8ec70afa617d64e 100644 (file)
@@ -1122,7 +1122,7 @@ static void _xlat_debug(xlat_exp_head_t const *head, int depth)
                                        while ((rr = tmpl_request_list_next(list, rr))) {
                                                INFO_INDENT("ref  %d", rr->request);
                                        }
-                                       INFO_INDENT("list %d", tmpl_list(node->vpt));
+                                       INFO_INDENT("list %s", tmpl_list_name(tmpl_list(node->vpt), "<INVALID>"));
                                        if (tmpl_attr_tail_num(node->vpt) != NUM_UNSPEC) {
                                                if (tmpl_attr_tail_num(node->vpt) == NUM_COUNT) {
                                                        INFO_INDENT("[#]");
index 5e725d19378b07c9e8d1360e3b0816f3a1617504..d038f0bbe9db4568d5e77a9fec1499e6cd42b08c 100644 (file)
@@ -1161,7 +1161,7 @@ static int json_pair_alloc(rlm_rest_t const *instance, rlm_rest_section_t const
                                        if (!vp) continue;
                                }
                                RINDENT();
-                               RDEBUG2("&%s:%pP", fr_table_str_by_value(pair_list_table, tmpl_list(dst), ""), vp);
+                               RDEBUG2("&%s:%pP", tmpl_list_name(tmpl_list(dst), ""), vp);
                                REXDENT();
 
                                fr_pair_list_init(&tmp_list);