]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Various casting fixes
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 5 Mar 2018 10:24:31 +0000 (16:24 +0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 5 Mar 2018 10:25:18 +0000 (16:25 +0600)
share/dictionary.freeradius.internal
src/lib/util/value.c
src/tests/keywords/ethernet [new file with mode: 0644]

index b29a0684b72b80c68836853010f92499a2072a8a..6852b1066c87487de51b607c2e70259571c53719 100644 (file)
@@ -620,6 +620,12 @@ ATTRIBUTE  Tmp-Signed-7                            1867    signed
 ATTRIBUTE      Tmp-Signed-8                            1868    signed
 ATTRIBUTE      Tmp-Signed-9                            1869    signed
 
+ATTRIBUTE      Tmp-Ethernet-0                          1870    ether
+ATTRIBUTE      Tmp-Ethernet-1                          1871    ether
+ATTRIBUTE      Tmp-Ethernet-2                          1872    ether
+ATTRIBUTE      Tmp-Ethernet-3                          1873    ether
+ATTRIBUTE      Tmp-Ethernet-4                          1874    ether
+
 # 1870 - 1890, unused
 
 #
@@ -628,9 +634,9 @@ ATTRIBUTE   Tmp-Signed-9                            1869    signed
 ATTRIBUTE      Tmp-String-Tagged-0                     1891    string has_tag
 ATTRIBUTE      Tmp-String-Tagged-1                     1892    string has_tag
 
-ATTRIBUTE      Log-Message                             1893    string
-ATTRIBUTE      Log-Level                               1894    integer
-ATTRIBUTE      Log-Type                                1895    integer
+ATTRIBUTE      Log-Message                             1894    string
+ATTRIBUTE      Log-Level                               1895    integer
+ATTRIBUTE      Log-Type                                1896    integer
 
 #      Range:  1900-1909
 #      WiMAX server-side attributes.
index 0f16db3c41d31e556850bcc5f2f63b2ad9882044..5798edd978ecbb25e5081c3e71b5e230ecb5cb2f 100644 (file)
@@ -1649,7 +1649,10 @@ static inline int fr_value_box_cast_to_ipv4prefix(TALLOC_CTX *ctx, fr_value_box_
        }
 
        default:
-               break;
+               fr_strerror_printf("Invalid cast from %s to %s.  Unsupported",
+                                  fr_int2str(dict_attr_types, src->type, "<INVALID>"),
+                                  fr_int2str(dict_attr_types, dst_type, "<INVALID>"));
+               return -1;
        }
 
        dst->vb_ip.af = AF_INET;
@@ -1835,7 +1838,10 @@ static inline int fr_value_box_cast_to_ipv6prefix(TALLOC_CTX *ctx, fr_value_box_
                break;
 
        default:
-               break;
+               fr_strerror_printf("Invalid cast from %s to %s.  Unsupported",
+                                  fr_int2str(dict_attr_types, src->type, "<INVALID>"),
+                                  fr_int2str(dict_attr_types, dst_type, "<INVALID>"));
+               return -1;
        }
 
        dst->vb_ip.af = AF_INET6;
@@ -1845,6 +1851,46 @@ static inline int fr_value_box_cast_to_ipv6prefix(TALLOC_CTX *ctx, fr_value_box_
        return 0;
 }
 
