Skip to content

Commit 7e2fb4e

Browse files
committed
ensure that groups have a ref extension
1 parent 5de040f commit 7e2fb4e

File tree

3 files changed

+47
-13
lines changed

3 files changed

+47
-13
lines changed

src/lib/util/dict.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,8 @@ int fr_dict_enum_add_name_next(fr_dict_attr_t *da, char const *name) CC_HINT(n
532532
int fr_dict_str_to_argv(char *str, char **argv, int max_argc);
533533

534534
int fr_dict_attr_acopy_local(fr_dict_attr_t const *dst, fr_dict_attr_t const *src) CC_HINT(nonnull);
535+
536+
int fr_dict_attr_set_group(fr_dict_attr_t **da_p) CC_HINT(nonnull);
535537
/** @} */
536538

537539
/** @name Dict accessors

src/lib/util/dict_util.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4972,3 +4972,22 @@ fr_dict_attr_t const *fr_dict_unlocal(fr_dict_attr_t const *da)
49724972

49734973
return da;
49744974
}
4975+
4976+
int fr_dict_attr_set_group(fr_dict_attr_t **da_p)
4977+
{
4978+
if ((*da_p)->type == FR_TYPE_GROUP) {
4979+
fr_assert(fr_dict_attr_ext(*da_p, FR_DICT_ATTR_EXT_REF) != NULL);
4980+
return 0;
4981+
}
4982+
4983+
(*da_p)->type = FR_TYPE_GROUP;
4984+
4985+
fr_assert(fr_dict_attr_ext(*da_p, FR_DICT_ATTR_EXT_REF) == NULL);
4986+
4987+
if (!dict_attr_ext_alloc(da_p, FR_DICT_ATTR_EXT_REF)) {
4988+
return -1;
4989+
}
4990+
4991+
return 0;
4992+
}
4993+

src/protocols/der/base.c

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,22 @@ RCSID("$Id$")
2929
#include <freeradius-devel/util/net.h>
3030
#include <freeradius-devel/util/proto.h>
3131
#include <freeradius-devel/util/table.h>
32+
#include <freeradius-devel/util/dict_ext_priv.h>
3233

3334
#include "der.h"
3435

3536
static uint32_t instance_count = 0;
3637

3738
fr_dict_t const *dict_der;
39+
//fr_dict_attr_t const *attr_oid_tree;
3840

3941
extern fr_dict_autoload_t libfreeradius_der_dict[];
4042
fr_dict_autoload_t libfreeradius_der_dict[] = { { .out = &dict_der, .proto = "der" }, { NULL } };
4143

4244
extern fr_dict_attr_autoload_t libfreeradius_der_dict_attr[];
4345
fr_dict_attr_autoload_t libfreeradius_der_dict_attr[] = {
44-
{ NULL }
46+
// { .out = &attr_oid_tree, .name = "OID-Tree", .type = FR_TYPE_TLV, .dict = &dict_der },
47+
{ NULL }
4548
};
4649

4750
static fr_table_num_sorted_t const tag_name_to_number[] = {
@@ -274,9 +277,8 @@ static int dict_flag_sequence_of(fr_dict_attr_t **da_p, char const *value, UNUSE
274277
}
275278

276279
if (strcmp(value, "oid_and_value") == 0) {
277-
(*da_p)->type = FR_TYPE_GROUP;
278280
flags->is_pair = true;
279-
return 0;
281+
return fr_dict_attr_set_group(da_p);
280282
}
281283

282284
type = fr_table_value_by_str(tag_name_to_number, value, FR_DER_TAG_INVALID);
@@ -307,9 +309,8 @@ static int dict_flag_set_of(fr_dict_attr_t **da_p, char const *value, UNUSED fr_
307309
}
308310

309311
if (strcmp(value, "oid_and_value") == 0) {
310-
(*da_p)->type = FR_TYPE_GROUP;
311312
flags->is_pair = true;
312-
return 0;
313+
return fr_dict_attr_set_group(da_p);
313314
}
314315

315316
type = fr_table_value_by_str(tag_name_to_number, value, FR_DER_TAG_INVALID);
@@ -692,14 +693,6 @@ static bool attr_valid(fr_dict_attr_t *da)
692693
{
693694
fr_der_attr_flags_t *flags = fr_dict_attr_ext(da->parent, FR_DICT_ATTR_EXT_PROTOCOL_SPECIFIC);
694695

695-
/*
696-
* sequence_of=oid_and_value has to have a reference to the OID tree.
697-
*/
698-
if (flags->is_pair && !fr_dict_attr_ref(da)) {
699-
fr_strerror_const("Flag has 'oid_and_value' set, but is missing 'ref=OID-Tree'");
700-
return false;
701-
}
702-
703696
if (flags->is_sequence_of || flags->is_set_of) {
704697
fr_der_tag_t of_type = (flags->is_sequence_of ?
705698
flags->sequence_of :
@@ -716,6 +709,26 @@ static bool attr_valid(fr_dict_attr_t *da)
716709

717710
flags = fr_dict_attr_ext(da, FR_DICT_ATTR_EXT_PROTOCOL_SPECIFIC);
718711

712+
/*
713+
* sequence_of=oid_and_value has to have a reference to the OID tree.
714+
*
715+
* Group refs are added as unresolved refs, see dict_flag_ref(), and are resolved later
716+
* in dict_fixup_group_apply().
717+
*
718+
* @todo - have a function called from dict_attr_finalize() ?
719+
*/
720+
#if 0
721+
if (flags->is_pair) {
722+
fr_dict_attr_t const *ref;
723+
724+
fr_assert(da->type == FR_TYPE_GROUP);
725+
726+
if (!fr_dict_attr_ref(da)) {
727+
(void) dict_attr_ref_set(da, attr_oid_tree, FR_DICT_ATTR_REF_ALIAS);
728+
}
729+
}
730+
#endif
731+
719732
if (flags->is_choice && unlikely(!fr_type_is_tlv(da->type))) {
720733
fr_strerror_printf("Attribute %s of type %s is not allowed represent a collection of choices.",
721734
da->name, fr_type_to_str(da->type));

0 commit comments

Comments
 (0)