From: Arran Cudbard-Bell Date: Fri, 2 Oct 2020 19:47:04 +0000 (-0500) Subject: Better errors X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=91bd3bb3797c8f7abc06c2170ad7cefa89d68f49;p=thirdparty%2Ffreeradius-server.git Better errors --- diff --git a/src/lib/server/tmpl_tokenize.c b/src/lib/server/tmpl_tokenize.c index 716ec396058..437a13667ad 100644 --- a/src/lib/server/tmpl_tokenize.c +++ b/src/lib/server/tmpl_tokenize.c @@ -1319,6 +1319,7 @@ static inline int tmpl_attr_afrom_attr_substr(TALLOC_CTX *ctx, tmpl_attr_error_t fr_dict_attr_t const *da; fr_sbuff_marker_t m_s; tmpl_attr_filter_t filter; + fr_dict_attr_err_t dict_err; fr_sbuff_marker(&m_s, name); @@ -1343,14 +1344,26 @@ static inline int tmpl_attr_afrom_attr_substr(TALLOC_CTX *ctx, tmpl_attr_error_t * No parent means we need to go hunting through all the dictionaries */ if (!parent) { - slen = fr_dict_attr_by_qualified_name_substr(NULL, &da, + slen = fr_dict_attr_by_qualified_name_substr(&dict_err, &da, rules->dict_def, name, !rules->disallow_internal); /* * Otherwise we're resolving in the context of the last component, * or its reference in the case of group attributes. */ } else { - slen = fr_dict_attr_child_by_name_substr(NULL, &da, parent, name, false); + slen = fr_dict_attr_child_by_name_substr(&dict_err, &da, parent, name, false); + } + + /* + * Fatal errors related to nesting... + */ + switch (dict_err) { + case FR_DICT_ATTR_NO_CHILDREN: + case FR_DICT_ATTR_NOT_DESCENDENT: + goto error; + + default: + break; } /* diff --git a/src/lib/util/dict_util.c b/src/lib/util/dict_util.c index 1c19cab7a8d..9635796470b 100644 --- a/src/lib/util/dict_util.c +++ b/src/lib/util/dict_util.c @@ -2109,6 +2109,22 @@ ssize_t fr_dict_attr_child_by_name_substr(fr_dict_attr_err_t *err, DA_VERIFY(parent); + /* + * Check the parent can is a grouping attribute + */ + switch (parent->type) { + case FR_TYPE_STRUCTURAL: + break; + + default: + fr_strerror_printf("Parent (%s) is a %s, it cannot contain nested attributes", + parent->name, + fr_table_str_by_value(fr_value_box_type_table, + parent->type, "?Unknown?")); + if (err) *err = FR_DICT_ATTR_NO_CHILDREN; + return 0; + } + /* * We return the child of the referenced attribute, and * not of the "group" attribute. @@ -2116,7 +2132,7 @@ ssize_t fr_dict_attr_child_by_name_substr(fr_dict_attr_err_t *err, if (parent->type == FR_TYPE_GROUP) parent = parent->ref; if (!parent->children) { - fr_strerror_printf("%s has no children", parent->name); + fr_strerror_printf("Parent (%s) has no children", parent->name); if (err) *err = FR_DICT_ATTR_NO_CHILDREN; return 0; } @@ -2127,7 +2143,7 @@ ssize_t fr_dict_attr_child_by_name_substr(fr_dict_attr_err_t *err, if (is_direct_decendent) { if ((*out)->parent != parent) { not_decendent: - fr_strerror_printf("%s is not a descendent of %s", parent->name, (*out)->name); + fr_strerror_printf("%s is not a descendent of parent (%s)", parent->name, (*out)->name); if (err) *err = FR_DICT_ATTR_NOT_DESCENDENT; *out = NULL; return 0;