diff options
| author | yamt <yamt@NetBSD.org> | 2004-09-18 16:44:38 +0000 |
|---|---|---|
| committer | yamt <yamt@NetBSD.org> | 2004-09-18 16:44:38 +0000 |
| commit | 2936303c19eabf43f49092face61566c4a4d4859 (patch) | |
| tree | 342afdbe22094501d85bbf0248906a2f6ce702de /lib/libutil | |
| parent | 22399b45d049422504e2956ce85bcf165e80e819 (diff) | |
openpty: just check errors of syscalls,
instead of checking permission beforehand in userland.
Diffstat (limited to 'lib/libutil')
| -rw-r--r-- | lib/libutil/pty.c | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/lib/libutil/pty.c b/lib/libutil/pty.c index 229faf0224e..c81cfa89dd2 100644 --- a/lib/libutil/pty.c +++ b/lib/libutil/pty.c @@ -1,4 +1,4 @@ -/* $NetBSD: pty.c,v 1.23 2004/06/18 02:42:57 christos Exp $ */ +/* $NetBSD: pty.c,v 1.24 2004/09/18 16:44:38 yamt 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.23 2004/06/18 02:42:57 christos Exp $"); +__RCSID("$NetBSD: pty.c,v 1.24 2004/09/18 16:44:38 yamt Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -86,11 +86,6 @@ 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 @@ -110,11 +105,11 @@ openpty(int *amaster, int *aslave, char *name, struct termios *termp, } } else { line[5] = 't'; - (void) chown(line, getuid(), ttygid); - (void) chmod(line, S_IRUSR|S_IWUSR|S_IWGRP); - (void) revoke(line); linep = line; - if ((slave = open(line, O_RDWR, 0)) != -1) { + if (chown(line, getuid(), ttygid) == 0 && + chmod(line, S_IRUSR|S_IWUSR|S_IWGRP) == 0 && + revoke(line) == 0 && + (slave = open(line, O_RDWR, 0)) != -1) { gotit: *amaster = master; *aslave = slave; |
