From: Alan T. DeKok Date: Sat, 31 Aug 2024 14:08:53 +0000 (-0400) Subject: clean up uses of "set leaf num" X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=84cbd8532086d1138ab9319891f9d6f70333dcd9;p=thirdparty%2Ffreeradius-server.git clean up uses of "set leaf num" in most cases it's not necessary. We instead initialize the ar filter to NONE. In other cases (now that we may have multiple kinds of filters), we check that we're only setting the num for FILTER_INDEX. and if we're clearing the num by setting it to NUM_UNSPEC, we also set the filter to FILTER_NONE Much of the code in the server assumed that it could always look at ar->ar_num. It would therefore behave "surprisingly" when other filters are used. --- diff --git a/src/lib/server/map.c b/src/lib/server/map.c index 7842d6b9dc..7d9c49a868 100644 --- a/src/lib/server/map.c +++ b/src/lib/server/map.c @@ -1368,7 +1368,6 @@ int map_afrom_vp(TALLOC_CTX *ctx, map_t **out, fr_pair_t *vp, tmpl_rules_t const if (!map->lhs) goto oom; tmpl_attr_set_leaf_da(map->lhs, vp->da); - tmpl_attr_set_leaf_num(map->lhs, NUM_UNSPEC); tmpl_attr_set_request_ref(map->lhs, rules->attr.request_def); tmpl_attr_set_list(map->lhs, rules->attr.list_def); diff --git a/src/lib/server/tmpl_tokenize.c b/src/lib/server/tmpl_tokenize.c index f2e50862b3..4caa53abaf 100644 --- a/src/lib/server/tmpl_tokenize.c +++ b/src/lib/server/tmpl_tokenize.c @@ -983,6 +983,7 @@ static tmpl_attr_t *tmpl_attr_add(tmpl_t *vpt, tmpl_attr_type_t type) *ar = (tmpl_attr_t){ .type = type, .filter = { + .type = TMPL_ATTR_FILTER_TYPE_NONE, .num = NUM_UNSPEC } }; @@ -1163,28 +1164,17 @@ int tmpl_attr_set_leaf_da(tmpl_t *vpt, fr_dict_attr_t const *da) */ ref->ar_parent = fr_dict_root(fr_dict_by_da(da)); /* Parent is the root of the dictionary */ + /* + * Set the filter type to none. + */ + ref->ar_filter_type = TMPL_ATTR_FILTER_TYPE_NONE; + ref->ar_num = NUM_UNSPEC; + TMPL_ATTR_VERIFY(vpt); return 0; } -void tmpl_attr_set_leaf_num(tmpl_t *vpt, int16_t num) -{ - tmpl_attr_t *ar; - - tmpl_assert_type(tmpl_is_attr(vpt) || tmpl_is_attr_unresolved(vpt)); - - if (tmpl_attr_list_num_elements(tmpl_attr(vpt)) == 0) { - ar = tmpl_attr_add(vpt, TMPL_ATTR_TYPE_UNKNOWN); - } else { - ar = tmpl_attr_list_tail(tmpl_attr(vpt)); - } - - ar->ar_num = num; - - TMPL_ATTR_VERIFY(vpt); -} - /** Rewrite the leaf's instance number * */ @@ -1268,7 +1258,6 @@ int tmpl_attr_afrom_list(TALLOC_CTX *ctx, tmpl_t **out, tmpl_t const *list, fr_d ar = tmpl_attr_add(vpt, TMPL_ATTR_TYPE_NORMAL); ar->ar_da = da; ar->ar_parent = fr_dict_root(fr_dict_by_da(da)); - tmpl_attr_set_leaf_num(vpt, tmpl_attr_tail_num(list)); /* * We need to rebuild the attribute name, to be the