summaryrefslogtreecommitdiffstats
path: root/usr.sbin/jail
diff options
context:
space:
mode:
authorjamie <jamie@FreeBSD.org>2010-11-04 17:01:21 +0000
committerjamie <jamie@FreeBSD.org>2010-11-04 17:01:21 +0000
commit85767896da1c52300de322e3fc4f29fe9b7e4413 (patch)
treebced28660a29b3ffad515a0234107c8eeb256ded /usr.sbin/jail
parent94aa5f72213aae7248f78420b16afc320dd93e4b (diff)
downloadFreeBSD-src-85767896da1c52300de322e3fc4f29fe9b7e4413.zip
FreeBSD-src-85767896da1c52300de322e3fc4f29fe9b7e4413.tar.gz
Reads the mount.fstab file, and put its lines separately into the
IP__MOUNT_FROM_FSTAB internal parameter.
Diffstat (limited to 'usr.sbin/jail')
-rw-r--r--usr.sbin/jail/command.c13
-rw-r--r--usr.sbin/jail/config.c41
-rw-r--r--usr.sbin/jail/jail.c12
-rw-r--r--usr.sbin/jail/jailp.h1
4 files changed, 50 insertions, 17 deletions
diff --git a/usr.sbin/jail/command.c b/usr.sbin/jail/command.c
index 437096a..dfb7e4e 100644
--- a/usr.sbin/jail/command.c
+++ b/usr.sbin/jail/command.c
@@ -189,7 +189,7 @@ run_command(struct cfjail *j, int *plimit, enum intparam comparam)
jidstr ? jidstr : string_param(j->intparams[KP_NAME]);
argv[4] = NULL;
j->flags |= JF_IFUP;
- } else if (comparam == IP_MOUNT) {
+ } else if (comparam == IP_MOUNT || comparam == IP__MOUNT_FROM_FSTAB) {
argv = alloca(8 * sizeof(char *));
comcs = alloca(comstring->len + 1);
strcpy(comcs, comstring->s);
@@ -198,8 +198,8 @@ run_command(struct cfjail *j, int *plimit, enum intparam comparam)
cs = strtok(NULL, " \t\f\v\r\n"))
argv[argc++] = cs;
if (argc < 3) {
- jail_warnx(j, "mount: %s: missing information",
- comstring->s);
+ jail_warnx(j, "%s: %s: missing information",
+ j->intparams[comparam]->name, comstring->s);
failed(j);
return -1;
}
@@ -223,13 +223,6 @@ run_command(struct cfjail *j, int *plimit, enum intparam comparam)
}
*(const char **)&argv[1] = "-t";
j->flags |= JF_MOUNTED;
- } else if (comparam == IP_MOUNT_FSTAB) {
- argv = alloca(4 * sizeof(char *));
- *(const char **)&argv[0] = down ? "/sbin/umount" : _PATH_MOUNT;
- *(const char **)&argv[1] = "-aF";
- argv[2] = comstring->s;
- argv[3] = NULL;
- j->flags |= JF_MOUNTED;
} else if (comparam == IP_MOUNT_DEVFS) {
path = string_param(j->intparams[KP_PATH]);
if (path == NULL) {
diff --git a/usr.sbin/jail/config.c b/usr.sbin/jail/config.c
index a12b60e..206ff60 100644
--- a/usr.sbin/jail/config.c
+++ b/usr.sbin/jail/config.c
@@ -28,6 +28,7 @@
__FBSDID("$FreeBSD$");
#include <sys/types.h>
+#include <sys/errno.h>
#include <sys/socket.h>
#include <sys/sysctl.h>
@@ -85,6 +86,7 @@ static const struct ipspec intparams[] = {
#ifdef INET6
[IP__IP6_IFADDR] = {"ip6.addr", PF_INTERNAL | PF_CONV},
#endif
+ [IP__MOUNT_FROM_FSTAB] = {"mount.fstab", PF_INTERNAL | PF_CONV},
[KP_ALLOW_CHFLAGS] = {"allow.chflags", 0},
[KP_ALLOW_MOUNT] = {"allow.mount", 0},
[KP_ALLOW_RAW_SOCKETS] = {"allow.raw_sockets", 0},
@@ -430,9 +432,10 @@ check_intparams(struct cfjail *j)
struct addrinfo *ai0, *ai;
struct cfparam *p;
struct cfstring *s, *ns;
+ FILE *f;
const char *hostname, *val;
- char *cs, *ep;
- size_t size;
+ char *cs, *ep, *ln;
+ size_t size, lnlen;
int error, gicode, ip4ok, defif, prefix;
int mib[4];
char avalue4[INET_ADDRSTRLEN];
@@ -601,6 +604,40 @@ check_intparams(struct cfjail *j)
#ifndef INET6
while (0);
#endif
+
+ /*
+ * Read mount.fstab file(s), and treat each line as its own mount
+ * parameter.
+ */
+ if (j->intparams[IP_MOUNT_FSTAB] != NULL) {
+ STAILQ_FOREACH(s, &j->intparams[IP_MOUNT_FSTAB]->val, tq) {
+ if (s->len == 0)
+ continue;
+ f = fopen(s->s, "r");
+ if (f == NULL) {
+ jail_warnx(j, "mount.fstab: %s: %s",
+ s->s, strerror(errno));
+ error = -1;
+ continue;
+ }
+ while ((ln = fgetln(f, &lnlen))) {
+ if ((cs = memchr(ln, '#', lnlen - 1)))
+ lnlen = cs - ln + 1;
+ if (ln[lnlen - 1] == '\n' ||
+ ln[lnlen - 1] == '#')
+ ln[lnlen - 1] = '\0';
+ else {
+ cs = alloca(lnlen + 1);
+ strlcpy(cs, ln, lnlen + 1);
+ ln = cs;
+ }
+ add_param(j, NULL, IP__MOUNT_FROM_FSTAB, ln);
+ }
+ fclose(f);
+ }
+ }
+ if (error)
+ failed(j);
return error;
}
diff --git a/usr.sbin/jail/jail.c b/usr.sbin/jail/jail.c
index fbfa28c..0bc1bd1 100644
--- a/usr.sbin/jail/jail.c
+++ b/usr.sbin/jail/jail.c
@@ -294,7 +294,7 @@ main(int argc, char **argv)
clear_persist(j);
if (j->flags & JF_MOUNTED) {
(void)run_command(j, NULL, IP_MOUNT_DEVFS);
- if (run_command(j, NULL, IP_MOUNT_FSTAB))
+ if (run_command(j, NULL, IP__MOUNT_FROM_FSTAB))
while (run_command(j, NULL, 0)) ;
if (run_command(j, NULL, IP_MOUNT))
while (run_command(j, NULL, 0)) ;
@@ -393,10 +393,11 @@ main(int argc, char **argv)
continue;
/* FALLTHROUGH */
case IP_MOUNT:
- if (run_command(j, &plimit, IP_MOUNT_FSTAB))
+ if (run_command(j, &plimit,
+ IP__MOUNT_FROM_FSTAB))
continue;
/* FALLTHROUGH */
- case IP_MOUNT_FSTAB:
+ case IP__MOUNT_FROM_FSTAB:
if (run_command(j, &plimit, IP_MOUNT_DEVFS))
continue;
/* FALLTHROUGH */
@@ -509,10 +510,11 @@ main(int argc, char **argv)
continue;
/* FALLTHROUGH */
case IP_MOUNT_DEVFS:
- if (run_command(j, &plimit, IP_MOUNT_FSTAB))
+ if (run_command(j, &plimit,
+ IP__MOUNT_FROM_FSTAB))
continue;
/* FALLTHROUGH */
- case IP_MOUNT_FSTAB:
+ case IP__MOUNT_FROM_FSTAB:
if (run_command(j, &plimit, IP_MOUNT))
continue;
/* FALLTHROUGH */
diff --git a/usr.sbin/jail/jailp.h b/usr.sbin/jail/jailp.h
index 885a162..9dc47fc 100644
--- a/usr.sbin/jail/jailp.h
+++ b/usr.sbin/jail/jailp.h
@@ -102,6 +102,7 @@ enum intparam {
#ifdef INET6
IP__IP6_IFADDR, /* Copy of ip6.addr with interface/prefixlen */
#endif
+ IP__MOUNT_FROM_FSTAB, /* Line from mount.fstab file */
KP_ALLOW_CHFLAGS,
KP_ALLOW_MOUNT,
KP_ALLOW_RAW_SOCKETS,
OpenPOWER on IntegriCloud