svn commit: r214783 - projects/jailconf/usr.sbin/jail
Jamie Gritton
jamie at FreeBSD.org
Thu Nov 4 17:01:21 UTC 2010
Author: jamie
Date: Thu Nov 4 17:01:21 2010
New Revision: 214783
URL: http://svn.freebsd.org/changeset/base/214783
Log:
Reads the mount.fstab file, and put its lines separately into the
IP__MOUNT_FROM_FSTAB internal parameter.
Modified:
projects/jailconf/usr.sbin/jail/command.c
projects/jailconf/usr.sbin/jail/config.c
projects/jailconf/usr.sbin/jail/jail.c
projects/jailconf/usr.sbin/jail/jailp.h
Modified: projects/jailconf/usr.sbin/jail/command.c
==============================================================================
--- projects/jailconf/usr.sbin/jail/command.c Thu Nov 4 15:33:50 2010 (r214782)
+++ projects/jailconf/usr.sbin/jail/command.c Thu Nov 4 17:01:21 2010 (r214783)
@@ -189,7 +189,7 @@ run_command(struct cfjail *j, int *plimi
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 *plimi
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 *plimi
}
*(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) {
Modified: projects/jailconf/usr.sbin/jail/config.c
==============================================================================
--- projects/jailconf/usr.sbin/jail/config.c Thu Nov 4 15:33:50 2010 (r214782)
+++ projects/jailconf/usr.sbin/jail/config.c Thu Nov 4 17:01:21 2010 (r214783)
@@ -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;
}
Modified: projects/jailconf/usr.sbin/jail/jail.c
==============================================================================
--- projects/jailconf/usr.sbin/jail/jail.c Thu Nov 4 15:33:50 2010 (r214782)
+++ projects/jailconf/usr.sbin/jail/jail.c Thu Nov 4 17:01:21 2010 (r214783)
@@ -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 */
Modified: projects/jailconf/usr.sbin/jail/jailp.h
==============================================================================
--- projects/jailconf/usr.sbin/jail/jailp.h Thu Nov 4 15:33:50 2010 (r214782)
+++ projects/jailconf/usr.sbin/jail/jailp.h Thu Nov 4 17:01:21 2010 (r214783)
@@ -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,
More information about the svn-src-projects
mailing list