From: Alan T. DeKok Date: Sun, 1 Sep 2024 16:19:34 +0000 (-0400) Subject: distinguish usage of "group" X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4e3c6936689d064adf9bc96dadaa137537d2541b;p=thirdparty%2Ffreeradius-server.git distinguish usage of "group" group foo is a local variable definition group foo { is a section name. Oops. --- diff --git a/src/lib/server/cf_file.c b/src/lib/server/cf_file.c index d12c0aa074..82a0582008 100644 --- a/src/lib/server/cf_file.c +++ b/src/lib/server/cf_file.c @@ -2364,6 +2364,7 @@ static int parse_input(cf_stack_t *stack) */ if ((name1_token == T_BARE_WORD) && parent->allow_locals) { fr_type_t type; + char const *ptr3; type = fr_table_value_by_str(fr_type_table, buff[1], FR_TYPE_NULL); if (type == FR_TYPE_NULL) { @@ -2373,6 +2374,27 @@ static int parse_input(cf_stack_t *stack) if (type == FR_TYPE_TLV) goto parse_name2; + /* + * group { + * + * is a section. + */ + if (type == FR_TYPE_GROUP) { + fr_skip_whitespace(ptr); + if (*ptr == '{') { + ptr++; + value = NULL; + name2_token = T_BARE_WORD; + goto alloc_section; + } + + } else if (!fr_type_is_leaf(type)) { + /* + * Other structural types are allowed. + */ + return parse_error(stack, ptr2, "Invalid data type for local variable. Must be 'tlv' or else a non-structrul type"); + } + /* * We don't have an operator, so set it to a magic value. */ @@ -2381,12 +2403,34 @@ static int parse_input(cf_stack_t *stack) /* * Parse the name of the local variable, and use it as the "value" for the CONF_PAIR. */ + ptr3 = ptr; if (cf_get_token(parent, &ptr, &value_token, buff[2], stack->bufsize, frame->filename, frame->lineno) < 0) { return -1; } + + if (value_token != T_BARE_WORD) { + return parse_error(stack, ptr3, "Invalid name"); + } + value = buff[2]; - goto alloc_pair; + + /* + * Non-structural things must be variable definitions. + */ + if (fr_type_is_leaf(type)) goto alloc_pair; + + /* + * Parse: group foo + * vs group foo { ... + */ + fr_skip_whitespace(ptr); + + if (*ptr != '{') goto alloc_pair; + + ptr++; + name2_token = T_BARE_WORD; + goto alloc_section; } /* @@ -2500,6 +2544,8 @@ check_for_eol: value = buff[2]; alloc_section: + parent->allow_locals = false; + css = cf_section_alloc(parent, parent, buff[1], value); if (!css) { ERROR("%s[%d]: Failed allocating memory for section",