From: Alan T. DeKok Date: Fri, 17 Feb 2023 14:00:56 +0000 (-0500) Subject: allow DEFINE for STRUCT X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=69cc0572941cd3888dc5f24665f8ebd08932dc93;p=thirdparty%2Ffreeradius-server.git allow DEFINE for STRUCT --- diff --git a/src/lib/util/dict_tokenize.c b/src/lib/util/dict_tokenize.c index a7c2156ae3c..0f4ae6c404c 100644 --- a/src/lib/util/dict_tokenize.c +++ b/src/lib/util/dict_tokenize.c @@ -1032,8 +1032,8 @@ static int dict_read_process_define(dict_tokenize_ctx_t *ctx, char **argv, int a } /* - * Since there is no number, the attribute MUST be - * internal, and cannot be encoded as a number. + * Since there is no number, the attribute cannot be + * encoded as a number. */ memcpy(&flags, base_flags, sizeof(flags)); flags.name_only = true; @@ -1044,7 +1044,6 @@ static int dict_read_process_define(dict_tokenize_ctx_t *ctx, char **argv, int a * Certain structural types MUST have numbers. */ switch (type) { - case FR_TYPE_STRUCT: case FR_TYPE_VSA: case FR_TYPE_VENDOR: fr_strerror_printf("DEFINE cannot be used for type '%s'", argv[1]); @@ -1098,7 +1097,16 @@ static int dict_read_process_define(dict_tokenize_ctx_t *ctx, char **argv, int a if (dict_process_ref(ctx, parent, da, ref) < 0) return -1; - memcpy(&ctx->value_attr, &da, sizeof(da)); + /* + * Adding an attribute of type 'struct' is an implicit + * BEGIN-STRUCT. + */ + if (type == FR_TYPE_STRUCT) { + if (dict_gctx_push(ctx, da) < 0) return -1; + ctx->value_attr = NULL; + } else { + memcpy(&ctx->value_attr, &da, sizeof(da)); + } return 0; } diff --git a/src/lib/util/dict_util.c b/src/lib/util/dict_util.c index a0182fecf19..4ef9e8ca5c5 100644 --- a/src/lib/util/dict_util.c +++ b/src/lib/util/dict_util.c @@ -1080,7 +1080,7 @@ int dict_attr_child_add(fr_dict_attr_t *parent, fr_dict_attr_t *child) * The parent has children by name only, not by number. Don't even bother trying to track * numbers. */ - if (parent->flags.name_only) return 0; + if (parent->flags.name_only && (parent->type != FR_TYPE_STRUCT)) return 0; /* * We only allocate the pointer array *if* the parent has children.