Index: stable/11/etc/mtree/BSD.tests.dist =================================================================== --- stable/11/etc/mtree/BSD.tests.dist (revision 352560) +++ stable/11/etc/mtree/BSD.tests.dist (revision 352561) @@ -1,770 +1,772 @@ # $FreeBSD$ # # Please see the file src/etc/mtree/README before making changes to this file. # /set type=dir uname=root gname=wheel mode=0755 . bin cat .. chflags .. chmod .. date .. dd .. echo .. expr .. ln .. ls .. mkdir .. mv .. pax .. pkill .. pwait .. rcp .. rmdir .. sh builtins .. errors .. execution .. expansion .. parameters .. parser .. set-e .. .. sleep .. test .. .. cddl lib .. sbin .. usr.bin ctfconvert .. .. usr.sbin dtrace common aggs .. arithmetic .. arrays .. assocs .. begin .. bitfields .. buffering .. builtinvar .. cg .. clauses .. cpc .. decls .. drops .. dtraceUtil .. end .. enum .. error .. exit .. fbtprovider .. funcs .. grammar .. include .. inline .. io .. ip .. java_api .. json .. lexer .. llquantize .. mdb .. mib .. misc .. multiaggs .. offsetof .. operators .. pid .. plockstat .. pointers .. pragma .. predicates .. preprocessor .. print .. printa .. printf .. privs .. probes .. proc .. profile-n .. providers .. raise .. rates .. safety .. scalars .. sched .. scripting .. sdt .. sizeof .. speculation .. stability .. stack .. stackdepth .. stop .. strlen .. strtoll .. struct .. syscall .. sysevent .. tick-n .. trace .. tracemem .. translators .. typedef .. types .. uctf .. union .. usdt .. ustack .. vars .. version .. .. .. zfsd .. .. .. etc rc.d .. .. games .. gnu lib .. usr.bin diff .. .. .. lib atf libatf-c detail .. .. libatf-c++ detail .. .. test-programs .. .. libarchive .. libbe .. libc c063 .. db .. gen execve .. posix_spawn .. .. hash data .. .. iconv .. inet .. locale .. net getaddrinfo data .. .. .. nss .. regex data .. .. resolv .. rpc .. ssp .. setjmp .. stdio .. stdlib .. string .. sys .. time .. tls dso .. .. termios .. ttyio .. .. libcam .. libcasper services cap_dns .. cap_grp .. cap_pwd .. cap_sysctl .. .. .. libcrypt .. libdevdctl .. libkvm .. libmp .. libnv .. libpam .. libproc .. librt .. libsbuf .. libthr dlopen .. .. libutil .. libxo .. msun .. .. libexec atf atf-check .. atf-sh .. .. rtld-elf .. tftpd .. .. sbin bectl .. dhclient .. devd .. growfs .. ifconfig .. mdconfig .. .. secure lib .. libexec .. usr.bin .. usr.sbin .. .. share examples tests atf .. plain .. tap .. .. .. zoneinfo .. .. sys acl .. aio .. audit .. auditpipe .. capsicum .. fifo .. file .. fs tmpfs .. .. geom class concat .. eli .. gate .. gpt .. mirror .. nop .. part .. raid3 .. shsec .. stripe .. uzip etalon .. .. .. .. kern acct .. execve .. pipe .. .. kqueue libkqueue .. .. mac bsdextended .. portacl .. .. mqueue .. net .. netinet .. netmap .. opencrypto .. pjdfstest chflags .. chmod .. chown .. ftruncate .. granular .. link .. mkdir .. mkfifo .. mknod .. open .. rename .. rmdir .. symlink .. truncate .. unlink .. .. posixshm .. sys .. vfs .. vm .. .. usr.bin apply .. basename .. bmake archives fmt_44bsd .. fmt_44bsd_mod .. fmt_oldbsd .. .. basic t0 .. t1 .. t2 .. t3 .. .. execution ellipsis .. empty .. joberr .. plus .. .. shell builtin .. meta .. path .. path_select .. replace .. select .. .. suffixes basic .. src_wild1 .. src_wild2 .. .. syntax directive-t0 .. enl .. funny-targets .. semi .. .. sysmk t0 2 1 .. .. mk .. .. t1 2 1 .. .. mk .. .. t2 2 1 .. .. mk .. .. .. variables modifier_M .. modifier_t .. opt_V .. t0 .. .. .. bsdcat .. calendar .. cmp .. compress .. cpio .. col .. comm .. cut .. dirname .. du .. file2c .. fold .. getconf .. grep .. gzip .. head .. hexdump .. ident .. indent .. join .. jot .. lastcomm .. limits .. m4 .. mkimg .. ncal .. opensm .. pr .. printf .. procstat .. rs .. sdiff .. sed regress.multitest.out .. .. seq .. soelim .. stat .. tail .. tar .. timeout .. tr .. truncate .. units .. uudecode .. uuencode .. uniq .. xargs .. xinstall .. xo .. yacc yacc .. .. .. usr.sbin chown .. etcupdate .. extattr .. fstyp .. + jail + .. makefs .. newsyslog .. nmtree .. praudit .. pw .. rpcbind .. sa .. .. .. # vim: set expandtab ts=4 sw=4: Index: stable/11/usr.sbin/jail/Makefile =================================================================== --- stable/11/usr.sbin/jail/Makefile (revision 352560) +++ stable/11/usr.sbin/jail/Makefile (revision 352561) @@ -1,27 +1,30 @@ # $FreeBSD$ .include PROG= jail MAN= jail.8 jail.conf.5 SRCS= jail.c command.c config.c state.c jailp.h jaillex.l jailparse.y y.tab.h LIBADD= jail kvm util PACKAGE=jail NO_WMISSING_VARIABLE_DECLARATIONS= YFLAGS+=-v CFLAGS+=-I. -I${.CURDIR} .if ${MK_INET6_SUPPORT} != "no" CFLAGS+= -DINET6 .endif .if ${MK_INET_SUPPORT} != "no" CFLAGS+= -DINET .endif CLEANFILES= y.output +HAS_TESTS= +SUBDIR.${MK_TESTS}+= tests + .include Index: stable/11/usr.sbin/jail/state.c =================================================================== --- stable/11/usr.sbin/jail/state.c (revision 352560) +++ stable/11/usr.sbin/jail/state.c (revision 352561) @@ -1,478 +1,494 @@ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2011 James Gritton * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include "jailp.h" struct cfjails ready = TAILQ_HEAD_INITIALIZER(ready); struct cfjails depend = TAILQ_HEAD_INITIALIZER(depend); static void dep_add(struct cfjail *from, struct cfjail *to, unsigned flags); static int cmp_jailptr(const void *a, const void *b); static int cmp_jailptr_name(const void *a, const void *b); static struct cfjail *find_jail(const char *name); -static int running_jid(const char *name, int flags); +static struct cfjail *running_jail(const char *name, int flags); static struct cfjail **jails_byname; static size_t njails; /* * Set up jail dependency lists. */ void dep_setup(int docf) { struct cfjail *j, *dj; struct cfparam *p; struct cfstring *s; struct cfdepend *d; const char *cs; char *pname; size_t plen; int deps, ldeps; if (!docf) { /* * With no config file, let "depend" for a single jail * look at currently running jails. */ if ((j = TAILQ_FIRST(&cfjails)) && (p = j->intparams[IP_DEPEND])) { TAILQ_FOREACH(s, &p->val, tq) { - if (running_jid(s->s, 0) < 0) { + if (running_jail(s->s, 0) == NULL) { warnx("depends on nonexistent jail " "\"%s\"", s->s); j->flags |= JF_FAILED; } } } return; } njails = 0; TAILQ_FOREACH(j, &cfjails, tq) njails++; jails_byname = emalloc(njails * sizeof(struct cfjail *)); njails = 0; TAILQ_FOREACH(j, &cfjails, tq) jails_byname[njails++] = j; qsort(jails_byname, njails, sizeof(struct cfjail *), cmp_jailptr); deps = 0; ldeps = 0; plen = 0; pname = NULL; TAILQ_FOREACH(j, &cfjails, tq) { if (j->flags & JF_FAILED) continue; if ((p = j->intparams[IP_DEPEND])) { TAILQ_FOREACH(s, &p->val, tq) { dj = find_jail(s->s); if (dj != NULL) { deps++; dep_add(j, dj, 0); } else { jail_warnx(j, "depends on undefined jail \"%s\"", s->s); j->flags |= JF_FAILED; } } } /* A jail has an implied dependency on its parent. */ if ((cs = strrchr(j->name, '.'))) { if (plen < (size_t)(cs - j->name + 1)) { plen = (cs - j->name) + 1; pname = erealloc(pname, plen); } strlcpy(pname, j->name, plen); dj = find_jail(pname); if (dj != NULL) { ldeps++; dep_add(j, dj, DF_LIGHT); } } } /* Look for dependency loops. */ if (deps && (deps > 1 || ldeps)) { (void)start_state(NULL, 0, 0, 0); while ((j = TAILQ_FIRST(&ready))) { requeue(j, &cfjails); dep_done(j, DF_NOFAIL); } while ((j = TAILQ_FIRST(&depend)) != NULL) { jail_warnx(j, "dependency loop"); j->flags |= JF_FAILED; do { requeue(j, &cfjails); dep_done(j, DF_NOFAIL); } while ((j = TAILQ_FIRST(&ready))); } TAILQ_FOREACH(j, &cfjails, tq) STAILQ_FOREACH(d, &j->dep[DEP_FROM], tq[DEP_FROM]) d->flags &= ~DF_SEEN; } if (pname != NULL) free(pname); } /* * Return if a jail has dependencies. */ int dep_check(struct cfjail *j) { int reset, depfrom, depto, ndeps, rev; struct cfjail *dj; struct cfdepend *d; static int bits[] = { 0, 1, 1, 2, 1, 2, 2, 3 }; if (j->ndeps == 0) return 0; ndeps = 0; if ((rev = JF_DO_STOP(j->flags))) { depfrom = DEP_TO; depto = DEP_FROM; } else { depfrom = DEP_FROM; depto = DEP_TO; } STAILQ_FOREACH(d, &j->dep[depfrom], tq[depfrom]) { if (d->flags & DF_SEEN) continue; dj = d->j[depto]; if (dj->flags & JF_FAILED) { if (!(j->flags & (JF_DEPEND | JF_FAILED)) && verbose >= 0) jail_warnx(j, "skipped"); j->flags |= JF_FAILED; continue; } /* * The dependee's state may be set (or changed) as a result of * being in a dependency it wasn't in earlier. */ reset = 0; if (bits[dj->flags & JF_OP_MASK] <= 1) { if (!(dj->flags & JF_OP_MASK)) { reset = 1; dj->flags |= JF_DEPEND; requeue(dj, &ready); } /* Set or change the dependee's state. */ switch (j->flags & JF_OP_MASK) { case JF_START: dj->flags |= JF_START; break; case JF_SET: if (!(dj->flags & JF_OP_MASK)) dj->flags |= JF_SET; else if (dj->flags & JF_STOP) dj->flags |= JF_START; break; case JF_STOP: case JF_RESTART: if (!(dj->flags & JF_STOP)) reset = 1; dj->flags |= JF_STOP; if (dj->flags & JF_SET) dj->flags ^= (JF_START | JF_SET); break; } } if (reset) dep_reset(dj); if (!((d->flags & DF_LIGHT) && (rev ? dj->jid < 0 : dj->jid > 0))) ndeps++; } if (ndeps == 0) return 0; requeue(j, &depend); return 1; } /* * Resolve any dependencies from a finished jail. */ void dep_done(struct cfjail *j, unsigned flags) { struct cfjail *dj; struct cfdepend *d; int depfrom, depto; if (JF_DO_STOP(j->flags)) { depfrom = DEP_TO; depto = DEP_FROM; } else { depfrom = DEP_FROM; depto = DEP_TO; } STAILQ_FOREACH(d, &j->dep[depto], tq[depto]) { if ((d->flags & DF_SEEN) | (flags & ~d->flags & DF_LIGHT)) continue; d->flags |= DF_SEEN; dj = d->j[depfrom]; if (!(flags & DF_NOFAIL) && (j->flags & JF_FAILED) && (j->flags & (JF_OP_MASK | JF_DEPEND)) != (JF_SET | JF_DEPEND)) { if (!(dj->flags & (JF_DEPEND | JF_FAILED)) && verbose >= 0) jail_warnx(dj, "skipped"); dj->flags |= JF_FAILED; } if (!--dj->ndeps && dj->queue == &depend) requeue(dj, &ready); } } /* * Count a jail's dependencies and mark them as unseen. */ void dep_reset(struct cfjail *j) { int depfrom; struct cfdepend *d; depfrom = JF_DO_STOP(j->flags) ? DEP_TO : DEP_FROM; j->ndeps = 0; STAILQ_FOREACH(d, &j->dep[depfrom], tq[depfrom]) j->ndeps++; } /* * Find the next jail ready to do something. */ struct cfjail * next_jail(void) { struct cfjail *j; if (!(j = next_proc(!TAILQ_EMPTY(&ready))) && (j = TAILQ_FIRST(&ready)) && JF_DO_STOP(j->flags) && (j = TAILQ_LAST(&ready, cfjails)) && !JF_DO_STOP(j->flags)) { TAILQ_FOREACH_REVERSE(j, &ready, cfjails, tq) if (JF_DO_STOP(j->flags)) break; } if (j != NULL) requeue(j, &cfjails); return j; } /* * Set jails to the proper start state. */ int start_state(const char *target, int docf, unsigned state, int running) { struct iovec jiov[6]; struct cfjail *j, *tj; int jid; char namebuf[MAXHOSTNAMELEN]; if (!target || (!docf && state != JF_STOP) || (!running && !strcmp(target, "*"))) { /* * For a global wildcard (including no target specified), * set the state on all jails and start with those that * have no dependencies. */ TAILQ_FOREACH_SAFE(j, &cfjails, tq, tj) { j->flags = (j->flags & JF_FAILED) | state | (docf ? JF_WILD : 0); dep_reset(j); requeue(j, j->ndeps ? &depend : &ready); } } else if (wild_jail_name(target)) { /* * For targets specified singly, or with a non-global wildcard, * set their state and call them ready (even if there are * dependencies). Leave everything else unqueued for now. */ if (running) { /* * -R matches its wildcards against currently running * jails, not against the config file. */ jiov[0].iov_base = __DECONST(char *, "lastjid"); jiov[0].iov_len = sizeof("lastjid"); jiov[1].iov_base = &jid; jiov[1].iov_len = sizeof(jid); jiov[2].iov_base = __DECONST(char *, "jid"); jiov[2].iov_len = sizeof("jid"); jiov[3].iov_base = &jid; jiov[3].iov_len = sizeof(jid); jiov[4].iov_base = __DECONST(char *, "name"); jiov[4].iov_len = sizeof("name"); jiov[5].iov_base = &namebuf; jiov[5].iov_len = sizeof(namebuf); for (jid = 0; jail_get(jiov, 6, 0) > 0; ) { if (wild_jail_match(namebuf, target)) { j = add_jail(); j->name = estrdup(namebuf); j->jid = jid; j->flags = (j->flags & JF_FAILED) | state | JF_WILD; dep_reset(j); requeue(j, &ready); } } } else { TAILQ_FOREACH_SAFE(j, &cfjails, tq, tj) { if (wild_jail_match(j->name, target)) { j->flags = (j->flags & JF_FAILED) | state | JF_WILD; dep_reset(j); requeue(j, &ready); } } } } else { j = find_jail(target); if (j == NULL && state == JF_STOP) { /* Allow -[rR] to specify a currently running jail. */ - if ((jid = running_jid(target, JAIL_DYING)) > 0) { - j = add_jail(); - j->name = estrdup(target); - j->jid = jid; - } + j = running_jail(target, JAIL_DYING); } if (j == NULL) { warnx("\"%s\" not found", target); return -1; } j->flags = (j->flags & JF_FAILED) | state; dep_reset(j); requeue(j, &ready); } return 0; } /* * Move a jail to a new list. */ void requeue(struct cfjail *j, struct cfjails *queue) { if (j->queue != queue) { TAILQ_REMOVE(j->queue, j, tq); TAILQ_INSERT_TAIL(queue, j, tq); j->queue = queue; } } void requeue_head(struct cfjail *j, struct cfjails *queue) { TAILQ_REMOVE(j->queue, j, tq); TAILQ_INSERT_HEAD(queue, j, tq); j->queue = queue; } /* * Add a dependency edge between two jails. */ static void dep_add(struct cfjail *from, struct cfjail *to, unsigned flags) { struct cfdepend *d; d = emalloc(sizeof(struct cfdepend)); d->flags = flags; d->j[DEP_FROM] = from; d->j[DEP_TO] = to; STAILQ_INSERT_TAIL(&from->dep[DEP_FROM], d, tq[DEP_FROM]); STAILQ_INSERT_TAIL(&to->dep[DEP_TO], d, tq[DEP_TO]); } /* * Compare jail pointers for qsort/bsearch. */ static int cmp_jailptr(const void *a, const void *b) { return strcmp((*((struct cfjail * const *)a))->name, ((*(struct cfjail * const *)b))->name); } static int cmp_jailptr_name(const void *a, const void *b) { return strcmp((const char *)a, ((*(struct cfjail * const *)b))->name); } /* * Find a jail object by name. */ static struct cfjail * find_jail(const char *name) { struct cfjail **jp; + + if (jails_byname == NULL) + return NULL; jp = bsearch(name, jails_byname, njails, sizeof(struct cfjail *), cmp_jailptr_name); return jp ? *jp : NULL; } /* - * Return the named jail's jid if it is running, and -1 if it isn't. + * Return jail if it is running, and NULL if it isn't. */ -static int -running_jid(const char *name, int flags) +static struct cfjail * +running_jail(const char *name, int flags) { - struct iovec jiov[2]; + struct iovec jiov[4]; + struct cfjail *jail; char *ep; - int jid; - + char jailname[MAXHOSTNAMELEN]; + int jid, ret, len; + if ((jid = strtol(name, &ep, 10)) && !*ep) { - jiov[0].iov_base = __DECONST(char *, "jid"); - jiov[0].iov_len = sizeof("jid"); - jiov[1].iov_base = &jid; - jiov[1].iov_len = sizeof(jid); + memset(jailname,0,sizeof(jailname)); + len = sizeof(jailname); } else { - jiov[0].iov_base = __DECONST(char *, "name"); - jiov[0].iov_len = sizeof("name"); - jiov[1].iov_len = strlen(name) + 1; - jiov[1].iov_base = alloca(jiov[1].iov_len); - strcpy(jiov[1].iov_base, name); + strncpy(jailname, name,sizeof(jailname)); + len = strlen(name) + 1; + jid = 0; } - return jail_get(jiov, 2, flags); + + jiov[0].iov_base = __DECONST(char *, "jid"); + jiov[0].iov_len = sizeof("jid"); + jiov[1].iov_base = &jid; + jiov[1].iov_len = sizeof(jid); + jiov[2].iov_base = __DECONST(char *, "name"); + jiov[2].iov_len = sizeof("name"); + jiov[3].iov_base = &jailname; + jiov[3].iov_len = len; + + if ((ret = jail_get(jiov, 4, flags)) < 0) + return (NULL); + + if ((jail = find_jail(jailname)) == NULL) { + jail = add_jail(); + jail->name = estrdup(jailname); + jail->jid = ret; + } + + return (jail); } Index: stable/11/usr.sbin/jail/tests/Makefile =================================================================== --- stable/11/usr.sbin/jail/tests/Makefile (nonexistent) +++ stable/11/usr.sbin/jail/tests/Makefile (revision 352561) @@ -0,0 +1,9 @@ +# $FreeBSD$ + +PACKAGE= tests + +ATF_TESTS_SH+= jail_basic_test + +${PACKAGE}FILES+= commands.jail.conf + +.include Property changes on: stable/11/usr.sbin/jail/tests/Makefile ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: stable/11/usr.sbin/jail/tests/commands.jail.conf =================================================================== --- stable/11/usr.sbin/jail/tests/commands.jail.conf (nonexistent) +++ stable/11/usr.sbin/jail/tests/commands.jail.conf (revision 352561) @@ -0,0 +1,7 @@ +# $FreeBSD$ + +exec.prestop = "echo STOP"; +exec.prestart = "echo START"; +persist; + +basejail {} Property changes on: stable/11/usr.sbin/jail/tests/commands.jail.conf ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: stable/11/usr.sbin/jail/tests/jail_basic_test.sh =================================================================== --- stable/11/usr.sbin/jail/tests/jail_basic_test.sh (nonexistent) +++ stable/11/usr.sbin/jail/tests/jail_basic_test.sh (revision 352561) @@ -0,0 +1,136 @@ +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Michael Zhilin +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. + +# $FreeBSD$ + +atf_test_case "basic" "cleanup" +atf_test_case "nested" "cleanup" +atf_test_case "commands" "cleanup" + +basic_head() +{ + atf_set descr 'Basic jail test' + atf_set require.user root +} + +basic_body() +{ + # Create the jail + atf_check -s exit:0 -o ignore jail -c name=basejail persist ip4.addr=192.0.1.1 + # Check output of jls + atf_check -s exit:0 -o ignore jls + atf_check -s exit:0 -o ignore jls -v + atf_check -s exit:0 -o ignore jls -n + # Stop jail + atf_check -s exit:0 -o ignore jail -r basejail + jail -c name=basejail persist ip4.addr=192.0.1.1 + # Stop jail by jid + atf_check -s exit:0 -o ignore jail -r `jls -j basejail jid` + # Recreate + atf_check -s exit:0 -o ignore jail -cm name=basejail persist ip4.addr=192.0.1.1 + # Restart + atf_check -s exit:0 -o ignore jail -rc name=basejail persist ip4.addr=192.0.1.1 +} + +basic_cleanup() +{ + jail -r basejail +} + +nested_head() +{ + atf_set descr 'Hierarchical jails test' + atf_set require.user root +} + +nested_body() +{ + # Create the first jail + jail -c name=basejail persist ip4.addr=192.0.1.1 children.max=1 + atf_check -s exit:0 -o empty \ + jexec basejail \ + jail -c name=nestedjail persist ip4.addr=192.0.1.1 + + atf_check -s exit:1 -o empty -e inline:"jail: prison limit exceeded\n"\ + jexec basejail \ + jail -c name=secondnestedjail persist ip4.addr=192.0.1.1 + # Check output of jls + atf_check -s exit:0 -o ignore \ + jexec basejail jls + atf_check -s exit:0 -o ignore \ + jexec basejail jls -v + atf_check -s exit:0 -o ignore \ + jexec basejail jls -n + # Create jail with no child - children.max should be 0 by default + jail -c name=basejail_nochild persist ip4.addr=192.0.1.1 + atf_check -s exit:1 -o empty \ + -e inline:"jail: jail_set: Operation not permitted\n" \ + jexec basejail_nochild \ + jail -c name=nestedjail persist ip4.addr=192.0.1.1 +} + +nested_cleanup() +{ + jail -r nestedjail + jail -r basejail + jail -r basejail_nochild +} + +commands_header() +{ + atf_set descr 'Commands jail test' + atf_set require.user root +} + +commands_body() +{ + # exec.prestart + atf_check -s exit:0 -o inline:"START\n" \ + jail -f $(atf_get_srcdir)/commands.jail.conf -qc basejail + # exec.prestop by jailname + atf_check -s exit:0 -o inline:"STOP\n" \ + jail -f $(atf_get_srcdir)/commands.jail.conf -qr basejail + # exec.prestop by jid + jail -f $(atf_get_srcdir)/commands.jail.conf -qc basejail + atf_check -s exit:0 -o inline:"STOP\n" \ + jail -f $(atf_get_srcdir)/commands.jail.conf -qr `jls -j basejail jid` +} + +commands_cleanup() +{ + jls -j basejail > /dev/null 2>&1 + if [ $? -e 0 ] + then + jail -r basejail + fi +} + +atf_init_test_cases() +{ + atf_add_test_case "basic" + atf_add_test_case "nested" + atf_add_test_case "commands" +} Property changes on: stable/11/usr.sbin/jail/tests/jail_basic_test.sh ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: stable/11 =================================================================== --- stable/11 (revision 352560) +++ stable/11 (revision 352561) Property changes on: stable/11 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head:r352263