Allow ptyfs to be mounted inside a chrooted environment.

This commit is contained in:
christos 2009-03-15 16:47:45 +00:00
parent 3cb697e64a
commit 9f97ab946c
2 changed files with 31 additions and 9 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: mount_ptyfs.8,v 1.6 2008/04/30 13:10:53 martin Exp $
.\" $NetBSD: mount_ptyfs.8,v 1.7 2009/03/15 16:47:45 christos Exp $
.\"
.\"
.\" Copyright (c) 2004 The NetBSD Foundation, Inc.
@ -28,7 +28,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd November 24, 2004
.Dd March 15, 2009
.Dt MOUNT_PTYFS 8
.Os
.Sh NAME
@ -36,6 +36,7 @@
.Nd mount the /dev/pts file system
.Sh SYNOPSIS
.Nm
.Op Fl c
.Op Fl g Ar group|gid
.Op Fl m Ar mode
.Op Fl o Ar options
@ -62,6 +63,10 @@ or they are already open via traditional BSD style ptys.
.Pp
The options are as follows:
.Bl -tag -width indent
.It Fl c
Allows
.Ar ptyfs
to be mounted inside a chrooted environment.
.It Fl g Ar group|gid
Specify the group ownership of the slave pseudo-tty.
.It Fl m Ar mode
@ -75,6 +80,9 @@ flag followed by a comma separated string of options.
.Pp
.Nm
specific options are
.Dv chroot
which corresponds to
.Fl c ,
.Dv group
which corresponds to
.Fl g ,

View File

@ -1,4 +1,4 @@
/* $NetBSD: mount_ptyfs.c,v 1.9 2008/07/20 01:20:22 lukem Exp $ */
/* $NetBSD: mount_ptyfs.c,v 1.10 2009/03/15 16:47:45 christos Exp $ */
/*
* Copyright (c) 1992, 1993, 1994
@ -77,7 +77,7 @@ __COPYRIGHT("@(#) Copyright (c) 1992, 1993, 1994\
#if 0
static char sccsid[] = "@(#)mount_ptyfs.c 8.3 (Berkeley) 5/4/95";
#else
__RCSID("$NetBSD: mount_ptyfs.c,v 1.9 2008/07/20 01:20:22 lukem Exp $");
__RCSID("$NetBSD: mount_ptyfs.c,v 1.10 2009/03/15 16:47:45 christos Exp $");
#endif
#endif /* not lint */
@ -94,17 +94,20 @@ __RCSID("$NetBSD: mount_ptyfs.c,v 1.9 2008/07/20 01:20:22 lukem Exp $");
#include <stdlib.h>
#include <string.h>
#include <grp.h>
#include <util.h>
#include <mntopts.h>
#define ALTF_GROUP 1
#define ALTF_MODE 2
#define ALTF_CHROOT 3
static const struct mntopt mopts[] = {
MOPT_STDOPTS,
MOPT_GETARGS,
{ "group", 0, ALTF_GROUP, 1 },
{ "mode", 0, ALTF_MODE, 1 },
{ "chroot", 0, ALTF_CHROOT, 1 },
MOPT_NULL,
};
@ -160,8 +163,9 @@ mount_ptyfs(int argc, char *argv[])
args.version = PTYFS_ARGSVERSION;
args.gid = getgrp("tty");
args.mode = S_IRUSR|S_IWUSR|S_IWGRP;
args.flags = 0;
while ((ch = getopt(argc, argv, "g:m:o:")) != -1)
while ((ch = getopt(argc, argv, "cg:m:o:")) != -1)
switch (ch) {
case 'o':
altflags = 0;
@ -172,8 +176,13 @@ mount_ptyfs(int argc, char *argv[])
args.gid = getgrp(getmntoptstr(mp, "group"));
if (altflags & ALTF_MODE)
args.mode = (mode_t)getmntoptnum(mp, "mode");
if (altflags & ALTF_CHROOT)
args.flags |= PTYFSMNT_CHROOT;
freemntopts(mp);
break;
case 'c':
args.flags |= PTYFSMNT_CHROOT;
break;
case 'g':
args.gid = getgrp(optarg);
break;
@ -200,9 +209,13 @@ mount_ptyfs(int argc, char *argv[])
if (mount(MOUNT_PTYFS, canon_dir, mntflags, &args, sizeof args) == -1)
err(1, "ptyfs on %s", canon_dir);
if (mntflags & MNT_GETARGS)
printf("version=%d, gid=%lu, mode=0%o\n", args.version,
(unsigned long)args.gid, args.mode);
if (mntflags & MNT_GETARGS) {
char buf[1024];
(void)snprintb(buf, sizeof(buf), PTYFSMNT_BITS, args.flags);
printf("version=%d, flags=%s\n", args.version, buf);
printf("version=%d, gid=%lu, mode=0%o flags=%s\n", args.version,
(unsigned long)args.gid, args.mode, buf);
}
return 0;
}
@ -210,6 +223,7 @@ static void
usage(void)
{
(void)fprintf(stderr,
"Usage: %s [-g <group|gid>] [-m <mode>] [-o options] ptyfs mountpoint\n", getprogname());
"Usage: %s [-c] [-g <group|gid>] [-m <mode>] [-o options] "
"ptyfs mountpoint\n", getprogname());
exit(1);
}