summaryrefslogtreecommitdiff
path: root/lib/libutil
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>2004-06-18 02:42:57 +0000
committerchristos <christos@NetBSD.org>2004-06-18 02:42:57 +0000
commit92cd5ee20c29b706c149122f95f941d39f2d4d15 (patch)
treeda534bca749e3233abfc87903de5c9d0b5b92c71 /lib/libutil
parent8b0935d09f5b09953b84306c90cced903e39ccb1 (diff)
Don't allow openpty to succeed if the caller is non-superuser.
XXX: we cross-reference ptm 4 which does not exist (yet)
Diffstat (limited to 'lib/libutil')
-rw-r--r--lib/libutil/openpty.38
-rw-r--r--lib/libutil/pty.c11
2 files changed, 14 insertions, 5 deletions
diff --git a/lib/libutil/openpty.3 b/lib/libutil/openpty.3
index fa77c9e2ba8..d222efb01b3 100644
--- a/lib/libutil/openpty.3
+++ b/lib/libutil/openpty.3
@@ -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
diff --git a/lib/libutil/pty.c b/lib/libutil/pty.c
index 2a7966ad0bf..229faf0224e 100644
--- a/lib/libutil/pty.c
+++ b/lib/libutil/pty.c
@@ -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;