+/** Convert any supported type to a bool
+ *
+ * Allowed input types are:
+ * - FR_TYPE_STRING ("00:11:22:33:44:55")
+ * - FR_TYPE_OCTETS (0x001122334455)
+ *
+ *
+ * @param ctx          unused.
+ * @param dst          Where to write result of casting.
+ * @param dst_type     to cast to.
+ * @param dst_enumv    enumeration values.
+ * @param src          Input data.
+ */
+static inline int fr_value_box_cast_to_ethernet(TALLOC_CTX *ctx, fr_value_box_t *dst,
+                                               fr_type_t dst_type, fr_dict_attr_t const *dst_enumv,
+                                               fr_value_box_t const *src)
+{
+       switch (src->type) {
+       case FR_TYPE_STRING:
+               if (fr_value_box_from_str(ctx, dst, &dst_type, dst_enumv,
+                                         src->vb_strvalue, src->datum.length, '\0', false) < 0) return -1;
+               break;
+
+       case FR_TYPE_OCTETS:
+               if (fr_value_box_fixed_size_from_ocets(dst, dst_type, dst_enumv, src) < 0) return -1;
+               break;
+
+       default:
+               fr_strerror_printf("Invalid cast from %s to %s.  Unsupported",
+                                  fr_int2str(dict_attr_types, src->type, "<INVALID>"),
+                                  fr_int2str(dict_attr_types, dst_type, "<INVALID>"));
+               return -1;
+       }
+
+       dst->type = FR_TYPE_ETHERNET;
+       dst->enumv = dst_enumv;
+
+       return 0;
+}
+
 /** Convert any supported type to a bool
  *
  * Allowed input types are:
@@ -1866,9 +1912,11 @@ static inline int fr_value_box_cast_to_bool(TALLOC_CTX *ctx, fr_value_box_t *dst
                                          src->vb_strvalue, src->datum.length, '\0', false) < 0) return -1;
                break;
 
-
        default:
-               break;
+               fr_strerror_printf("Invalid cast from %s to %s.  Unsupported",
+                                  fr_int2str(dict_attr_types, src->type, "<INVALID>"),
+                                  fr_int2str(dict_attr_types, dst_type, "<INVALID>"));
+               return -1;
        }
 
        dst->type = FR_TYPE_BOOL;
@@ -1905,9 +1953,15 @@ static inline int fr_value_box_cast_to_uint8(TALLOC_CTX *ctx, fr_value_box_t *ds
                                          src->vb_strvalue, src->datum.length, '\0', false) < 0) return -1;
                break;
 
-       default:
+       case FR_TYPE_OCTETS:
                if (fr_value_box_fixed_size_from_ocets(dst, dst_type, dst_enumv, src) < 0) return -1;
                break;
+
+       default:
+               fr_strerror_printf("Invalid cast from %s to %s.  Unsupported",
+                                  fr_int2str(dict_attr_types, src->type, "<INVALID>"),
+                                  fr_int2str(dict_attr_types, dst_type, "<INVALID>"));
+               return -1;
        }
 
        dst->type = FR_TYPE_UINT8;
@@ -1957,9 +2011,15 @@ static inline int fr_value_box_cast_to_uint16(TALLOC_CTX *ctx, fr_value_box_t *d
                                          src->vb_strvalue, src->datum.length, '\0', false) < 0) return -1;
                break;
 
-       default:
+       case FR_TYPE_OCTETS:
                if (fr_value_box_fixed_size_from_ocets(dst, dst_type, dst_enumv, src) < 0) return -1;
                break;
+
+       default:
+               fr_strerror_printf("Invalid cast from %s to %s.  Unsupported",
+                                  fr_int2str(dict_attr_types, src->type, "<INVALID>"),
+                                  fr_int2str(dict_attr_types, dst_type, "<INVALID>"));
+               return -1;
        }
 
        dst->type = FR_TYPE_UINT16;
@@ -2027,9 +2087,15 @@ static inline int fr_value_box_cast_to_uint32(TALLOC_CTX *ctx, fr_value_box_t *d
                                          src->vb_strvalue, src->datum.length, '\0', false) < 0) return -1;
                break;
 
-       default:
+       case FR_TYPE_OCTETS:
                if (fr_value_box_fixed_size_from_ocets(dst, dst_type, dst_enumv, src) < 0) return -1;
                break;
+
+       default:
+               fr_strerror_printf("Invalid cast from %s to %s.  Unsupported",
+                                  fr_int2str(dict_attr_types, src->type, "<INVALID>"),
+                                  fr_int2str(dict_attr_types, dst_type, "<INVALID>"));
+               return -1;
        }
 
        dst->type = FR_TYPE_UINT32;
@@ -2111,9 +2177,15 @@ static inline int fr_value_box_cast_to_uint64(TALLOC_CTX *ctx, fr_value_box_t *d
                                          src->vb_strvalue, src->datum.length, '\0', false) < 0) return -1;
                break;
 
-       default:
+       case FR_TYPE_OCTETS:
                if (fr_value_box_fixed_size_from_ocets(dst, dst_type, dst_enumv, src) < 0) return -1;
                break;
+
+       default:
+               fr_strerror_printf("Invalid cast from %s to %s.  Unsupported",
+                                  fr_int2str(dict_attr_types, src->type, "<INVALID>"),
+                                  fr_int2str(dict_attr_types, dst_type, "<INVALID>"));
+               return -1;
        }
 
        dst->type = FR_TYPE_UINT64;
@@ -2191,7 +2263,11 @@ int fr_value_box_cast(TALLOC_CTX *ctx, fr_value_box_t *dst,
        case FR_TYPE_IFID:
        case FR_TYPE_COMBO_IP_ADDR:
        case FR_TYPE_COMBO_IP_PREFIX:
+               break;
+
        case FR_TYPE_ETHERNET:
+               return fr_value_box_cast_to_ethernet(ctx, dst, dst_type, dst_enumv, src);
+
        case FR_TYPE_BOOL:
                return fr_value_box_cast_to_bool(ctx, dst, dst_type, dst_enumv, src);
 
diff --git a/src/tests/keywords/ethernet b/src/tests/keywords/ethernet
new file mode 100644 (file)
index 0000000..6aa5238
--- /dev/null
@@ -0,0 +1,35 @@
+update request {
+       Tmp-Ethernet-0 := "00:11:22:33:44:54"
+       Tmp-Ethernet-0 += "00:11:22:33:44:55"
+       Tmp-Octets-0 := 0x001122334456
+}
+
+if (&Tmp-Ethernet-0[0] != 00:11:22:33:44:54) {
+       test_fail
+}
+
+if (&Tmp-Ethernet-0[1] != 00:11:22:33:44:55) {
+       test_fail
+}
+
+update request {
+       &Tmp-Ethernet-0 += &Tmp-Octets-0[0]
+}
+
+if (&Tmp-Ethernet-0[2] != 00:11:22:33:44:56) {
+       test_fail
+}
+
+# NULL assignment
+update request {
+       &Tmp-Ethernet-0 += "%{Calling-Station-ID[42]}"
+}
+
+# Null xlat expansion results in zero length string, which with current behaviour
+# results in all zeros ethernet address.
+if (&Tmp-Ethernet-0[3] != 00:00:00:00:00:00) {
+       test_fail
+}
+
+
+success