Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libutil openpty: just check errors of syscalls,



details:   https://anonhg.NetBSD.org/src/rev/23fd1aeef6f3
branches:  trunk
changeset: 570043:23fd1aeef6f3
user:      yamt <yamt%NetBSD.org@localhost>
date:      Sat Sep 18 16:44:38 2004 +0000

description:
openpty: just check errors of syscalls,
instead of checking permission beforehand in userland.

diffstat:

 lib/libutil/pty.c |  17 ++++++-----------
 1 files changed, 6 insertions(+), 11 deletions(-)

diffs (46 lines):

diff -r d32c3b170a87 -r 23fd1aeef6f3 lib/libutil/pty.c
--- a/lib/libutil/pty.c Sat Sep 18 16:40:11 2004 +0000
+++ b/lib/libutil/pty.c Sat Sep 18 16:44:38 2004 +0000
@@ -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 @@
                }
        }
 
-       if (geteuid() != 0) {
-               errno = EPERM;
-               return -1;
-       }
-
        if ((gr = getgrnam("tty")) != NULL)
                ttygid = gr->gr_gid;
        else
@@ -110,11 +105,11 @@
                                }
                        } 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;



Home | Main Index | Thread Index | Old Index