]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
clean up uses of "set leaf num"
authorAlan T. DeKok <aland@freeradius.org>
Sat, 31 Aug 2024 14:08:53 +0000 (10:08 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Sat, 31 Aug 2024 14:08:53 +0000 (10:08 -0400)
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.

src/lib/server/map.c
src/lib/server/tmpl_tokenize.c

index 7842d6b9dca390b35ba430c2fdb89466d56c26e5..7d9c49a868a34a5de1cfd267e1bfecc533d1f3ba 100644 (file)
@@ -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);
index f2e50862b366dfd98b905ac8f82bc8afbd044331..4caa53abafb065a2550bf3e825396c527c28da23 100644 (file)
@@ -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