diff --git a/libexec/rc/rc.d/jail b/libexec/rc/rc.d/jail --- a/libexec/rc/rc.d/jail +++ b/libexec/rc/rc.d/jail @@ -455,7 +455,7 @@ _ALL) command=$jail_program rc_flags=$jail_flags - command_args="-f $jail_conf -c" + command_args="-c" if ! checkyesno jail_parallel_start; then command_args="$command_args -p1" fi @@ -543,7 +543,7 @@ _ALL) command=$jail_program rc_flags=$jail_flags - command_args="-f $jail_conf -r" + command_args="-r" if checkyesno jail_reverse_stop; then $jail_jls name | tail -r else diff --git a/usr.sbin/jail/config.c b/usr.sbin/jail/config.c --- a/usr.sbin/jail/config.c +++ b/usr.sbin/jail/config.c @@ -32,12 +32,14 @@ #include #include #include +#include #include -#include #include +#include #include +#include #include #include #include @@ -123,6 +125,14 @@ [KP_VNET] = {"vnet", 0}, }; +static void +check_glob(int rc) { + if (rc == GLOB_NOSPACE) + err(1, "Failed to allocate memory for glob!"); + else if (rc == GLOB_ABORTED) + err(1, "Error encountered parsing glob!"); +} + /* * Parse the jail configuration file. */ @@ -136,18 +146,43 @@ struct cfstring *s, *vs, *ns; struct cfvar *v, *vv; char *ep; - int did_self, jseq, pgen; - - if (!strcmp(cfname, "-")) { - cfname = "STDIN"; - yyin = stdin; - } else { + int did_self, jseq, pgen, rc; + + glob_t g; + memset(&g, 0, sizeof(g)); + rc = glob("/etc/jail.conf", GLOB_DOOFFS, NULL, &g); + check_glob(rc); + rc = glob("/etc/jail.conf.d/*.conf", GLOB_DOOFFS | GLOB_APPEND, NULL, &g); + check_glob(rc); + rc = glob("/etc/jail.*.conf", GLOB_DOOFFS | GLOB_APPEND, NULL, &g); + check_glob(rc); + if (cfname != NULL && strcmp(cfname, "-")) { + struct stat st; + memset(&st, 0, sizeof(st)); + if (stat(cfname, &st) != 0) + err(1, "No such file %s!", cfname); + rc = glob(cfname, GLOB_DOOFFS | GLOB_APPEND, NULL, &g); + } + if (g.gl_pathc == 0) + err(1, "No config file found!"); + for (size_t i = 0; i < g.gl_pathc; ++i) { + cfname = g.gl_pathv[i]; yyin = fopen(cfname, "r"); if (!yyin) err(1, "%s", cfname); + if (yyparse() || yynerrs) { + fclose(yyin); + exit(1); + } + fclose(yyin); + } + if (cfname != NULL && !strcmp(cfname, "-")) { + cfname = "STDIN"; + yyin = stdin; + if (yyparse() || yynerrs) { + exit(1); + } } - if (yyparse() || yynerrs) - exit(1); /* Separate the wildcard jails out from the actual jails. */ jseq = 0; diff --git a/usr.sbin/jail/jail.c b/usr.sbin/jail/jail.c --- a/usr.sbin/jail/jail.c +++ b/usr.sbin/jail/jail.c @@ -134,7 +134,6 @@ int main(int argc, char **argv) { - struct stat st; FILE *jfp; struct cfjail *j; char *JidFile; @@ -152,7 +151,7 @@ op = 0; dflag = Rflag = 0; docf = 1; - cfname = CONF_FILE; + cfname = NULL; JidFile = NULL; while ((ch = getopt(argc, argv, "cde:f:hiJ:lmn:p:qrRs:u:U:v")) != -1) { @@ -294,13 +293,13 @@ /* Jail remove, perhaps using the config file */ if (!docf || argc == 0) usage(); - if (!Rflag) + docf = !Rflag; + if (docf) { for (i = 0; i < argc; i++) if (strchr(argv[i], '=')) usage(); - if ((docf = !Rflag && - (!strcmp(cfname, "-") || stat(cfname, &st) == 0))) load_config(); + } note_remove = docf || argc > 1 || wild_jail_name(argv[0]); } else if (argc > 1 || (argc == 1 && strchr(argv[0], '='))) { /* Single jail specified on the command line */ diff --git a/usr.sbin/jail/jailp.h b/usr.sbin/jail/jailp.h --- a/usr.sbin/jail/jailp.h +++ b/usr.sbin/jail/jailp.h @@ -36,8 +36,6 @@ #include -#define CONF_FILE "/etc/jail.conf" - #define DEP_FROM 0 #define DEP_TO 1