]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
ensure that the list && list_def are set correctly
authorAlan T. DeKok <aland@freeradius.org>
Mon, 8 Aug 2022 14:07:45 +0000 (10:07 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 8 Aug 2022 21:25:18 +0000 (17:25 -0400)
so that when we look at them later, they're consistent with
the attribute references in the tmpl

src/lib/server/tmpl_tokenize.c

index 143b4f545126193a3376c74c64eca9f984b8e8fd..16d7c25de8987ddf19dc20514ea320ace7b1fa02 100644 (file)
@@ -2197,7 +2197,41 @@ ssize_t tmpl_afrom_attr_substr(TALLOC_CTX *ctx, tmpl_attr_error_t *err,
                tmpl_request_ref_list_acopy(vpt, &vpt->rules.attr.request_def, t_rules->attr.request_def);
        }
 
-       if (tmpl_is_attr(vpt) && (tmpl_da(vpt)->type == tmpl_rules_cast(vpt))) vpt->rules.cast = FR_TYPE_NULL;
+       if (tmpl_is_attr(vpt)) {
+               /*
+                *      Suppress useless casts.
+                */
+               if (tmpl_da(vpt)->type == tmpl_rules_cast(vpt)) {
+                       vpt->rules.cast = FR_TYPE_NULL;
+               }
+
+               /*
+                *      Ensure that the list is set correctly, so that
+                *      the returned vpt just doesn't just match the
+                *      input rules, it is also internally consistent.
+                */
+               if (t_attr_rules->list_as_attr) {
+                       tmpl_attr_t *ar;
+
+                       ar = tmpl_attr_list_head(&vpt->data.attribute.ar);
+                       fr_assert(ar != NULL);
+
+                       if (ar->ar_da == request_attr_request) {
+                               vpt->rules.attr.list_def = PAIR_LIST_REQUEST;
+
+                       } else if (ar->ar_da == request_attr_reply) {
+                               vpt->rules.attr.list_def = PAIR_LIST_REPLY;
+
+                       } else if (ar->ar_da == request_attr_control) {
+                               vpt->rules.attr.list_def = PAIR_LIST_CONTROL;
+
+                       } else if (ar->ar_da == request_attr_state) {
+                               vpt->rules.attr.list_def = PAIR_LIST_STATE;
+                       }
+
+                       vpt->data.attribute.list = vpt->rules.attr.list_def;
+               }
+       }
 
        if (!tmpl_substr_terminal_check(&our_name, p_rules)) {
                fr_strerror_const("Unexpected text after attribute reference");