Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/jail/jailparse.y
Show First 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | |||||
/* | /* | ||||
* A config file is a list of jails and parameters. Parameters are | * A config file is a list of jails and parameters. Parameters are | ||||
* added to the current jail, otherwise to a global pesudo-jail. | * added to the current jail, otherwise to a global pesudo-jail. | ||||
*/ | */ | ||||
conf : | conf : | ||||
| conf jail | | conf jail | ||||
| conf param ';' | | conf param ';' | ||||
{ | { | ||||
if (!special_param($2, scanner)) { | |||||
struct cfjail *j = current_jail; | struct cfjail *j = current_jail; | ||||
if (j == NULL) { | if (j == NULL) { | ||||
if (global_jail == NULL) { | if (global_jail == NULL) { | ||||
global_jail = add_jail(); | global_jail = add_jail(); | ||||
global_jail->name = estrdup("*"); | global_jail->name = estrdup("*"); | ||||
} | } | ||||
j = global_jail; | j = global_jail; | ||||
} | } | ||||
TAILQ_INSERT_TAIL(&j->params, $2, tq); | TAILQ_INSERT_TAIL(&j->params, $2, tq); | ||||
} | } | ||||
} | |||||
| conf ';' | | conf ';' | ||||
; | ; | ||||
jail : jail_name '{' conf '}' | jail : jail_name '{' conf '}' | ||||
{ | { | ||||
current_jail = current_jail->cfparent; | current_jail = current_jail->cfparent; | ||||
} | } | ||||
; | ; | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | | name PLEQ value | ||||
TAILQ_CONCAT(&$$->val, $3, tq); | TAILQ_CONCAT(&$$->val, $3, tq); | ||||
$$->flags |= PF_APPEND; | $$->flags |= PF_APPEND; | ||||
free($3); | free($3); | ||||
} | } | ||||
| name value | | name value | ||||
{ | { | ||||
$$ = $1; | $$ = $1; | ||||
TAILQ_CONCAT(&$$->val, $2, tq); | TAILQ_CONCAT(&$$->val, $2, tq); | ||||
$$->flags |= PF_NAMEVAL; | |||||
free($2); | free($2); | ||||
} | } | ||||
| error | | error | ||||
; | ; | ||||
/* | /* | ||||
* A parameter has a fixed name. A variable definition looks just like a | * A parameter has a fixed name. A variable definition looks just like a | ||||
* parameter except that the name is a variable. | * parameter except that the name is a variable. | ||||
▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | | string VAR1 | ||||
STAILQ_INSERT_TAIL(&$$->vars, v, tq); | STAILQ_INSERT_TAIL(&$$->vars, v, tq); | ||||
} | } | ||||
; | ; | ||||
%% | %% | ||||
extern int YYLEX_DECL(); | extern int YYLEX_DECL(); | ||||
extern struct cflex *yyget_extra(void *scanner); | |||||
extern int yyget_lineno(void *scanner); | |||||
extern char *yyget_text(void *scanner); | |||||
static void | static void | ||||
YYERROR_DECL() | YYERROR_DECL() | ||||
{ | { | ||||
if (!yyget_text(scanner)) | if (!yyget_text(scanner)) | ||||
warnx("%s line %d: %s", | warnx("%s line %d: %s", | ||||
yyget_extra(scanner)->cfname, yyget_lineno(scanner), s); | yyget_extra(scanner)->cfname, yyget_lineno(scanner), s); | ||||
else if (!yyget_text(scanner)[0]) | else if (!yyget_text(scanner)[0]) | ||||
warnx("%s: unexpected EOF", | warnx("%s: unexpected EOF", | ||||
yyget_extra(scanner)->cfname); | yyget_extra(scanner)->cfname); | ||||
else | else | ||||
warnx("%s line %d: %s: %s", | warnx("%s line %d: %s: %s", | ||||
yyget_extra(scanner)->cfname, yyget_lineno(scanner), | yyget_extra(scanner)->cfname, yyget_lineno(scanner), | ||||
yyget_text(scanner), s); | yyget_text(scanner), s); | ||||
} | |||||
/* Handle special parameters (i.e. the include directive). | |||||
* Return true if the parameter was specially handled. | |||||
*/ | |||||
static int | |||||
special_param(struct cfparam *p, void *scanner) | |||||
{ | |||||
if ((p->flags & (PF_VAR | PF_APPEND | PF_NAMEVAL)) != PF_NAMEVAL | |||||
|| strcmp(p->name, ".include")) | |||||
return 0; | |||||
struct cfstring *s; | |||||
TAILQ_FOREACH(s, &p->val, tq) { | |||||
if (STAILQ_EMPTY(&s->vars)) | |||||
include_config(scanner, s->s); | |||||
else { | |||||
warnx("%s line %d: " | |||||
"variables not permitted in '.include' filename", | |||||
yyget_extra(scanner)->cfname, | |||||
yyget_lineno(scanner)); | |||||
yyget_extra(scanner)->error = 1; | |||||
} | |||||
} | |||||
free_param_strings(p); | |||||
free(p); | |||||
return 1; | |||||
} | } |