]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
be more liberal with [...] in attr definitions
authorAlan T. DeKok <aland@freeradius.org>
Wed, 18 May 2016 20:02:11 +0000 (16:02 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 18 May 2016 21:24:36 +0000 (17:24 -0400)
and add tests for struct

src/lib/dict.c
src/tests/unit/dict.txt

index 2125b487f92bb30f282129d5bbb695b28a91db41..ef9983c3542d202d7b0b36c178b78e38bca8a57b 100644 (file)
@@ -1490,34 +1490,39 @@ static int dict_read_process_attribute(fr_dict_t *dict, fr_dict_attr_t const *pa
                block_vendor = vendor; /* Weird case where we're processing 26.<vid>.<tlv> */
        }
 
-       if (strncmp(argv[2], "octets[", 7) != 0) {
-               /*
-                *      find the type of the attribute.
-                */
-               type = fr_str2int(dict_attr_types, argv[2], -1);
-               if (type < 0) {
-                       fr_strerror_printf("Unknown data type '%s'", argv[2]);
-                       return -1;
-               }
+       /*
+        *      Some types can have fixed length
+        */
+       p = strchr(argv[2], '[');
+       if (p) *p = '\0';
 
-       } else {
-               type = PW_TYPE_OCTETS;
+       /*
+        *      find the type of the attribute.
+        */
+       type = fr_str2int(dict_attr_types, argv[2], -1);
+       if (type < 0) {
+               fr_strerror_printf("Unknown data type '%s'", argv[2]);
+               return -1;
+       }
+
+       if (p) {
+               char *q;
 
-               p = strchr(argv[2] + 7, ']');
-               if (!p) {
-                       fr_strerror_printf("Invalid format for 'octets'");
+               q = strchr(p + 1, ']');
+               if (!q) {
+                       fr_strerror_printf("Invalid format for '%s[...]'", argv[2]);
                        return -1;
                }
 
-               *p = 0;
+               *q = 0;
 
-               if (!dict_read_sscanf_i(argv[2] + 7, &length)) {
-                       fr_strerror_printf("Invalid length for 'octets'");
+               if (!dict_read_sscanf_i(p + 1, &length)) {
+                       fr_strerror_printf("Invalid length for '%s[...]'", argv[2]);
                        return -1;
                }
 
                if ((length == 0) || (length > 253)) {
-                       fr_strerror_printf("Invalid length for 'octets'");
+                       fr_strerror_printf("Invalid length for '%s[...]'", argv[2]);
                        return -1;
                }
 
index a6e3c3cfb9f6c0ee72c5fa6160c2629833d8fcac..950e61e6484172887bdbb66f45c035a996ebe60c 100644 (file)
@@ -51,7 +51,10 @@ dictionary ATTRIBUTE Unit-Fail       241.243.255.1   integer
 data Unknown child attribute starting at "255.1"
 
 dictionary ATTRIBUTE   Unit-Array      255             octets[123458]
-data Invalid length for 'octets'
+data Invalid length for 'octets[...]'
+
+dictionary ATTRIBUTE   Unit-Integer    255             integer[1]
+data fr_dict_attr_add: Failed adding 'Unit-Integer': The 'length' flag can only be set for attributes of type 'octets'
 
 dictionary ATTRIBUTE   Unit-$bad$stuff 255             integer
 data Invalid character '$' in attribute name
@@ -60,7 +63,7 @@ data Invalid character '$' in attribute name
 # flags
 #
 dictionary ATTRIBUTE   Unit-Array      241.254         octets[1234]
-data Invalid length for 'octets'
+data Invalid length for 'octets[...]'
 
 dictionary ATTRIBUTE   Unit-Tag        241.255         integer has_tag
 data fr_dict_attr_add: Failed adding 'Unit-Tag': The 'has_tag' flag can only be used with RFC and VSA attributes
@@ -70,3 +73,15 @@ data fr_dict_attr_add: Failed adding 'Unit-Tag': The 'has_tag' flag can only be
 
 dictionary ATTRIBUTE   Unit-Tag        255             tlv     encrypt=1
 data fr_dict_attr_add: Failed adding 'Unit-Tag': The 'encrypt=1' flag can only be used with attributes of type 'string'
+
+#
+#  structs
+#
+dictionary ATTRIBUTE   Unit-Struct     241.254         struct
+data ok
+
+dictionary ATTRIBUTE   Unit-Struct-Byte        241.254.1               byte
+data ok
+
+dictionary ATTRIBUTE   Unit-Struct-Octets      241.254.2               octets[2]
+data ok