2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2011 James Gritton
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/types.h>
30 #include <sys/errno.h>
31 #include <sys/socket.h>
32 #include <sys/sysctl.h>
34 #include <arpa/inet.h>
35 #include <netinet/in.h>
47 #define MAX_INCLUDE_DEPTH 32
54 extern int yylex_init_extra(struct cflex *extra, void *scanner);
55 extern int yylex_destroy(void *scanner);
56 extern int yyparse(void *scanner);
57 extern int yyset_in(FILE *fp, void *scanner);
59 struct cfjails cfjails = TAILQ_HEAD_INITIALIZER(cfjails);
61 static void parse_config(const char *fname, int is_stdin);
62 static void free_param(struct cfparams *pp, struct cfparam *p);
64 static const struct ipspec intparams[] = {
65 [IP_ALLOW_DYING] = {"allow.dying", PF_INTERNAL | PF_BOOL},
66 [IP_COMMAND] = {"command", PF_INTERNAL},
67 [IP_DEPEND] = {"depend", PF_INTERNAL},
68 [IP_EXEC_CLEAN] = {"exec.clean", PF_INTERNAL | PF_BOOL},
69 [IP_EXEC_CONSOLELOG] = {"exec.consolelog", PF_INTERNAL},
70 [IP_EXEC_FIB] = {"exec.fib", PF_INTERNAL | PF_INT},
71 [IP_EXEC_JAIL_USER] = {"exec.jail_user", PF_INTERNAL},
72 [IP_EXEC_POSTSTART] = {"exec.poststart", PF_INTERNAL},
73 [IP_EXEC_POSTSTOP] = {"exec.poststop", PF_INTERNAL},
74 [IP_EXEC_PREPARE] = {"exec.prepare", PF_INTERNAL},
75 [IP_EXEC_PRESTART] = {"exec.prestart", PF_INTERNAL},
76 [IP_EXEC_PRESTOP] = {"exec.prestop", PF_INTERNAL},
77 [IP_EXEC_RELEASE] = {"exec.release", PF_INTERNAL},
78 [IP_EXEC_CREATED] = {"exec.created", PF_INTERNAL},
79 [IP_EXEC_START] = {"exec.start", PF_INTERNAL},
80 [IP_EXEC_STOP] = {"exec.stop", PF_INTERNAL},
81 [IP_EXEC_SYSTEM_JAIL_USER]= {"exec.system_jail_user",
82 PF_INTERNAL | PF_BOOL},
83 [IP_EXEC_SYSTEM_USER] = {"exec.system_user", PF_INTERNAL},
84 [IP_EXEC_TIMEOUT] = {"exec.timeout", PF_INTERNAL | PF_INT},
85 #if defined(INET) || defined(INET6)
86 [IP_INTERFACE] = {"interface", PF_INTERNAL},
87 [IP_IP_HOSTNAME] = {"ip_hostname", PF_INTERNAL | PF_BOOL},
89 [IP_MOUNT] = {"mount", PF_INTERNAL | PF_REV},
90 [IP_MOUNT_DEVFS] = {"mount.devfs", PF_INTERNAL | PF_BOOL},
91 [IP_MOUNT_FDESCFS] = {"mount.fdescfs", PF_INTERNAL | PF_BOOL},
92 [IP_MOUNT_PROCFS] = {"mount.procfs", PF_INTERNAL | PF_BOOL},
93 [IP_MOUNT_FSTAB] = {"mount.fstab", PF_INTERNAL},
94 [IP_STOP_TIMEOUT] = {"stop.timeout", PF_INTERNAL | PF_INT},
95 [IP_VNET_INTERFACE] = {"vnet.interface", PF_INTERNAL},
97 [IP__IP4_IFADDR] = {"ip4.addr", PF_INTERNAL | PF_CONV | PF_REV},
100 [IP__IP6_IFADDR] = {"ip6.addr", PF_INTERNAL | PF_CONV | PF_REV},
102 [IP__MOUNT_FROM_FSTAB] = {"mount.fstab", PF_INTERNAL | PF_CONV | PF_REV},
103 [IP__OP] = {NULL, PF_CONV},
104 [KP_ALLOW_CHFLAGS] = {"allow.chflags", 0},
105 [KP_ALLOW_MOUNT] = {"allow.mount", 0},
106 [KP_ALLOW_RAW_SOCKETS] = {"allow.raw_sockets", 0},
107 [KP_ALLOW_SET_HOSTNAME]= {"allow.set_hostname", 0},
108 [KP_ALLOW_SOCKET_AF] = {"allow.socket_af", 0},
109 [KP_ALLOW_SYSVIPC] = {"allow.sysvipc", 0},
110 [KP_DEVFS_RULESET] = {"devfs_ruleset", 0},
111 [KP_HOST_HOSTNAME] = {"host.hostname", 0},
113 [KP_IP4_ADDR] = {"ip4.addr", 0},
116 [KP_IP6_ADDR] = {"ip6.addr", 0},
118 [KP_JID] = {"jid", PF_IMMUTABLE},
119 [KP_NAME] = {"name", PF_IMMUTABLE},
120 [KP_PATH] = {"path", 0},
121 [KP_PERSIST] = {"persist", 0},
122 [KP_SECURELEVEL] = {"securelevel", 0},
123 [KP_VNET] = {"vnet", 0},
127 * Parse the jail configuration file.
130 load_config(const char *cfname)
134 struct cfjail *j, *tj, *wj;
135 struct cfparam *p, *vp, *tp;
136 struct cfstring *s, *vs, *ns;
137 struct cfvar *v, *vv;
139 int did_self, jseq, pgen;
141 parse_config(cfname, !strcmp(cfname, "-"));
143 /* Separate the wildcard jails out from the actual jails. */
146 TAILQ_FOREACH_SAFE(j, &cfjails, tq, tj) {
148 if (wild_jail_name(j->name))
152 TAILQ_FOREACH(j, &cfjails, tq) {
153 /* Set aside the jail's parameters. */
155 TAILQ_CONCAT(&opp, &j->params, tq);
157 * The jail name implies its "name" or "jid" parameter,
158 * though they may also be explicitly set later on.
161 strtol(j->name, &ep, 10) && !*ep ? KP_JID : KP_NAME,
164 * Collect parameters for the jail, global parameters/variables,
165 * and any matching wildcard jails.
168 TAILQ_FOREACH(wj, &wild, tq) {
169 if (j->seq < wj->seq && !did_self) {
170 TAILQ_FOREACH(p, &opp, tq)
171 add_param(j, p, 0, NULL);
174 if (wild_jail_match(j->name, wj->name))
175 TAILQ_FOREACH(p, &wj->params, tq)
176 add_param(j, p, 0, NULL);
179 TAILQ_FOREACH(p, &opp, tq)
180 add_param(j, p, 0, NULL);
182 /* Resolve any variable substitutions. */
184 TAILQ_FOREACH(p, &j->params, tq) {
187 TAILQ_FOREACH(s, &p->val, tq) {
188 while ((v = STAILQ_FIRST(&s->vars))) {
189 TAILQ_FOREACH(vp, &j->params, tq)
190 if (!strcmp(vp->name, v->name))
192 if (!vp || TAILQ_EMPTY(&vp->val)) {
194 "%s: variable \"%s\" not found",
197 j->flags |= JF_FAILED;
198 TAILQ_FOREACH(vp, &j->params, tq)
203 if (vp->flags & PF_BAD)
205 if (vp->gen == pgen) {
206 jail_warnx(j, "%s: variable loop",
210 TAILQ_FOREACH(vs, &vp->val, tq)
211 if (!STAILQ_EMPTY(&vs->vars)) {
213 TAILQ_REMOVE(&j->params, vp,
215 TAILQ_INSERT_BEFORE(p, vp, tq);
219 vs = TAILQ_FIRST(&vp->val);
220 if (TAILQ_NEXT(vs, tq) != NULL &&
222 STAILQ_NEXT(v, tq))) {
223 jail_warnx(j, "%s: array cannot be "
224 "substituted inline",
228 s->s = erealloc(s->s, s->len + vs->len + 1);
229 memmove(s->s + v->pos + vs->len,
231 s->len - v->pos + 1);
232 memcpy(s->s + v->pos, vs->s, vs->len);
234 while ((vv = STAILQ_NEXT(vv, tq)))
237 while ((vs = TAILQ_NEXT(vs, tq))) {
238 ns = emalloc(sizeof(struct cfstring));
239 ns->s = estrdup(vs->s);
241 STAILQ_INIT(&ns->vars);
242 TAILQ_INSERT_AFTER(&p->val, s, ns, tq);
247 STAILQ_REMOVE_HEAD(&s->vars, tq);
253 /* Free the jail's original parameter list and any variables. */
254 while ((p = TAILQ_FIRST(&opp)))
256 TAILQ_FOREACH_SAFE(p, &j->params, tq, tp)
257 if (p->flags & PF_VAR)
258 free_param(&j->params, p);
260 while ((wj = TAILQ_FIRST(&wild))) {
262 while ((p = TAILQ_FIRST(&wj->params)))
263 free_param(&wj->params, p);
264 TAILQ_REMOVE(&wild, wj, tq);
269 include_config(void *scanner, const char *cfname)
271 static unsigned int depth;
274 char *fullpath = NULL;
276 /* Simple sanity check for include loops. */
277 if (++depth > MAX_INCLUDE_DEPTH)
278 errx(1, "maximum include depth exceeded");
279 /* Base relative pathnames on the current config file. */
280 if (yyget_in(scanner) != stdin && cfname[0] != '/') {
281 const char *outer_cfname = yyget_extra(scanner)->cfname;
282 if ((slash = strrchr(outer_cfname, '/')) != NULL) {
283 size_t dirlen = (slash - outer_cfname) + 1;
285 fullpath = emalloc(dirlen + strlen(cfname) + 1);
286 strncpy(fullpath, outer_cfname, dirlen);
287 strcpy(fullpath + dirlen, cfname);
292 * Check if the include statement had a filename glob.
293 * Globbing doesn't need to catch any files, but a non-glob
294 * file needs to exist (enforced by parse_config).
296 if (glob(cfname, GLOB_NOCHECK, NULL, &g) != 0)
297 errx(1, "%s: filename glob failed", cfname);
298 if (g.gl_flags & GLOB_MAGCHAR) {
299 for (size_t gi = 0; gi < g.gl_matchc; gi++)
300 parse_config(g.gl_pathv[gi], 0);
302 parse_config(cfname, 0);
309 parse_config(const char *cfname, int is_stdin)
311 struct cflex cflex = {.cfname = cfname, .error = 0};
314 yylex_init_extra(&cflex, &scanner);
316 cflex.cfname = "STDIN";
317 yyset_in(stdin, scanner);
319 FILE *yfp = fopen(cfname, "r");
321 err(1, "%s", cfname);
322 yyset_in(yfp, scanner);
324 if (yyparse(scanner) || cflex.error)
326 yylex_destroy(scanner);
330 * Create a new jail record.
337 j = emalloc(sizeof(struct cfjail));
338 memset(j, 0, sizeof(struct cfjail));
339 TAILQ_INIT(&j->params);
340 STAILQ_INIT(&j->dep[DEP_FROM]);
341 STAILQ_INIT(&j->dep[DEP_TO]);
343 TAILQ_INSERT_TAIL(&cfjails, j, tq);
348 * Add a parameter to a jail.
351 add_param(struct cfjail *j, const struct cfparam *p, enum intparam ipnum,
354 struct cfstrings nss;
355 struct cfparam *dp, *np;
356 struct cfstring *s, *ns;
357 struct cfvar *v, *nv;
363 /* Create a single anonymous jail if one doesn't yet exist. */
364 j = TAILQ_LAST(&cfjails, cfjails);
373 * Make a copy of the parameter's string list,
374 * which may be freed if it's overridden later.
376 TAILQ_FOREACH(s, &p->val, tq) {
377 ns = emalloc(sizeof(struct cfstring));
378 ns->s = estrdup(s->s);
380 STAILQ_INIT(&ns->vars);
381 STAILQ_FOREACH(v, &s->vars, tq) {
382 nv = emalloc(sizeof(struct cfvar));
383 nv->name = strdup(v->name);
385 STAILQ_INSERT_TAIL(&ns->vars, nv, tq);
387 TAILQ_INSERT_TAIL(&nss, ns, tq);
391 if (ipnum != IP__NULL) {
392 name = intparams[ipnum].name;
393 flags |= intparams[ipnum].flags;
394 } else if ((cs = strchr(value, '='))) {
395 tname = alloca(cs - value + 1);
396 strlcpy(tname, value, cs - value + 1);
404 ns = emalloc(sizeof(struct cfstring));
405 ns->s = estrdup(value);
406 ns->len = strlen(value);
407 STAILQ_INIT(&ns->vars);
408 TAILQ_INSERT_TAIL(&nss, ns, tq);
412 /* See if this parameter has already been added. */
413 if (ipnum != IP__NULL)
414 dp = j->intparams[ipnum];
416 TAILQ_FOREACH(dp, &j->params, tq)
417 if (!(dp->flags & PF_CONV) && equalopts(dp->name, name))
420 /* Found it - append or replace. */
421 if ((flags ^ dp->flags) & PF_VAR) {
422 jail_warnx(j, "variable \"$%s\" cannot have the same "
423 "name as a parameter.", name);
424 j->flags |= JF_FAILED;
427 if (dp->flags & PF_IMMUTABLE) {
428 jail_warnx(j, "cannot redefine parameter \"%s\".",
430 j->flags |= JF_FAILED;
433 if (strcmp(dp->name, name)) {
435 dp->name = estrdup(name);
437 if (!(flags & PF_APPEND) || TAILQ_EMPTY(&nss))
438 free_param_strings(dp);
439 TAILQ_CONCAT(&dp->val, &nss, tq);
442 /* Not found - add it. */
443 np = emalloc(sizeof(struct cfparam));
444 np->name = estrdup(name);
445 TAILQ_INIT(&np->val);
446 TAILQ_CONCAT(&np->val, &nss, tq);
449 TAILQ_INSERT_TAIL(&j->params, np, tq);
450 if (ipnum != IP__NULL)
451 j->intparams[ipnum] = np;
453 for (ipnum = IP__NULL + 1; ipnum < IP_NPARAM; ipnum++)
454 if (!(intparams[ipnum].flags & PF_CONV) &&
455 equalopts(name, intparams[ipnum].name)) {
456 if (flags & PF_VAR) {
459 "cannot have the same "
460 "name as a parameter.",
462 j->flags |= JF_FAILED;
465 j->intparams[ipnum] = np;
466 np->flags |= intparams[ipnum].flags;
473 * Return if a boolean parameter exists and is true.
476 bool_param(const struct cfparam *p)
482 cs = strrchr(p->name, '.');
483 return !strncmp(cs ? cs + 1 : p->name, "no", 2) ^
484 (TAILQ_EMPTY(&p->val) ||
485 !strcasecmp(TAILQ_LAST(&p->val, cfstrings)->s, "true") ||
486 (strtol(TAILQ_LAST(&p->val, cfstrings)->s, NULL, 10)));
490 * Set an integer if a parameter if it exists.
493 int_param(const struct cfparam *p, int *ip)
495 if (p == NULL || TAILQ_EMPTY(&p->val))
497 *ip = strtol(TAILQ_LAST(&p->val, cfstrings)->s, NULL, 10);
502 * Return the string value of a scalar parameter if it exists.
505 string_param(const struct cfparam *p)
507 return (p && !TAILQ_EMPTY(&p->val)
508 ? TAILQ_LAST(&p->val, cfstrings)->s : NULL);
512 * Check syntax and values of internal parameters. Set some internal
513 * parameters based on the values of others.
516 check_intparams(struct cfjail *j)
525 #if defined(INET) || defined(INET6)
526 struct addrinfo hints;
527 struct addrinfo *ai0, *ai;
528 const char *hostname;
532 struct in_addr addr4;
534 char avalue4[INET_ADDRSTRLEN];
537 struct in6_addr addr6;
539 char avalue6[INET6_ADDRSTRLEN];
543 /* Check format of boolan and integer values. */
544 TAILQ_FOREACH(p, &j->params, tq) {
545 if (!TAILQ_EMPTY(&p->val) && (p->flags & (PF_BOOL | PF_INT))) {
546 val = TAILQ_LAST(&p->val, cfstrings)->s;
547 if (p->flags & PF_BOOL) {
548 if (strcasecmp(val, "false") &&
549 strcasecmp(val, "true") &&
550 ((void)strtol(val, &ep, 10), *ep)) {
552 "%s: unknown boolean value \"%s\"",
557 (void)strtol(val, &ep, 10);
558 if (ep == val || *ep) {
560 "%s: non-integer value \"%s\"",
568 #if defined(INET) || defined(INET6)
570 * The ip_hostname parameter looks up the hostname, and adds parameters
571 * for any IP addresses it finds.
573 if (((j->flags & JF_OP_MASK) != JF_STOP ||
574 j->intparams[IP_INTERFACE] != NULL) &&
575 bool_param(j->intparams[IP_IP_HOSTNAME]) &&
576 (hostname = string_param(j->intparams[KP_HOST_HOSTNAME]))) {
577 j->intparams[IP_IP_HOSTNAME] = NULL;
579 * Silently ignore unsupported address families from
583 ip4ok = feature_present("inet");
586 ip6ok = feature_present("inet6");
589 #if defined(INET) && defined(INET6)
597 /* Look up the hostname (or get the address) */
598 memset(&hints, 0, sizeof(hints));
599 hints.ai_socktype = SOCK_STREAM;
601 #if defined(INET) && defined(INET6)
602 ip4ok ? (ip6ok ? PF_UNSPEC : PF_INET) : PF_INET6;
608 gicode = getaddrinfo(hostname, NULL, &hints, &ai0);
610 jail_warnx(j, "host.hostname %s: %s", hostname,
611 gai_strerror(gicode));
615 * Convert the addresses to ASCII so jailparam
616 * can convert them back. Errors are not
619 for (ai = ai0; ai; ai = ai->ai_next)
620 switch (ai->ai_family) {
624 &((struct sockaddr_in *)
625 (void *)ai->ai_addr)->
626 sin_addr, sizeof(addr4));
627 if (inet_ntop(AF_INET,
629 INET_ADDRSTRLEN) == NULL)
631 add_param(j, NULL, KP_IP4_ADDR,
638 &((struct sockaddr_in6 *)
639 (void *)ai->ai_addr)->
640 sin6_addr, sizeof(addr6));
641 if (inet_ntop(AF_INET6,
643 INET6_ADDRSTRLEN) == NULL)
645 add_param(j, NULL, KP_IP6_ADDR,
656 * IP addresses may include an interface to set that address on,
657 * a netmask/suffix for that address and options for ifconfig.
658 * These are copied to an internal command parameter and then stripped
659 * so they won't be passed on to jailparam_set.
661 defif = string_param(j->intparams[IP_INTERFACE]) != NULL;
663 if (j->intparams[KP_IP4_ADDR] != NULL) {
664 TAILQ_FOREACH(s, &j->intparams[KP_IP4_ADDR]->val, tq) {
665 cs = strchr(s->s, '|');
667 add_param(j, NULL, IP__IP4_IFADDR, s->s);
669 s->len -= cs + 1 - s->s;
670 memmove(s->s, cs + 1, s->len + 1);
672 if ((cs = strchr(s->s, '/')) != NULL) {
676 if ((cs = strchr(s->s, ' ')) != NULL) {
684 if (j->intparams[KP_IP6_ADDR] != NULL) {
685 TAILQ_FOREACH(s, &j->intparams[KP_IP6_ADDR]->val, tq) {
686 cs = strchr(s->s, '|');
688 add_param(j, NULL, IP__IP6_IFADDR, s->s);
690 s->len -= cs + 1 - s->s;
691 memmove(s->s, cs + 1, s->len + 1);
693 if ((cs = strchr(s->s, '/')) != NULL) {
697 if ((cs = strchr(s->s, ' ')) != NULL) {
707 * Read mount.fstab file(s), and treat each line as its own mount
710 if (j->intparams[IP_MOUNT_FSTAB] != NULL) {
711 TAILQ_FOREACH(s, &j->intparams[IP_MOUNT_FSTAB]->val, tq) {
714 f = fopen(s->s, "r");
716 jail_warnx(j, "mount.fstab: %s: %s",
717 s->s, strerror(errno));
721 while ((ln = fgetln(f, &lnlen))) {
722 if ((cs = memchr(ln, '#', lnlen - 1)))
724 if (ln[lnlen - 1] == '\n' ||
725 ln[lnlen - 1] == '#')
726 ln[lnlen - 1] = '\0';
728 cs = alloca(lnlen + 1);
729 strlcpy(cs, ln, lnlen + 1);
732 add_param(j, NULL, IP__MOUNT_FROM_FSTAB, ln);
743 * Import parameters into libjail's binary jailparam format.
746 import_params(struct cfjail *j)
749 struct cfstring *s, *ts;
750 struct jailparam *jp;
757 TAILQ_FOREACH(p, &j->params, tq)
758 if (!(p->flags & PF_INTERNAL))
760 j->jp = jp = emalloc(j->njp * sizeof(struct jailparam));
761 TAILQ_FOREACH(p, &j->params, tq) {
762 if (p->flags & PF_INTERNAL)
764 if (jailparam_init(jp, p->name) < 0) {
766 jail_warnx(j, "%s", jail_errmsg);
770 if (TAILQ_EMPTY(&p->val))
772 else if (!jp->jp_elemlen ||
773 !TAILQ_NEXT(TAILQ_FIRST(&p->val), tq)) {
775 * Scalar parameters silently discard multiple (array)
776 * values, keeping only the last value added. This
777 * lets values added from the command line append to
778 * arrays wthout pre-checking the type.
780 value = TAILQ_LAST(&p->val, cfstrings)->s;
783 * Convert arrays into comma-separated strings, which
784 * jailparam_import will then convert back into arrays.
787 TAILQ_FOREACH(s, &p->val, tq)
788 vallen += s->len + 1;
789 value = alloca(vallen);
791 TAILQ_FOREACH_SAFE(s, &p->val, tq, ts) {
792 memcpy(cs, s->s, s->len);
796 value[vallen - 1] = '\0';
798 if (jailparam_import(jp, value) < 0) {
800 jail_warnx(j, "%s", jail_errmsg);
805 jailparam_free(j->jp, j->njp);
814 * Check if options are equal (with or without the "no" prefix).
817 equalopts(const char *opt1, const char *opt2)
821 /* "opt" vs. "opt" or "noopt" vs. "noopt" */
822 if (strcmp(opt1, opt2) == 0)
824 /* "noopt" vs. "opt" */
825 if (strncmp(opt1, "no", 2) == 0 && strcmp(opt1 + 2, opt2) == 0)
827 /* "opt" vs. "noopt" */
828 if (strncmp(opt2, "no", 2) == 0 && strcmp(opt1, opt2 + 2) == 0)
830 while ((p = strchr(opt1, '.')) != NULL &&
831 !strncmp(opt1, opt2, ++p - opt1)) {
834 /* "foo.noopt" vs. "foo.opt" */
835 if (strncmp(opt1, "no", 2) == 0 && strcmp(opt1 + 2, opt2) == 0)
837 /* "foo.opt" vs. "foo.noopt" */
838 if (strncmp(opt2, "no", 2) == 0 && strcmp(opt1, opt2 + 2) == 0)
845 * See if a jail name matches a wildcard.
848 wild_jail_match(const char *jname, const char *wname)
850 const char *jc, *jd, *wc, *wd;
853 * A non-final "*" component in the wild name matches a single jail
854 * component, and a final "*" matches one or more jail components.
856 for (jc = jname, wc = wname;
857 (jd = strchr(jc, '.')) && (wd = strchr(wc, '.'));
858 jc = jd + 1, wc = wd + 1)
859 if (strncmp(jc, wc, jd - jc + 1) && strncmp(wc, "*.", 2))
861 return (!strcmp(jc, wc) || !strcmp(wc, "*"));
865 * Return if a jail name is a wildcard.
868 wild_jail_name(const char *wname)
872 for (wc = strchr(wname, '*'); wc; wc = strchr(wc + 1, '*'))
873 if ((wc == wname || wc[-1] == '.') &&
874 (wc[1] == '\0' || wc[1] == '.'))
880 * Free a parameter record and all its strings and variables.
883 free_param(struct cfparams *pp, struct cfparam *p)
886 free_param_strings(p);
887 TAILQ_REMOVE(pp, p, tq);
892 free_param_strings(struct cfparam *p)
897 while ((s = TAILQ_FIRST(&p->val))) {
899 while ((v = STAILQ_FIRST(&s->vars))) {
901 STAILQ_REMOVE_HEAD(&s->vars, tq);
904 TAILQ_REMOVE(&p->val, s, tq);