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/cpuset.h>
31 #include <sys/event.h>
32 #include <sys/mount.h>
34 #include <sys/sysctl.h>
42 #include <login_cap.h>
54 #define DEFAULT_STOP_TIMEOUT 10
55 #define PHASH_SIZE 256
57 LIST_HEAD(phhead, phash);
67 extern char **environ;
69 static int run_command(struct cfjail *j);
70 static int add_proc(struct cfjail *j, pid_t pid);
71 static void clear_procs(struct cfjail *j);
72 static struct cfjail *find_proc(pid_t pid);
73 static int term_procs(struct cfjail *j);
74 static int get_user_info(struct cfjail *j, const char *username,
75 const struct passwd **pwdp, login_cap_t **lcapp);
76 static int check_path(struct cfjail *j, const char *pname, const char *path,
77 int isfile, const char *umount_type);
79 static struct cfjails sleeping = TAILQ_HEAD_INITIALIZER(sleeping);
80 static struct cfjails runnable = TAILQ_HEAD_INITIALIZER(runnable);
81 static struct cfstring dummystring = { .len = 1 };
82 static struct phhead phash[PHASH_SIZE];
88 static cpusetid_t setid = CPUSET_INVALID;
91 /* Only try to get the cpuset once. */
92 if (error == 0 && setid == CPUSET_INVALID)
93 error = cpuset_getid(CPU_LEVEL_ROOT, CPU_WHICH_PID, -1, &setid);
95 return (CPUSET_INVALID);
100 * Run the next command associated with a jail.
103 next_command(struct cfjail *j)
105 enum intparam comparam;
106 int create_failed, stopping;
108 if (paralimit == 0) {
109 if (j->flags & JF_FROM_RUNQ)
110 requeue_head(j, &runnable);
112 requeue(j, &runnable);
115 j->flags &= ~JF_FROM_RUNQ;
116 create_failed = (j->flags & (JF_STOP | JF_FAILED)) == JF_FAILED;
117 stopping = (j->flags & JF_STOP) != 0;
118 comparam = *j->comparam;
120 if (j->comstring == NULL) {
121 j->comparam += create_failed ? -1 : 1;
122 switch ((comparam = *j->comparam)) {
126 if (!bool_param(j->intparams[IP_MOUNT_DEVFS]))
128 j->comstring = &dummystring;
130 case IP_MOUNT_FDESCFS:
131 if (!bool_param(j->intparams[IP_MOUNT_FDESCFS]))
133 j->comstring = &dummystring;
135 case IP_MOUNT_PROCFS:
136 if (!bool_param(j->intparams[IP_MOUNT_PROCFS]))
138 j->comstring = &dummystring;
141 case IP_STOP_TIMEOUT:
142 j->comstring = &dummystring;
145 if (j->intparams[comparam] == NULL)
147 j->comstring = create_failed || (stopping &&
148 (j->intparams[comparam]->flags & PF_REV))
149 ? TAILQ_LAST(&j->intparams[comparam]->val,
151 : TAILQ_FIRST(&j->intparams[comparam]->val);
154 j->comstring = j->comstring == &dummystring ? NULL :
155 create_failed || (stopping &&
156 (j->intparams[comparam]->flags & PF_REV))
157 ? TAILQ_PREV(j->comstring, cfstrings, tq)
158 : TAILQ_NEXT(j->comstring, tq);
160 if (j->comstring == NULL || j->comstring->len == 0 ||
161 (create_failed && (comparam == IP_EXEC_PRESTART ||
162 comparam == IP_EXEC_CREATED || comparam == IP_EXEC_START ||
163 comparam == IP_COMMAND || comparam == IP_EXEC_POSTSTART ||
164 comparam == IP_EXEC_PREPARE)))
166 switch (run_command(j)) {
177 * Check command exit status
180 finish_command(struct cfjail *j)
185 if (!(j->flags & JF_SLEEPQ))
187 j->flags &= ~JF_SLEEPQ;
188 if (*j->comparam == IP_STOP_TIMEOUT) {
189 j->flags &= ~JF_TIMEOUT;
194 if (!TAILQ_EMPTY(&runnable)) {
195 rj = TAILQ_FIRST(&runnable);
196 rj->flags |= JF_FROM_RUNQ;
200 if (j->flags & JF_TIMEOUT) {
201 j->flags &= ~JF_TIMEOUT;
202 if (*j->comparam != IP_STOP_TIMEOUT) {
203 jail_warnx(j, "%s: timed out", j->comline);
206 } else if (verbose > 0)
207 jail_note(j, "timed out\n");
208 } else if (j->pstatus != 0) {
209 if (WIFSIGNALED(j->pstatus))
210 jail_warnx(j, "%s: exited on signal %d",
211 j->comline, WTERMSIG(j->pstatus));
213 jail_warnx(j, "%s: failed", j->comline);
224 * Check for finished processes or timeouts.
227 next_proc(int nonblock)
231 struct timespec *tsp;
234 if (!TAILQ_EMPTY(&sleeping)) {
237 if ((j = TAILQ_FIRST(&sleeping)) && j->timeout.tv_sec) {
238 clock_gettime(CLOCK_REALTIME, &ts);
239 ts.tv_sec = j->timeout.tv_sec - ts.tv_sec;
240 ts.tv_nsec = j->timeout.tv_nsec - ts.tv_nsec;
241 if (ts.tv_nsec < 0) {
243 ts.tv_nsec += 1000000000;
246 (ts.tv_sec == 0 && ts.tv_nsec == 0)) {
247 j->flags |= JF_TIMEOUT;
258 switch (kevent(kq, NULL, 0, &ke, 1, tsp)) {
265 j = TAILQ_FIRST(&sleeping);
266 j->flags |= JF_TIMEOUT;
272 (void)waitpid(ke.ident, NULL, WNOHANG);
273 if ((j = find_proc(ke.ident))) {
274 j->pstatus = ke.data;
284 * Run a single command for a jail, possibly inside the jail.
287 run_command(struct cfjail *j)
289 const struct passwd *pwd;
290 const struct cfstring *comstring, *s;
293 char *acs, *cs, *comcs, *devpath;
294 const char *jidstr, *conslog, *fmt, *path, *ruleset, *term, *username;
295 enum intparam comparam;
299 int argc, bg, clean, consfd, down, fib, i, injail, sjuser, timeout;
300 #if defined(INET) || defined(INET6)
301 char *addr, *extrap, *p, *val;
304 static char *cleanenv;
306 /* Perform some operations that aren't actually commands */
307 comparam = *j->comparam;
308 down = j->flags & (JF_STOP | JF_FAILED);
310 case IP_STOP_TIMEOUT:
311 return term_procs(j);
315 if (jail_remove(j->jid) < 0 && errno == EPERM) {
316 jail_warnx(j, "jail_remove: %s",
320 if (verbose > 0 || (verbose == 0 && (j->flags & JF_STOP
321 ? note_remove : j->name != NULL)))
322 jail_note(j, "removed\n");
324 if (j->flags & JF_STOP)
325 dep_done(j, DF_LIGHT);
327 j->flags &= ~JF_PERSIST;
329 if (create_jail(j) < 0)
332 printf("%d\n", j->jid);
333 if (verbose >= 0 && (j->name || verbose > 0))
334 jail_note(j, "created\n");
335 dep_done(j, DF_LIGHT);
342 * Collect exec arguments. Internal commands for network and
343 * mounting build their own argument lists.
345 comstring = j->comstring;
351 val = alloca(strlen(comstring->s) + 1);
352 strcpy(val, comstring->s);
355 while ((p = strchr(cs, ' ')) != NULL && strlen(p) > 1) {
356 if (extrap == NULL) {
364 argv = alloca((8 + argc) * sizeof(char *));
365 argv[0] = _PATH_IFCONFIG;
366 if ((cs = strchr(val, '|'))) {
367 argv[1] = acs = alloca(cs - val + 1);
368 strlcpy(acs, val, cs - val + 1);
371 argv[1] = string_param(j->intparams[IP_INTERFACE]);
375 if (!(cs = strchr(addr, '/'))) {
378 argv[5] = "255.255.255.255";
380 } else if (strchr(cs + 1, '.')) {
381 argv[3] = acs = alloca(cs - addr + 1);
382 strlcpy(acs, addr, cs - addr + 1);
391 if (!down && extrap != NULL) {
392 for (cs = strtok(extrap, " "); cs;
393 cs = strtok(NULL, " ")) {
394 size_t len = strlen(cs) + 1;
395 argv[argc++] = acs = alloca(len);
396 strlcpy(acs, cs, len);
400 argv[argc] = down ? "-alias" : "alias";
401 argv[argc + 1] = NULL;
408 val = alloca(strlen(comstring->s) + 1);
409 strcpy(val, comstring->s);
412 while ((p = strchr(cs, ' ')) != NULL && strlen(p) > 1) {
413 if (extrap == NULL) {
421 argv = alloca((8 + argc) * sizeof(char *));
422 argv[0] = _PATH_IFCONFIG;
423 if ((cs = strchr(val, '|'))) {
424 argv[1] = acs = alloca(cs - val + 1);
425 strlcpy(acs, val, cs - val + 1);
428 argv[1] = string_param(j->intparams[IP_INTERFACE]);
433 if (!(cs = strchr(addr, '/'))) {
434 argv[4] = "prefixlen";
440 if (!down && extrap != NULL) {
441 for (cs = strtok(extrap, " "); cs;
442 cs = strtok(NULL, " ")) {
443 size_t len = strlen(cs) + 1;
444 argv[argc++] = acs = alloca(len);
445 strlcpy(acs, cs, len);
449 argv[argc] = down ? "-alias" : "alias";
450 argv[argc + 1] = NULL;
454 case IP_VNET_INTERFACE:
455 argv = alloca(5 * sizeof(char *));
456 argv[0] = _PATH_IFCONFIG;
457 argv[1] = comstring->s;
458 argv[2] = down ? "-vnet" : "vnet";
459 jidstr = string_param(j->intparams[KP_JID]);
460 argv[3] = jidstr ? jidstr : string_param(j->intparams[KP_NAME]);
465 case IP__MOUNT_FROM_FSTAB:
466 argv = alloca(8 * sizeof(char *));
467 comcs = alloca(comstring->len + 1);
468 strcpy(comcs, comstring->s);
470 for (cs = strtok(comcs, " \t\f\v\r\n"); cs && argc < 4;
471 cs = strtok(NULL, " \t\f\v\r\n")) {
472 if (argc <= 1 && strunvis(cs, cs) < 0) {
473 jail_warnx(j, "%s: %s: fstab parse error",
474 j->intparams[comparam]->name, comstring->s);
482 jail_warnx(j, "%s: %s: missing information",
483 j->intparams[comparam]->name, comstring->s);
486 if (check_path(j, j->intparams[comparam]->name, argv[1], 0,
487 down ? argv[2] : NULL) < 0)
492 argv[0] = "/sbin/umount";
505 argv[0] = _PATH_MOUNT;
511 argv = alloca(7 * sizeof(char *));
512 path = string_param(j->intparams[KP_PATH]);
514 jail_warnx(j, "mount.devfs: no jail root path defined");
517 devpath = alloca(strlen(path) + 5);
518 sprintf(devpath, "%s/dev", path);
519 if (check_path(j, "mount.devfs", devpath, 0,
520 down ? "devfs" : NULL) < 0)
523 argv[0] = "/sbin/umount";
527 argv[0] = _PATH_MOUNT;
530 ruleset = string_param(j->intparams[KP_DEVFS_RULESET]);
532 ruleset = "4"; /* devfsrules_jail */
533 argv[3] = acs = alloca(11 + strlen(ruleset));
534 sprintf(acs, "-oruleset=%s", ruleset);
541 case IP_MOUNT_FDESCFS:
542 argv = alloca(7 * sizeof(char *));
543 path = string_param(j->intparams[KP_PATH]);
545 jail_warnx(j, "mount.fdescfs: no jail root path defined");
548 devpath = alloca(strlen(path) + 8);
549 sprintf(devpath, "%s/dev/fd", path);
550 if (check_path(j, "mount.fdescfs", devpath, 0,
551 down ? "fdescfs" : NULL) < 0)
554 argv[0] = "/sbin/umount";
558 argv[0] = _PATH_MOUNT;
567 case IP_MOUNT_PROCFS:
568 argv = alloca(7 * sizeof(char *));
569 path = string_param(j->intparams[KP_PATH]);
571 jail_warnx(j, "mount.procfs: no jail root path defined");
574 devpath = alloca(strlen(path) + 6);
575 sprintf(devpath, "%s/proc", path);
576 if (check_path(j, "mount.procfs", devpath, 0,
577 down ? "procfs" : NULL) < 0)
580 argv[0] = "/sbin/umount";
584 argv[0] = _PATH_MOUNT;
594 argv = alloca(4 * sizeof(char *));
595 jidstr = string_param(j->intparams[KP_JID]) ?
596 string_param(j->intparams[KP_JID]) :
597 string_param(j->intparams[KP_NAME]);
598 fmt = "if [ $(/sbin/zfs get -H -o value jailed %s) = on ]; then /sbin/zfs jail %s %s || echo error, attaching %s to jail %s failed; else echo error, you need to set jailed=on for dataset %s; fi";
602 - 6 * 2 /* 6 * "%s" */
604 comcs = alloca(comlen);
605 ret = snprintf(comcs, comlen, fmt, comstring->s,
606 jidstr, comstring->s, comstring->s, jidstr,
609 jail_warnx(j, "internal error in ZFS dataset handling");
612 argv[0] = _PATH_BSHELL;
620 goto default_command;
622 TAILQ_FOREACH(s, &j->intparams[IP_COMMAND]->val, tq)
624 argv = alloca((argc + 1) * sizeof(char *));
626 TAILQ_FOREACH(s, &j->intparams[IP_COMMAND]->val, tq)
629 j->comstring = &dummystring;
634 if ((cs = strpbrk(comstring->s, "!\"$&'()*;<>?[\\]`{|}~")) &&
635 !(cs[0] == '&' && cs[1] == '\0')) {
636 argv = alloca(4 * sizeof(char *));
637 argv[0] = _PATH_BSHELL;
639 argv[2] = comstring->s;
646 comcs = alloca(comstring->len + 1);
647 strcpy(comcs, comstring->s);
649 for (cs = strtok(comcs, " \t\f\v\r\n"); cs;
650 cs = strtok(NULL, " \t\f\v\r\n"))
652 argv = alloca((argc + 1) * sizeof(char *));
653 strcpy(comcs, comstring->s);
655 for (cs = strtok(comcs, " \t\f\v\r\n"); cs;
656 cs = strtok(NULL, " \t\f\v\r\n"))
664 if (int_param(j->intparams[IP_EXEC_TIMEOUT], &timeout) &&
666 clock_gettime(CLOCK_REALTIME, &j->timeout);
667 j->timeout.tv_sec += timeout;
669 j->timeout.tv_sec = 0;
671 injail = comparam == IP_EXEC_START || comparam == IP_COMMAND ||
672 comparam == IP_EXEC_STOP;
674 setid = root_cpuset_id();
676 setid = CPUSET_INVALID;
677 clean = bool_param(j->intparams[IP_EXEC_CLEAN]);
678 username = string_param(j->intparams[injail
679 ? IP_EXEC_JAIL_USER : IP_EXEC_SYSTEM_USER]);
680 sjuser = bool_param(j->intparams[IP_EXEC_SYSTEM_JAIL_USER]);
684 (conslog = string_param(j->intparams[IP_EXEC_CONSOLELOG]))) {
685 if (check_path(j, "exec.consolelog", conslog, 1, NULL) < 0)
688 open(conslog, O_WRONLY | O_CREAT | O_APPEND, DEFFILEMODE);
690 jail_warnx(j, "open %s: %s", conslog, strerror(errno));
696 for (i = 0; argv[i]; i++)
697 comlen += strlen(argv[i]) + 1;
698 j->comline = cs = emalloc(comlen);
699 for (i = 0; argv[i]; i++) {
702 cs += strlen(argv[i]) + 1;
707 jail_note(j, "run command%s%s%s: %s\n",
708 injail ? " in jail" : "", username ? " as " : "",
709 username ? username : "", j->comline);
715 if (bg || !add_proc(j, pid)) {
727 /* Set up the environment and run the command */
730 if ((clean || username) && injail && sjuser &&
731 get_user_info(j, username, &pwd, &lcap) < 0)
734 /* jail_attach won't chdir along with its chroot. */
735 path = string_param(j->intparams[KP_PATH]);
736 if (path && chdir(path) < 0) {
737 jail_warnx(j, "chdir %s: %s", path, strerror(errno));
740 if (int_param(j->intparams[IP_EXEC_FIB], &fib) &&
742 jail_warnx(j, "setfib: %s", strerror(errno));
747 * We wouldn't have specialized our affinity, so just setid to
748 * root. We do this prior to attaching to avoid the kernel
749 * having to create a transient cpuset that we'll promptly
750 * free up with a reset to the jail's cpuset.
752 * This is just a best-effort to use as wide of mask as
755 if (setid != CPUSET_INVALID)
756 (void)cpuset_setid(CPU_WHICH_PID, -1, setid);
758 if (jail_attach(j->jid) < 0) {
759 jail_warnx(j, "jail_attach: %s", strerror(errno));
763 if (clean || username) {
764 if (!(injail && sjuser) &&
765 get_user_info(j, username, &pwd, &lcap) < 0)
768 term = getenv("TERM");
770 setenv("PATH", "/bin:/usr/bin", 0);
772 setenv("TERM", term, 1);
774 if (setgid(pwd->pw_gid) < 0) {
775 jail_warnx(j, "setgid %d: %s", pwd->pw_gid,
779 if (setusercontext(lcap, pwd, pwd->pw_uid, username
780 ? LOGIN_SETALL & ~LOGIN_SETGROUP & ~LOGIN_SETLOGIN
781 : LOGIN_SETPATH | LOGIN_SETENV) < 0) {
782 jail_warnx(j, "setusercontext %s: %s", pwd->pw_name,
787 setenv("USER", pwd->pw_name, 1);
788 setenv("HOME", pwd->pw_dir, 1);
790 *pwd->pw_shell ? pwd->pw_shell : _PATH_BSHELL, 1);
791 if (clean && chdir(pwd->pw_dir) < 0) {
792 jail_warnx(j, "chdir %s: %s",
793 pwd->pw_dir, strerror(errno));
799 if (consfd != 0 && (dup2(consfd, 1) < 0 || dup2(consfd, 2) < 0)) {
800 jail_warnx(j, "exec.consolelog: %s", strerror(errno));
804 execvp(argv[0], __DECONST(char *const*, argv));
805 jail_warnx(j, "exec %s: %s", argv[0], strerror(errno));
810 * Add a process to the hash, tied to a jail.
813 add_proc(struct cfjail *j, pid_t pid)
819 if (!kq && (kq = kqueue()) < 0)
821 EV_SET(&ke, pid, EVFILT_PROC, EV_ADD, NOTE_EXIT, 0, NULL);
822 if (kevent(kq, &ke, 1, NULL, 0, NULL) < 0) {
827 ph = emalloc(sizeof(struct phash));
830 LIST_INSERT_HEAD(&phash[pid % PHASH_SIZE], ph, le);
832 j->flags |= JF_SLEEPQ;
833 if (j->timeout.tv_sec == 0)
834 requeue(j, &sleeping);
836 /* File the jail in the sleep queue according to its timeout. */
837 TAILQ_REMOVE(j->queue, j, tq);
838 TAILQ_FOREACH(tj, &sleeping, tq) {
839 if (!tj->timeout.tv_sec ||
840 j->timeout.tv_sec < tj->timeout.tv_sec ||
841 (j->timeout.tv_sec == tj->timeout.tv_sec &&
842 j->timeout.tv_nsec <= tj->timeout.tv_nsec)) {
843 TAILQ_INSERT_BEFORE(tj, j, tq);
848 TAILQ_INSERT_TAIL(&sleeping, j, tq);
849 j->queue = &sleeping;
855 * Remove any processes from the hash that correspond to a jail.
858 clear_procs(struct cfjail *j)
861 struct phash *ph, *tph;
865 for (i = 0; i < PHASH_SIZE; i++)
866 LIST_FOREACH_SAFE(ph, &phash[i], le, tph)
868 EV_SET(&ke, ph->pid, EVFILT_PROC, EV_DELETE,
870 (void)kevent(kq, &ke, 1, NULL, 0, NULL);
877 * Find the jail that corresponds to an exited process.
879 static struct cfjail *
885 LIST_FOREACH(ph, &phash[pid % PHASH_SIZE], le)
886 if (ph->pid == pid) {
890 return --j->nprocs ? NULL : j;
896 * Send SIGTERM to all processes in a jail and wait for them to die.
899 term_procs(struct cfjail *j)
901 struct kinfo_proc *ki;
902 int i, noted, pcnt, timeout;
906 if (!int_param(j->intparams[IP_STOP_TIMEOUT], &timeout))
907 timeout = DEFAULT_STOP_TIMEOUT;
908 else if (timeout == 0)
912 kd = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL);
917 ki = kvm_getprocs(kd, KERN_PROC_PROC, 0, &pcnt);
921 for (i = 0; i < pcnt; i++)
922 if (ki[i].ki_jid == j->jid &&
923 kill(ki[i].ki_pid, SIGTERM) == 0) {
924 (void)add_proc(j, ki[i].ki_pid);
928 jail_note(j, "sent SIGTERM to:");
930 printf(" %d", ki[i].ki_pid);
936 clock_gettime(CLOCK_REALTIME, &j->timeout);
937 j->timeout.tv_sec += timeout;
944 * Look up a user in the passwd and login.conf files.
947 get_user_info(struct cfjail *j, const char *username,
948 const struct passwd **pwdp, login_cap_t **lcapp)
950 const struct passwd *pwd;
953 *pwdp = pwd = username ? getpwnam(username) : getpwuid(getuid());
956 jail_warnx(j, "getpwnam%s%s: %s", username ? " " : "",
957 username ? username : "", strerror(errno));
959 jail_warnx(j, "%s: no such user", username);
961 jail_warnx(j, "unknown uid %d", getuid());
964 *lcapp = login_getpwclass(pwd);
965 if (*lcapp == NULL) {
966 jail_warnx(j, "getpwclass %s: %s", pwd->pw_name,
970 /* Set the groups while the group file is still available */
971 if (initgroups(pwd->pw_name, pwd->pw_gid) < 0) {
972 jail_warnx(j, "initgroups %s: %s", pwd->pw_name,
980 * Make sure a mount or consolelog path is a valid absolute pathname
984 check_path(struct cfjail *j, const char *pname, const char *path, int isfile,
985 const char *umount_type)
987 struct stat st, mpst;
990 const char *jailpath;
993 if (path[0] != '/') {
994 jail_warnx(j, "%s: %s: not an absolute pathname",
999 * Only check for symlinks in components below the jail's path,
1000 * since that's where the security risk lies.
1002 jailpath = string_param(j->intparams[KP_PATH]);
1003 if (jailpath == NULL)
1005 jplen = strlen(jailpath);
1006 if (!strncmp(path, jailpath, jplen) && path[jplen] == '/') {
1007 tpath = alloca(strlen(path) + 1);
1008 strcpy(tpath, path);
1009 for (p = tpath + jplen; p != NULL; ) {
1010 p = strchr(p + 1, '/');
1013 if (lstat(tpath, &st) < 0) {
1014 if (errno == ENOENT && isfile && !p)
1016 jail_warnx(j, "%s: %s: %s", pname, tpath,
1020 if (S_ISLNK(st.st_mode)) {
1021 jail_warnx(j, "%s: %s is a symbolic link",
1029 if (umount_type != NULL) {
1030 if (stat(path, &st) < 0 || statfs(path, &stfs) < 0) {
1031 jail_warnx(j, "%s: %s: %s", pname, path,
1035 if (stat(stfs.f_mntonname, &mpst) < 0) {
1036 jail_warnx(j, "%s: %s: %s", pname, stfs.f_mntonname,
1040 if (st.st_ino != mpst.st_ino) {
1041 jail_warnx(j, "%s: %s: not a mount point",
1045 if (strcmp(stfs.f_fstypename, umount_type)) {
1046 jail_warnx(j, "%s: %s: not a %s mount",
1047 pname, path, umount_type);