Reads the mount.fstab file, and put its lines separately into the

IP__MOUNT_FROM_FSTAB internal parameter.
This commit is contained in:
Jamie Gritton 2010-11-04 17:01:21 +00:00
parent e3c69673a6
commit 52a4962202
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/projects/jailconf/; revision=214783
4 changed files with 50 additions and 17 deletions

View File

@ -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) {

View File

@ -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;
}

View File

@ -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 */

View File

@ -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,