From: Alan T. DeKok Date: Wed, 18 May 2016 20:02:11 +0000 (-0400) Subject: be more liberal with [...] in attr definitions X-Git-Tag: branch_3_1_x~362 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5c11463f9181da58803becc68dacfa7e69f77d38;p=thirdparty%2Ffreeradius-server.git be more liberal with [...] in attr definitions and add tests for struct --- diff --git a/src/lib/dict.c b/src/lib/dict.c index 2125b487f92..ef9983c3542 100644 --- a/src/lib/dict.c +++ b/src/lib/dict.c @@ -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.. */ } - 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; } diff --git a/src/tests/unit/dict.txt b/src/tests/unit/dict.txt index a6e3c3cfb9f..950e61e6484 100644 --- a/src/tests/unit/dict.txt +++ b/src/tests/unit/dict.txt @@ -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