From: Alan T. DeKok Date: Wed, 17 May 2017 20:47:18 +0000 (-0400) Subject: allow for partially parsed sections X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3c36101185e6f003bb50ae40fc53883dc9a54207;p=thirdparty%2Ffreeradius-server.git allow for partially parsed sections where it doesn't print out the final }, until the caller parses more sub-sections, and then calls cf_parse_section() again, with variables=NULL --- diff --git a/src/include/conf_file.h b/src/include/conf_file.h index 742430f0390..29a12a0dbcd 100644 --- a/src/include/conf_file.h +++ b/src/include/conf_file.h @@ -423,6 +423,9 @@ typedef struct CONF_PARSER { #define CONF_PARSER_TERMINATOR { .name = NULL, .type = ~(UINT32_MAX - 1), \ .offset = 0, .data = NULL, .dflt = NULL, .quote = T_INVALID } +#define CONF_PARSER_PARTIAL_TERMINATOR { .name = NULL, .type = ~(UINT32_MAX - 1), \ + .offset = 1, .data = NULL, .dflt = NULL, .quote = T_INVALID } + typedef int (*cf_walker_t)(void *data, void *ctx); void cf_file_check_user(uid_t uid, gid_t gid); diff --git a/src/main/conf_file.c b/src/main/conf_file.c index cec3cd2a170..6640125664a 100644 --- a/src/main/conf_file.c +++ b/src/main/conf_file.c @@ -2472,6 +2472,14 @@ int cf_section_parse(TALLOC_CTX *ctx, void *base, CONF_SECTION *cs, CONF_PARSER void *data; bool *is_set = NULL; + /* + * Hack for partially parsed sections. + */ + if (!variables) { + cf_log_info(cs, "%.*s}", cs->depth, parse_spaces); + return 0; + } + cs->variables = variables; /* this doesn't hurt anything */ if (!cs->name2) { @@ -2548,14 +2556,21 @@ int cf_section_parse(TALLOC_CTX *ctx, void *base, CONF_SECTION *cs, CONF_PARSER */ rad_cond_assert(variables[i].type == conf_term.type); + cs->base = base; + + /* + * Hack for partially parsed sections. We don't print + * out the final "}", that will be printed out when the + * caller re-calls us with 'variable=NULL'. And, we don't warn about unused + */ + if (variables[i].offset == 1) return ret; + /* * Warn about items in the configuration which weren't * checked during parsing. */ if (rad_debug_lvl >= 3) cf_section_parse_warn(cs); - cs->base = base; - cf_log_info(cs, "%.*s}", cs->depth, parse_spaces); finish: