- New include directive 'include-toplevel:'. It closes the previous

clause (if any) and requires that all included files explicitly
  start a clause.
This commit is contained in:
George Thessalonikefs 2020-04-29 11:23:12 +02:00
parent a269db3828
commit 1bd4dbf302
36 changed files with 5208 additions and 4931 deletions

View file

@ -5,9 +5,13 @@
#
# this is a comment.
#Use this to include other text into the file.
# Use this anywhere in the file to include other text into this file.
#include: "otherfile.conf"
# Use this anywhere in the file to include other text, that explicitly starts a
# clause, into this file. Text after this directive needs to start a clause.
#include-toplevel: "otherfile.conf"
# The server clause sets the main parameters.
server:
# whitespace is not necessary, but looks cleaner.

View file

@ -77,6 +77,12 @@ for the included files works, relative pathnames for the included names work
if the directory where the daemon is started equals its chroot/working
directory or is specified before the include statement with directory: dir.
Wildcards can be used to include multiple files, see \fIglob\fR(7).
.P
For a more structural include option, the
.B include\-toplevel:
directive can be used. This closes whatever clause is currently active (if any)
and forces the use of clauses in the included files and right after this
directive.
.SS "Server Options"
These options are part of the
.B server:

View file

@ -0,0 +1,3 @@
include-toplevel: include.withoutclauses.*
server:
identity: "top 1"

View file

@ -0,0 +1,5 @@
include-toplevel: include.withclauses.*
server:
identity: "top 1"
include: include.withoutclauses.*
include-toplevel: include.withoutclauses.*

View file

@ -0,0 +1,6 @@
include-toplevel: include.withclauses.*
server:
identity: "top 1"
include: include.withoutclauses.*
include-toplevel: include.withclauses.*
include: include.withoutclauses.*

View file

@ -0,0 +1,7 @@
include-toplevel: include.withclauses.*
server:
identity: "top 1"
include: include.withoutclauses.*
include-toplevel: include.withclauses.*
include: include.withclauses.*
include-toplevel: include.withoutclauses.*

View file

@ -0,0 +1,8 @@
include-toplevel: include.withclauses.*
server:
identity: "top 1"
include: include.withoutclauses.*
include-toplevel: include.withsomeclauses.*
include: include.withclauses.*
include-toplevel: include.withclauses.*
server: identity: "top 2"

View file

@ -0,0 +1,10 @@
include-toplevel: include.withclauses.*
include-toplevel: include.withclauses.*
server:
identity: "top 1"
include: include.withoutclauses.*
include-toplevel: include.withclauses.*
include: include.withclauses.*
include-toplevel: include.withclauses.*
server: identity: "top 2"
include-toplevel: include.includetop.withoutclauses.*

View file

@ -0,0 +1,11 @@
include-toplevel: include.withclauses.*
include-toplevel: include.withclauses.*
server:
identity: "top 1"
include: include.withoutclauses.*
include-toplevel: include.withclauses.*
include: include.withclauses.*
include-toplevel: include.withclauses.*
server: identity: "top 2"
include-toplevel: include.includetop.withclauses.*
include-toplevel: include.include.withoutclauses.*

View file

@ -0,0 +1,12 @@
include-toplevel: include.withclauses.*
include-toplevel: include.withclauses.*
server:
identity: "top 1"
include: include.withoutclauses.*
include-toplevel: include.withclauses.*
include: include.withclauses.*
include-toplevel: include.withclauses.*
server: identity: "top 2"
include-toplevel: include.includetop.withclauses.*
include-toplevel: include.include.withclauses.*
include-toplevel: include.include.withclauses.*

View file

@ -0,0 +1 @@
include: include.withclauses.*

View file

@ -0,0 +1 @@
include: include.withclauses.*

View file

@ -0,0 +1 @@
include: include.withclauses.*

View file

@ -0,0 +1 @@
include: include.withoutclauses.*

View file

@ -0,0 +1 @@
include: include.withoutclauses.*

View file

@ -0,0 +1 @@
include: include.withoutclauses.*

View file

@ -0,0 +1 @@
include-toplevel: include.withclauses.*

View file

@ -0,0 +1 @@
include-toplevel: include.withclauses.*

View file

@ -0,0 +1 @@
include-toplevel: include.withclauses.*

