]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add taint and untaint xlats
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 2 Dec 2021 05:48:38 +0000 (23:48 -0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 2 Dec 2021 15:30:18 +0000 (09:30 -0600)
src/lib/unlang/xlat_builtin.c
src/lib/util/value.c
src/lib/util/value.h

index 3f147eaa5882e22f465b010dabb29b3ee1f102b9..cbbe740d245c1a47d45305fd5238cc02b36c0b13 100644 (file)
@@ -1196,6 +1196,32 @@ static xlat_action_t xlat_func_debug_attr(UNUSED TALLOC_CTX *ctx, UNUSED fr_dcur
        return XLAT_ACTION_DONE;
 }
 
+static xlat_action_t xlat_func_untaint(UNUSED TALLOC_CTX *ctx, fr_dcursor_t *out,
+                                      UNUSED xlat_ctx_t const *xctx,
+                                      UNUSED request_t *request, fr_value_box_list_t *in)
+{
+       fr_dcursor_t cursor_in;
+
+       fr_dcursor_init(&cursor_in, in);
+       fr_value_box_list_untaint(in);
+       fr_dcursor_merge(out, &cursor_in);
+
+       return XLAT_ACTION_DONE;
+}
+
+static xlat_action_t xlat_func_taint(UNUSED TALLOC_CTX *ctx, fr_dcursor_t *out,
+                                    UNUSED xlat_ctx_t const *xctx,
+                                    UNUSED request_t *request, fr_value_box_list_t *in)
+{
+       fr_dcursor_t cursor_in;
+
+       fr_dcursor_init(&cursor_in, in);
+       fr_value_box_list_taint(in);
+       fr_dcursor_merge(out, &cursor_in);
+
+       return XLAT_ACTION_DONE;
+}
+
 static xlat_arg_parser_t const xlat_func_explode_args[] = {
        { .required = true, .type = FR_TYPE_STRING },
        { .required = true, .concat = true, .type = FR_TYPE_STRING },
@@ -3662,6 +3688,9 @@ do { \
        XLAT_REGISTER_ARGS("sub", xlat_func_sub, xlat_func_sub_args);
        XLAT_REGISTER_ARGS("trigger", trigger_xlat, trigger_xlat_args);
 
+       xlat_register(NULL, "untaint", xlat_func_untaint, NULL);
+       xlat_register(NULL, "taint", xlat_func_taint, NULL);
+
        /*
         *      All of these functions are pure.
         */
index 0a82e1aa0f8aca79a2bcb3e963e8d19595dcad1e..6412297c298abfcac04cf93a786297dd6494e8e3 100644 (file)
@@ -5756,7 +5756,7 @@ int fr_value_box_list_acopy(TALLOC_CTX *ctx, fr_value_box_list_t *out, fr_value_
        return 0;
 }
 
-/** Check to see if any list members are tainted
+/** Check to see if any list members (or their children) are tainted
  *
  * @param[in] head     of list to check.
  * @return
@@ -5767,15 +5767,42 @@ bool fr_value_box_list_tainted(fr_value_box_list_t const *head)
 {
        fr_value_box_t *vb = NULL;
 
-       if (fr_dlist_empty(head)) return false;
-
        while ((vb = fr_dlist_next(head, vb))) {
+               if (fr_type_is_group(vb->type) && fr_value_box_list_tainted(&vb->vb_group)) return true;
                if (vb->tainted) return true;
        }
 
        return false;
 }
 
+/** Taint every list member (and their children)
+ *
+ * @param[in] head     of list.
+ */
+void fr_value_box_list_taint(fr_value_box_list_t *head)
+{
+       fr_value_box_t *vb = NULL;
+
+       while ((vb = fr_dlist_next(head, vb))) {
+               if (fr_type_is_group(vb->type)) fr_value_box_list_taint(&vb->vb_group);
+               vb->tainted = true;
+       }
+}
+
+/** Untaint every list member (and their children)
+ *
+ * @param[in] head     of list.
+ */
+void fr_value_box_list_untaint(fr_value_box_list_t *head)
+{
+       fr_value_box_t *vb = NULL;
+
+       while ((vb = fr_dlist_next(head, vb))) {
+               if (fr_type_is_group(vb->type)) fr_value_box_list_untaint(&vb->vb_group);
+               vb->tainted = false;
+       }
+}
+
 /** Validation function to check that a fr_value_box_t is correctly initialised
  *
  */
index 9d1569ef441797b6509c9d836a2360ceddbbff02..873f63dc85b6222414f0d3f57162e4689a134461 100644 (file)
@@ -846,6 +846,10 @@ char               *fr_value_box_list_aprint(TALLOC_CTX *ctx, fr_value_box_list_t const *list
 int            fr_value_box_list_acopy(TALLOC_CTX *ctx, fr_value_box_list_t *out, fr_value_box_list_t const *in);
 
 bool           fr_value_box_list_tainted(fr_value_box_list_t const *head);
+
+void           fr_value_box_list_taint(fr_value_box_list_t *head);
+
+void           fr_value_box_list_untaint(fr_value_box_list_t *head);
 /** @} */
 
 /** @name Print the value of a value box as a string