]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add := test
authorAlan T. DeKok <aland@freeradius.org>
Mon, 20 Dec 2021 14:13:41 +0000 (09:13 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 21 Dec 2021 17:43:03 +0000 (12:43 -0500)
Also if the RHS is octets, then it should be parsed as the correct
data type. Right now this happens on compilation, but it should
also happen at run-time

src/lib/unlang/edit.c
src/tests/keywords/edit-leaf-octets [new file with mode: 0644]

index c7e54b210094f97cf80fa12496b40ea7a2511189..f7fcf53b22d8f9214904d9861965e8c1098271ef 100644 (file)
@@ -113,17 +113,22 @@ static int templatize_lhs(TALLOC_CTX *ctx, edit_result_t *out, request_t *reques
 static int templatize_rhs(TALLOC_CTX *ctx, edit_result_t *out, fr_pair_t const *lhs, request_t *request)
 {
        fr_type_t type = lhs->vp_type;
+       fr_type_t cast_type = FR_TYPE_STRING;
        fr_value_box_t *box = fr_dlist_head(&out->result);
 
        /*
         *      There's only one box, and it's the correct type.  Just
         *      return that.  This is the fast path.
         */
-       if ((type != FR_TYPE_STRING) && (type == box->type) && !fr_dlist_next(&out->result, box)) {
+       if (fr_type_is_leaf(type) && (type == box->type) && !fr_dlist_next(&out->result, box)) {
                if (tmpl_afrom_value_box(ctx, &out->to_free, box, false) < 0) return -1;
                goto done;
        }
 
+       if (fr_type_is_structural(type) && (box->type == FR_TYPE_OCTETS)) {
+               cast_type = FR_TYPE_OCTETS;
+       }
+
        /*
         *      Slow path: mash all of the results together as a
         *      string and then cast it to the correct data type.
@@ -131,28 +136,23 @@ static int templatize_rhs(TALLOC_CTX *ctx, edit_result_t *out, fr_pair_t const *
         *      @todo - if all of the boxes are of the correct type,
         *      then return a vector.
         */
-       if (fr_value_box_list_concat_in_place(box, box, &out->result, FR_TYPE_STRING, FR_VALUE_BOX_LIST_FREE, true, SIZE_MAX) < 0) {
+       if (fr_value_box_list_concat_in_place(box, box, &out->result, cast_type, FR_VALUE_BOX_LIST_FREE, true, SIZE_MAX) < 0) {
                RPEDEBUG("Right side expansion failed");
                return -1;
        }
 
        /*
-        *      If the LHS is structural, the RHS MUST be an in-place
-        *      pair list, which gets parsed later.
-        */
-       if (fr_type_is_structural(type)) {
-               type = FR_TYPE_STRING;
-       }
-
-       /*
-        *      The concatenated string is not an attribute reference.
-        *      It MUST be parsed as a value of the input data type.
+        *      Leaf types are cast to the correct type.  Either by
+        *      decoding them from octets, or by parsing the string
+        *      values.
         */
-       if ((fr_value_box_cast_in_place(ctx, box, type, lhs->data.enumv) <= 0) ||
-           (tmpl_afrom_value_box(ctx, &out->to_free, box, false) < 0)) {
+       if (fr_type_is_leaf(type) &&
+           (fr_value_box_cast_in_place(ctx, box, type, lhs->data.enumv) <= 0)) {
                return -1;
        }
 
+       if (tmpl_afrom_value_box(ctx, &out->to_free, box, false) < 0) return -1;
+
 done:
        out->vpt = out->to_free;
        fr_dlist_talloc_free(&out->result);
diff --git a/src/tests/keywords/edit-leaf-octets b/src/tests/keywords/edit-leaf-octets
new file mode 100644 (file)
index 0000000..eb9e20b
--- /dev/null
@@ -0,0 +1,17 @@
+#
+#  PRE: edit
+#
+
+&Framed-IP-Address := 0x7f000001
+
+if (!&Framed-IP-Address) {
+       %(debug_attr:request[*])
+       test_fail
+}
+
+if (&Framed-IP-Address != 127.0.0.1) {
+       %(debug_attr:request[*])
+       test_fail
+}
+
+success