From: Arran Cudbard-Bell Date: Thu, 23 Jul 2015 01:32:29 +0000 (-0400) Subject: Pass error codes back through cf_section_parse X-Git-Tag: release_3_0_10~295 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3d847f8d59ff1b39c12e3abaa994d3fae26df669;p=thirdparty%2Ffreeradius-server.git Pass error codes back through cf_section_parse --- diff --git a/src/main/conffile.c b/src/main/conffile.c index cdf3390b215..49ea90739fd 100644 --- a/src/main/conffile.c +++ b/src/main/conffile.c @@ -1382,7 +1382,11 @@ static inline int fr_item_validate_ipaddr(CONF_SECTION *cs, char const *name, PW * - ``flag`` #PW_TYPE_NOT_EMPTY - @copybrief PW_TYPE_NOT_EMPTY * @param data Pointer to a global variable, or pointer to a field in the struct being populated with values. * @param dflt value to use, if no #CONF_PAIR is found. - * @return -1 on error, -2 if deprecated, 0 on success (correctly parsed), 1 if default value was used. + * @return + * - 1 if default value was used. + * - 0 on success. + * - -1 on error. + * - -2 if deprecated. */ int cf_item_parse(CONF_SECTION *cs, char const *name, unsigned int type, void *data, char const *dflt) { @@ -1824,24 +1828,29 @@ static void cf_section_parse_warn(CONF_SECTION *cs) } } -/* - * Parse a configuration section into user-supplied variables. +/** Parse a configuration section into user-supplied variables + * + * @param cs to parse. + * @param base pointer to a struct to fill with data. Any buffers will also be talloced + * using this parent as a pointer. + * @param variables mappings between struct fields and #CONF_ITEM s. + * @return + * - 0 on success. + * - -1 on general error. + * - -2 if a deprecated #CONF_ITEM was found. */ -int cf_section_parse(CONF_SECTION *cs, void *base, - CONF_PARSER const *variables) +int cf_section_parse(CONF_SECTION *cs, void *base, CONF_PARSER const *variables) { - int ret; + int ret = 0; int i; void *data; cs->variables = variables; /* this doesn't hurt anything */ if (!cs->name2) { - cf_log_info(cs, "%.*s%s {", cs->depth, parse_spaces, - cs->name1); + cf_log_info(cs, "%.*s%s {", cs->depth, parse_spaces, cs->name1); } else { - cf_log_info(cs, "%.*s%s %s {", cs->depth, parse_spaces, - cs->name1, cs->name2); + cf_log_info(cs, "%.*s%s %s {", cs->depth, parse_spaces, cs->name1, cs->name2); } cf_section_parse_init(cs, base, variables); @@ -1863,11 +1872,13 @@ int cf_section_parse(CONF_SECTION *cs, void *base, */ if (!variables[i].dflt || !subcs) { ERROR("Internal sanity check 1 failed in cf_section_parse %s", variables[i].name); - goto error; + ret = -1; + goto finish; } - if (cf_section_parse(subcs, (uint8_t *)base + variables[i].offset, - (CONF_PARSER const *) variables[i].dflt) < 0) goto error; + ret = cf_section_parse(subcs, (uint8_t *)base + variables[i].offset, + (CONF_PARSER const *) variables[i].dflt); + if (ret < 0) goto finish; continue; } /* else it's a CONF_PAIR */ @@ -1876,25 +1887,33 @@ int cf_section_parse(CONF_SECTION *cs, void *base, } else if (base) { data = ((char *)base) + variables[i].offset; } else { - DEBUG2("Internal sanity check 2 failed in cf_section_parse"); - goto error; + ERROR("Internal sanity check 2 failed in cf_section_parse"); + ret = -1; + goto finish; } /* * Parse the pair we found, or a default value. */ ret = cf_item_parse(cs, variables[i].name, variables[i].type, data, variables[i].dflt); - if (ret < 0) { - /* - * Be nice, and print the name of the new config item. - */ - if ((ret == -2) && (variables[i + 1].offset == variables[i].offset) && + switch (ret) { + case 1: /* Used default */ + ret = 0; + break; + + case 0: /* OK */ + break; + + case -1: /* Parse error */ + goto finish; + + case -2: /* Deprecated CONF ITEM */ + if ((variables[i + 1].offset == variables[i].offset) && (variables[i + 1].data == variables[i].data)) { cf_log_err(&(cs->item), "Replace \"%s\" with \"%s\"", variables[i].name, variables[i + 1].name); } - - goto error; + goto finish; } } /* for all variables in the configuration section */ @@ -1904,15 +1923,12 @@ int cf_section_parse(CONF_SECTION *cs, void *base, */ if (rad_debug_lvl >= 3) cf_section_parse_warn(cs); - cf_log_info(cs, "%.*s}", cs->depth, parse_spaces); - cs->base = base; - return 0; - - error: cf_log_info(cs, "%.*s}", cs->depth, parse_spaces); - return -1; + +finish: + return ret; }