From: Alan T. DeKok Date: Fri, 19 Feb 2021 13:44:42 +0000 (-0500) Subject: remove crap code X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5fa971fbbabfa6fb7fe9cfe2533ceaefbb259377;p=thirdparty%2Ffreeradius-server.git remove crap code it makes no sense to look up the parents name in the parent CONF_PARSER? Also add the new section to the parent AFTER the callback is done --- diff --git a/src/lib/server/cf_util.c b/src/lib/server/cf_util.c index 02ba180076e..1f7717d82c7 100644 --- a/src/lib/server/cf_util.c +++ b/src/lib/server/cf_util.c @@ -760,46 +760,8 @@ CONF_SECTION *_cf_section_alloc(TALLOC_CTX *ctx, CONF_SECTION *parent, CONF_DATA const *cd; CONF_PARSER *rule; - cs->depth = parent->depth + 1; - cf_item_add(parent, &(cs->item)); - - cd = cf_data_find(CF_TO_ITEM(parent), CONF_PARSER, cf_section_name1(parent)); - if (cd) { - rule = cf_data_value(cd); - - /* - * The parent has an ON_READ rule. Check - * if that rule has a child which matches - * this section. - */ - if ((FR_BASE_TYPE(rule->type) == FR_TYPE_SUBSECTION) && - ((rule->type & FR_TYPE_ON_READ) != 0) && - rule->subcs) { - CONF_PARSER const *rule_p; - - for (rule_p = rule->subcs; rule_p->name; rule_p++) { - if ((FR_BASE_TYPE(rule_p->type) == FR_TYPE_SUBSECTION) && - ((rule_p->type & FR_TYPE_ON_READ) != 0) && - (strcmp(rule_p->name, name1) == 0)) { - if (_cf_section_rule_push(cs, rule_p, - cd->item.filename, cd->item.lineno) < 0) { - error: - talloc_free(cs); - return NULL; - } - - if (rule_p->func(ctx, NULL, NULL, - cf_section_to_item(cs), rule_p) < 0) goto error; - return cs; - } - } - } - } - /* - * Call any ON_READ callback. And push this rule - * to the child section, so that the child can - * pick it up. + * Call any ON_READ callback. */ cd = cf_data_find(CF_TO_ITEM(parent), CONF_PARSER, name1); if (cd) { @@ -807,10 +769,19 @@ CONF_SECTION *_cf_section_alloc(TALLOC_CTX *ctx, CONF_SECTION *parent, if (rule->func && (FR_BASE_TYPE(rule->type) == FR_TYPE_SUBSECTION) && ((rule->type & FR_TYPE_ON_READ) != 0)) { - if (cf_section_rules_push(cs, rule) < 0) goto error; - if (rule->func(ctx, NULL, NULL, cf_section_to_item(cs), rule) < 0) goto error; + if (rule->func(ctx, NULL, NULL, cf_section_to_item(cs), rule) < 0) { + talloc_free(cs); + return NULL; + } } } + + /* + * Add the item to the parent after all sanity + * checks have been done. + */ + cs->depth = parent->depth + 1; + cf_item_add(parent, &(cs->item)); } return cs;