Source-Changes-HG archive

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

[src/netbsd-1-5]: src/usr.bin/su Pull up revision 1.44:



details:   https://anonhg.NetBSD.org/src/rev/009032e99897
branches:  netbsd-1-5
changeset: 489426:009032e99897
user:      erh <erh%NetBSD.org@localhost>
date:      Sun Sep 10 18:35:03 2000 +0000

description:
Pull up revision 1.44:
        Switch to user earlier so home directories on root=nobody NFS mount work.
        Avoid inadvertently raising the prority when we want to lower it.

diffstat:

 usr.bin/su/su.c |  25 +++++++++++++------------
 1 files changed, 13 insertions(+), 12 deletions(-)

diffs (73 lines):

diff -r 8137c79126b9 -r 009032e99897 usr.bin/su/su.c
--- a/usr.bin/su/su.c   Sun Sep 10 10:47:36 2000 +0000
+++ b/usr.bin/su/su.c   Sun Sep 10 18:35:03 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: su.c,v 1.39.4.1 2000/08/09 14:52:15 assar Exp $        */
+/*     $NetBSD: su.c,v 1.39.4.2 2000/09/10 18:35:03 erh Exp $  */
 
 /*
  * Copyright (c) 1988 The Regents of the University of California.
@@ -44,7 +44,7 @@
 #if 0
 static char sccsid[] = "@(#)su.c       8.3 (Berkeley) 4/2/94";*/
 #else
-__RCSID("$NetBSD: su.c,v 1.39.4.1 2000/08/09 14:52:15 assar Exp $");
+__RCSID("$NetBSD: su.c,v 1.39.4.2 2000/09/10 18:35:03 erh Exp $");
 #endif
 #endif /* not lint */
 
@@ -173,11 +173,13 @@
                }
        argv += optind;
 
+       /* Lower the priority so su runs faster */
        errno = 0;
        prio = getpriority(PRIO_PROCESS, 0);
        if (errno)
                prio = 0;
-       (void)setpriority(PRIO_PROCESS, 0, -2);
+       if (prio > -2)
+               (void)setpriority(PRIO_PROCESS, 0, -2);
        openlog("su", LOG_CONS, 0);
 
        /* get current login name and shell */
@@ -330,8 +332,13 @@
        if (iscsh == UNSET)
                iscsh = strstr(avshell, "csh") ? YES : NO;
 
-#ifndef LOGIN_CAP /* This is done by setusercontext() */
        /* set permissions */
+#ifdef LOGIN_CAP
+       if (setusercontext(lc, pwd, pwd->pw_uid,
+           (asthem ? (LOGIN_SETPRIORITY | LOGIN_SETUMASK) : 0) |
+           LOGIN_SETRESOURCES | LOGIN_SETGROUP | LOGIN_SETUSER))
+               err(1, "setting user context");
+#else
        if (setgid(pwd->pw_gid) < 0)
                err(1, "setgid");
        if (initgroups(user, pwd->pw_gid))
@@ -348,8 +355,7 @@
                                err(1, NULL);
                        environ[0] = NULL;
 #ifdef LOGIN_CAP
-                       if (setusercontext(lc,
-                           pwd, pwd->pw_uid, LOGIN_SETPATH))
+                       if (setusercontext(lc, pwd, pwd->pw_uid, LOGIN_SETPATH))
                                err(1, "setting user context");
 #else
                        (void)setenv("PATH", _PATH_DEFPATH, 1);
@@ -415,13 +421,8 @@
                syslog(LOG_NOTICE|LOG_AUTH, "%s to %s%s",
                    username, pwd->pw_name, ontty());
 
+       /* Raise our priority back to what we had before */
        (void)setpriority(PRIO_PROCESS, 0, prio);
-#ifdef LOGIN_CAP
-       if (setusercontext(lc, pwd, pwd->pw_uid,
-           (asthem ? (LOGIN_SETPRIORITY | LOGIN_SETUMASK) : 0) |
-           LOGIN_SETRESOURCES | LOGIN_SETGROUP | LOGIN_SETUSER))
-               err(1, "setting user context");
-#endif
 
        execv(shell, np);
        err(1, "%s", shell);



Home | Main Index | Thread Index | Old Index