]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
remove string/octets prepend.
authorAlan T. DeKok <aland@freeradius.org>
Wed, 19 Jan 2022 16:11:00 +0000 (11:11 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 19 Jan 2022 16:16:38 +0000 (11:16 -0500)
It's not really needed, and it interferes with the ability to
add XOR

doc/antora/modules/reference/pages/unlang/edit.adoc
src/lib/util/calc.c
src/tests/unit/calc.txt

index 00118321948e1e06e82ae37fd67611213fe2d5e1..0836877937b83233053eed26103e0e01ece6fcbf 100644 (file)
@@ -297,7 +297,7 @@ The operators also apply to non-integer attributes.
 | :=       | Override the attribute with the contents with the _<rhs>_.  If the attribute already exists, its value is over-written.  If the attribute does not exist, it is created, and the contents set to thex value of the _<rhs>_
 | +=       | Perform string append.  The contents of the _<rhs>_ are appended to the _<attribute>_.
 | -=       | Inverse of string append. The contents of the _<rhs>_ are deleted from from the _<attribute>_, if the `_<rhs>_` is a suffix of _<attribute>_ 
-| ^=       | Perform string prepend.  The contents of the _<rhs>_ are prepended to the _<attribute>_.
+| ^=       | Perform logical "xor".  The contents of the _<rhs>_ are "xor"ed with the contents of the _<rhs>_.  Both strings must be of the same length.
 | \|=       | Perform logical "or".  The value of the _<attribute>_ is "or"ed with the contents of the _<rhs>_.  Both strings must be of the same length.
 | \&=       | Perform logical "and".  The value of the _<attribute>_ is "and"ed with the contents of the _<rhs>_.  Both strings must be of the same length.
 | \<<=       | Perform left shift / truncation.  The first _<rhs>_ bytes of _<attribute>_ are dropped. i.e. shifted off of the start of the string.
index 0921c2c3640ad677da02eac20773b7bcf4224a07..f6f023cad3a35bf4b67c4ae31fda1a404cfe6bfe 100644 (file)
@@ -456,7 +456,7 @@ static int calc_octets(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_value_box_t cons
        len = a->length + b->length;
 
        switch (op) {
-       case T_OP_PREPEND:      /* dst = b . a */
+       case T_ADD:     /* dst = a . b */
                buf = talloc_array(ctx, uint8_t, len);
                if (!buf) {
                oom:
@@ -464,16 +464,6 @@ static int calc_octets(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_value_box_t cons
                        return -1;
                }
 
-               memcpy(buf, b->vb_octets, b->vb_length);
-               memcpy(buf + b->vb_length, a->vb_octets, a->vb_length);
-
-               fr_value_box_memdup_shallow(dst, dst->enumv, buf, len, a->tainted | b->tainted);
-               break;
-
-       case T_ADD:     /* dst = a . b */
-               buf = talloc_array(ctx, uint8_t, len);
-               if (!buf) goto oom;
-
                memcpy(buf, a->vb_octets, a->vb_length);
                memcpy(buf + a->vb_length, b->vb_octets, b->vb_length);
 
@@ -593,7 +583,7 @@ static int calc_string(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_value_box_t cons
        len = a->length + b->length;
 
        switch (op) {
-       case T_OP_PREPEND:      /* dst = b . a */
+       case T_ADD:
                buf = talloc_array(ctx, char, len + 1);
                if (!buf) {
                oom:
@@ -601,18 +591,6 @@ static int calc_string(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_value_box_t cons
                        return -1;
                }
 
-               len = a->vb_length + b->vb_length;
-               memcpy(buf, b->vb_strvalue, b->vb_length);
-               memcpy(buf + b->vb_length, a->vb_strvalue, a->vb_length);
-               buf[len] = '\0';
-
-               fr_value_box_bstrndup_shallow(dst, dst->enumv, buf, len, a->tainted | b->tainted);
-               break;
-
-       case T_ADD:
-               buf = talloc_array(ctx, char, len + 1);
-               if (!buf) goto oom;
-
                len = a->vb_length + b->vb_length;
                memcpy(buf, a->vb_strvalue, a->vb_length);
                memcpy(buf + a->vb_length, b->vb_strvalue, b->vb_length);
@@ -1278,23 +1256,6 @@ int fr_value_calc_binary_op(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_type_t hint
         */
        if (hint == FR_TYPE_NULL) do {
                switch (op) {
-               case T_OP_PREPEND:
-                       /*
-                        *      Pick the existing type if we have a
-                        *      variable-sized type.  Otherwise, pick
-                        *      octets.
-                        */
-                       if (fr_type_is_variable_size(a->type)) {
-                               hint = a->type;
-
-                       } else if (fr_type_is_variable_size(b->type)) {
-                               hint = b->type;
-
-                       } else {
-                               hint = FR_TYPE_OCTETS;
-                       }
-                       break;
-
                case T_OP_CMP_EQ:
                case T_OP_NE:
                case T_OP_GE:
@@ -1418,7 +1379,6 @@ int fr_value_calc_binary_op(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_type_t hint
        case T_DIV:
        case T_AND:
        case T_OR:
-       case T_OP_PREPEND:
        case T_RSHIFT:
        case T_LSHIFT:
                fr_assert(hint != FR_TYPE_NULL);
@@ -1503,10 +1463,6 @@ int fr_value_calc_assignment_op(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_token_t
                rcode = fr_value_calc_binary_op(ctx, &out, dst->type, dst, T_SUB, src);
                break;
 
-       case T_OP_PREPEND:
-               rcode = fr_value_calc_binary_op(ctx, dst, dst->type, dst, op, src);
-               break;
-
        case T_OP_AND_EQ:
                rcode = fr_value_calc_binary_op(ctx, &out, dst->type, dst, T_OR, src);
                break;
index a85ea644e4ea13b370db4186e15124ee753b20d0..04505c285cba251cadb2acd3d500da539b5eac97 100644 (file)
@@ -63,10 +63,6 @@ match a
 #
 #  octets
 #
-# octets prepend
-calc octets "a" ^ octets "b" -> octets
-match 0x6261
-
 # octets append
 calc octets "a" . octets "b" -> octets
 match 0x6162
@@ -81,6 +77,10 @@ match 0x60
 calc octets "a" | octets "b" -> octets
 match 0x63
 
+# octets xor
+#calc octets "a" ^ octets "b" -> octets
+#match 0x03
+
 # we can "fake out" structs by just appending stuff
 calc ipaddr 127.0.0.1 . ipaddr 127.0.0.2 -> octets
 match 0x7f0000017f000002
@@ -155,4 +155,4 @@ calc string "2" += string "test"
 match 2test
 
 count
-match 64
+match 62