View file

@ -0,0 +1 @@
include-toplevel: include.withoutclauses.*

View file

@ -0,0 +1 @@
include-toplevel: include.withoutclauses.*

View file

@ -0,0 +1 @@
include-toplevel: include.withoutclauses.*

View file

@ -0,0 +1 @@
server: identity: "withclauses1"

View file

@ -0,0 +1 @@
server: identity: "withclauses2"

View file

@ -0,0 +1 @@
server: identity: "withclauses3"

View file

@ -0,0 +1 @@
identity: "withoutclauses1"

View file

@ -0,0 +1 @@
identity: "withoutclauses2"

View file

@ -0,0 +1 @@
identity: "withoutclauses3"

View file

@ -0,0 +1 @@
server: identity: "withsomeclauses1"

View file

@ -0,0 +1 @@
identity: "withsomeclauses2"

View file

@ -0,0 +1 @@
identity: "withsomeclauses3"

File diff suppressed because it is too large Load diff

View file

@ -45,11 +45,13 @@ struct inc_state {
int line;
YY_BUFFER_STATE buffer;
struct inc_state* next;
int inc_toplevel;
};
static struct inc_state* config_include_stack = NULL;
static int inc_depth = 0;
static int inc_prev = 0;
static int num_args = 0;
static int inc_toplevel = 0;
void init_cfg_parse(void)
{
@ -57,14 +59,15 @@ void init_cfg_parse(void)
inc_depth = 0;
inc_prev = 0;
num_args = 0;
inc_toplevel = 0;
}
static void config_start_include(const char* filename)
static void config_start_include(const char* filename, int toplevel)
{
FILE *input;
struct inc_state* s;
char* nm;
if(inc_depth++ > 100000) {
if(inc_depth+1 > 100000) {
ub_c_error_msg("too many include files");
return;
}
@ -96,17 +99,20 @@ static void config_start_include(const char* filename)
return;
}
LEXOUT(("switch_to_include_file(%s)\n", filename));
inc_depth++;
s->filename = cfg_parser->filename;
s->line = cfg_parser->line;
s->buffer = YY_CURRENT_BUFFER;
s->inc_toplevel = inc_toplevel;
s->next = config_include_stack;
config_include_stack = s;
cfg_parser->filename = nm;
cfg_parser->line = 1;
inc_toplevel = toplevel;
yy_switch_to_buffer(yy_create_buffer(input, YY_BUF_SIZE));
}
static void config_start_include_glob(const char* filename)
static void config_start_include_glob(const char* filename, int toplevel)
{
/* check for wildcards */
@ -139,19 +145,19 @@ static void config_start_include_glob(const char* filename)
globfree(&g);
if(r == GLOB_NOMATCH)
return; /* no matches for pattern */
config_start_include(filename); /* let original deal with it */
config_start_include(filename, toplevel); /* let original deal with it */
return;
}
/* process files found, if any */
for(i=(int)g.gl_pathc-1; i>=0; i--) {
config_start_include(g.gl_pathv[i]);
config_start_include(g.gl_pathv[i], toplevel);
}
globfree(&g);
return;
}
#endif /* HAVE_GLOB */
config_start_include(filename);
config_start_include(filename, toplevel);
}
static void config_end_include(void)
@ -165,6 +171,7 @@ static void config_end_include(void)
yy_delete_buffer(YY_CURRENT_BUFFER);
yy_switch_to_buffer(s->buffer);
config_include_stack = s->next;
inc_toplevel = s->inc_toplevel;
free(s);
}
@ -199,7 +206,7 @@ COLON \:
DQANY [^\"\n\r\\]|\\.
SQANY [^\'\n\r\\]|\\.
%x quotedstring singlequotedstr include include_quoted val
%x quotedstring singlequotedstr include include_quoted val include_toplevel include_toplevel_quoted
%%
<INITIAL,val>{SPACE}* {
@ -563,7 +570,7 @@ tcp-connection-limit{COLON} { YDVAR(2, VAR_TCP_CONNECTION_LIMIT) }
<include>\" { LEXOUT(("IQS ")); BEGIN(include_quoted); }
<include>{UNQUOTEDLETTER}* {
LEXOUT(("Iunquotedstr(%s) ", yytext));
config_start_include_glob(yytext);
config_start_include_glob(yytext, 0);
BEGIN(inc_prev);
}
<include_quoted><<EOF>> {
@ -576,7 +583,7 @@ tcp-connection-limit{COLON} { YDVAR(2, VAR_TCP_CONNECTION_LIMIT) }
<include_quoted>\" {
LEXOUT(("IQE "));
yytext[yyleng - 1] = '\0';
config_start_include_glob(yytext);
config_start_include_glob(yytext, 0);
BEGIN(inc_prev);
}
<INITIAL,val><<EOF>> {
@ -585,11 +592,47 @@ tcp-connection-limit{COLON} { YDVAR(2, VAR_TCP_CONNECTION_LIMIT) }
if (!config_include_stack) {
yyterminate();
} else {
int prev_toplevel = inc_toplevel;
fclose(yyin);
config_end_include();
if(prev_toplevel) return (VAR_FORCE_TOPLEVEL);
}
}
/* include-toplevel: directive */
<INITIAL,val>include-toplevel{COLON} {
LEXOUT(("v(%s) ", yytext)); inc_prev = YYSTATE; BEGIN(include_toplevel);
}
<include_toplevel><<EOF>> {
yyerror("EOF inside include_toplevel directive");
BEGIN(inc_prev);
}
<include_toplevel>{SPACE}* { LEXOUT(("ITSP ")); /* ignore */ }
<include_toplevel>{NEWLINE} { LEXOUT(("NL\n")); cfg_parser->line++; }
<include_toplevel>\" { LEXOUT(("ITQS ")); BEGIN(include_toplevel_quoted); }
<include_toplevel>{UNQUOTEDLETTER}* {
LEXOUT(("ITunquotedstr(%s) ", yytext));
config_start_include_glob(yytext, 1);
BEGIN(inc_prev);
return (VAR_FORCE_TOPLEVEL);
}
<include_toplevel_quoted><<EOF>> {
yyerror("EOF inside quoted string");
BEGIN(inc_prev);
}
<include_toplevel_quoted>{DQANY}* { LEXOUT(("ITSTR(%s) ", yytext)); yymore(); }
<include_toplevel_quoted>{NEWLINE} {
yyerror("newline before \" in include name");
cfg_parser->line++; BEGIN(inc_prev);
}
<include_toplevel_quoted>\" {
LEXOUT(("ITQE "));
yytext[yyleng - 1] = '\0';
config_start_include_glob(yytext, 1);
BEGIN(inc_prev);
return (VAR_FORCE_TOPLEVEL);
}
<val>{UNQUOTEDLETTER}* { LEXOUT(("unquotedstr(%s) ", yytext));
if(--num_args == 0) { BEGIN(INITIAL); }
yylval.str = strdup(yytext); return STRING_ARG; }

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -69,6 +69,7 @@ extern struct config_parser_state* cfg_parser;
%token SPACE LETTER NEWLINE COMMENT COLON ANY ZONESTR
%token <str> STRING_ARG
%token VAR_FORCE_TOPLEVEL
%token VAR_SERVER VAR_VERBOSITY VAR_NUM_THREADS VAR_PORT
%token VAR_OUTGOING_RANGE VAR_INTERFACE VAR_PREFER_IP4
%token VAR_DO_IP4 VAR_DO_IP6 VAR_PREFER_IP6 VAR_DO_UDP VAR_DO_TCP
@ -182,16 +183,20 @@ toplevelvar: serverstart contents_server | stubstart contents_stub |
rcstart contents_rc | dtstart contents_dt | viewstart contents_view |
dnscstart contents_dnsc | cachedbstart contents_cachedb |
ipsetstart contents_ipset | authstart contents_auth |
rpzstart contents_rpz
rpzstart contents_rpz |
force_toplevel
;
force_toplevel: VAR_FORCE_TOPLEVEL
{
OUTYY(("\nP(force-toplevel)\n"));
}
/* server: declaration */
serverstart: VAR_SERVER
{
OUTYY(("\nP(server:)\n"));
OUTYY(("\nP(server:)\n"));
}
;
contents_server: contents_server content_server
contents_server: contents_server content_server
| ;
content_server: server_num_threads | server_verbosity | server_port |
server_outgoing_range | server_do_ip4 |