]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add 'length=uint8'
authorAlan T. DeKok <aland@freeradius.org>
Mon, 7 Mar 2022 14:15:26 +0000 (09:15 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 7 Mar 2022 14:15:26 +0000 (09:15 -0500)
src/lib/util/dict.h
src/lib/util/dict_print.c
src/lib/util/dict_tokenize.c
src/lib/util/dict_validate.c

index c130cea61e88a4839c530efd3de2138da2324471..1a0cdf4d23f408709ffc79509d0aaedced5bbce5 100644 (file)
@@ -134,12 +134,13 @@ enum {
        FLAG_EXTRA_NONE = 0,                            //!< no extra meaning, should be invalid
        FLAG_KEY_FIELD,                                 //!< this is a key field for a subsequent struct
        FLAG_BIT_FIELD,                                 //!< bit field inside of a struct
+       FLAG_LENGTH_UINT8,                              //!< string / octets type is prefixed by uint8 of length
        FLAG_LENGTH_UINT16,                             //!< string / octets type is prefixed by uint16 of length
 };
 
 #define fr_dict_attr_is_key_field(_da) ((_da)->flags.extra && ((_da)->flags.subtype == FLAG_KEY_FIELD))
 #define da_is_bit_field(_da) ((_da)->flags.extra && ((_da)->flags.subtype == FLAG_BIT_FIELD))
-#define da_is_length_field(_da) ((_da)->flags.extra && ((_da)->flags.subtype == FLAG_LENGTH_UINT16))
+#define da_is_length_field(_da) ((_da)->flags.extra && (((_da)->flags.subtype == FLAG_LENGTH_UINT16) || ((_da)->flags.subtype == FLAG_LENGTH_UINT16)))
 
 
 /** Extension identifier
index 499bc4e2c61d386f2a249c54c98503619fe8dd75..23312e1882e58848400f36083c260312b16dbc9f 100644 (file)
@@ -70,11 +70,15 @@ ssize_t fr_dict_attr_flags_print(fr_sbuff_t *out, fr_dict_t const *dict, fr_type
                        FR_SBUFF_IN_STRCPY_LITERAL_RETURN(&our_out, "key,");
                        break;
 
-               case FLAG_LENGTH_UINT16:
+               case FLAG_BIT_FIELD:
                        FR_SBUFF_IN_STRCPY_LITERAL_RETURN(&our_out, "length=uint16,");
                        break;
 
-               case FLAG_BIT_FIELD:
+               case FLAG_LENGTH_UINT8:
+                       FR_SBUFF_IN_STRCPY_LITERAL_RETURN(&our_out, "length=uint8,");
+                       break;
+
+               case FLAG_LENGTH_UINT16:
                        FR_SBUFF_IN_STRCPY_LITERAL_RETURN(&our_out, "length=uint16,");
                        break;
 
index ac11db0f6f4f4157511e51528768f59059165501..e22df453b0ddf2a6b00083cb7136e75795ac0c6d 100644 (file)
@@ -384,12 +384,23 @@ static int dict_process_flag_field(dict_tokenize_ctx_t *ctx, char *name, fr_type
                        flags->subtype = FLAG_KEY_FIELD;
 
                } else if (strcmp(key, "length") == 0) {
-                       if (!value || (strcmp(value, "uint16") != 0)) {
-                               fr_strerror_const("The 'length' flag can only be used with value 'uint16'");
+                       if (!value) {
+                               fr_strerror_const("The 'length' flag requires a value");
+                               return -1;
                        }
 
-                       flags->extra = 1;
-                       flags->subtype = FLAG_LENGTH_UINT16;
+                       if (strcmp(value, "uint8") == 0) {
+                               flags->extra = 1;
+                               flags->subtype = FLAG_LENGTH_UINT8;
+
+                       } else if (strcmp(value, "uint16") == 0) {
+                               flags->extra = 1;
+                               flags->subtype = FLAG_LENGTH_UINT16;
+
+                       } else {
+                               fr_strerror_const("Invalid value given for the 'length' flag");
+                               return -1;
+                       }
 
                } else if ((type == FR_TYPE_DATE) || (type == FR_TYPE_TIME_DELTA)) {
                        /*
@@ -1440,6 +1451,10 @@ static int dict_read_process_struct(dict_tokenize_ctx_t *ctx, char **argv, int a
         */
        memset(&flags, 0, sizeof(flags));
 
+       /*
+        *      Structs can be prefixed with 16-bit lengths, but not
+        *      with any other type of length.
+        */
        if (argc == 4) {
                if (strcmp(argv[3], "length=uint16") != 0) {
                        fr_strerror_printf("Unknown option '%s'", argv[3]);
index 0c48e8e8874add91666c9ea128e55596b3bdc59a..c86095122099a2358e004d7b26e6d029db8c23d3 100644 (file)
@@ -165,8 +165,8 @@ bool dict_attr_flags_valid(fr_dict_t *dict, fr_dict_attr_t const *parent,
         *      the data type.
         */
        if (flags->extra) {
-               if ((flags->subtype != FLAG_KEY_FIELD) && (flags->subtype != FLAG_LENGTH_UINT16) &&
-                   (flags->subtype != FLAG_BIT_FIELD)) {
+               if ((flags->subtype != FLAG_KEY_FIELD) && (flags->subtype != FLAG_BIT_FIELD) &&
+                   (flags->subtype != FLAG_LENGTH_UINT8) && (flags->subtype != FLAG_LENGTH_UINT16)) {
                        fr_strerror_const("The 'key' and 'length' flags cannot be used with any other flags.");
                        return false;
                }
@@ -209,7 +209,7 @@ bool dict_attr_flags_valid(fr_dict_t *dict, fr_dict_attr_t const *parent,
                        if (flags->array) {
                                ALLOW_FLAG(array);
 
-                               if (flags->subtype != FLAG_LENGTH_UINT16) goto invalid_extra;
+                               if ((flags->subtype != FLAG_LENGTH_UINT8) && (flags->subtype != FLAG_LENGTH_UINT16)) goto invalid_extra;
                        } else if (flags->subtype) {
                        invalid_extra:
                                fr_strerror_const("Invalid type for extra flag.");
@@ -243,7 +243,7 @@ bool dict_attr_flags_valid(fr_dict_t *dict, fr_dict_attr_t const *parent,
                        return false;
                }
 
-               if ((flags->subtype == FLAG_LENGTH_UINT16) &&
+               if (((flags->subtype == FLAG_LENGTH_UINT8) || (flags->subtype == FLAG_LENGTH_UINT16)) &&
                    ((type != FR_TYPE_STRING) && (type != FR_TYPE_OCTETS) && (type != FR_TYPE_STRUCT))) {
                        fr_strerror_printf("The 'length' flag cannot be used used with type %s",
                                           fr_type_to_str(type));