Don't allow openpty to succeed if the caller is non-superuser.

XXX: we cross-reference ptm 4 which does not exist (yet)
This commit is contained in:
christos 2004-06-18 02:42:57 +00:00
parent 8b0935d09f
commit 92cd5ee20c
2 changed files with 14 additions and 5 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: openpty.3,v 1.12 2003/08/07 16:44:59 agc Exp $
.\" $NetBSD: openpty.3,v 1.13 2004/06/18 02:42:57 christos Exp $
.\"
.\" Copyright (c) 1995
.\" The Regents of the University of California. All rights reserved.
@ -31,7 +31,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd November 4, 1996
.Dd June 17, 2004
.Dt OPENPTY 3
.Os
.Sh NAME
@ -139,6 +139,10 @@ will fail if:
.Bl -tag -width Er
.It Bq Er ENOENT
There are no available ttys.
.It Bq Er EPERM
The caller was not the superuser and the
.Xr ptm 4
device is missing or not configured.
.El
.Pp
.Fn login_tty

View File

@ -1,4 +1,4 @@
/* $NetBSD: pty.c,v 1.22 2004/05/27 03:12:48 christos Exp $ */
/* $NetBSD: pty.c,v 1.23 2004/06/18 02:42:57 christos Exp $ */
/*-
* Copyright (c) 1990, 1993, 1994
@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)pty.c 8.3 (Berkeley) 5/16/94";
#else
__RCSID("$NetBSD: pty.c,v 1.22 2004/05/27 03:12:48 christos Exp $");
__RCSID("$NetBSD: pty.c,v 1.23 2004/06/18 02:42:57 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@ -86,10 +86,15 @@ openpty(int *amaster, int *aslave, char *name, struct termios *termp,
}
}
if (geteuid() != 0) {
errno = EPERM;
return -1;
}
if ((gr = getgrnam("tty")) != NULL)
ttygid = gr->gr_gid;
else
ttygid = (gid_t) -1;
ttygid = _TTY_GID;
for (cp1 = TTY_LETTERS; *cp1; cp1++) {
line[8] = *cp1;