[Pkg-shadow-commits] r2666 - in upstream/trunk: . src

Nicolas FRANÇOIS nekral-guest at alioth.debian.org
Sun Apr 12 00:28:32 UTC 2009


Author: nekral-guest
Date: 2009-04-12 00:28:32 +0000 (Sun, 12 Apr 2009)
New Revision: 2666

Modified:
   upstream/trunk/ChangeLog
   upstream/trunk/src/su.c
Log:
	* src/su.c: If there are no root account, or if the root account
	has an UID != 0, default to the first UID 0 account.


Modified: upstream/trunk/ChangeLog
===================================================================
--- upstream/trunk/ChangeLog	2009-04-12 00:19:35 UTC (rev 2665)
+++ upstream/trunk/ChangeLog	2009-04-12 00:28:32 UTC (rev 2666)
@@ -1,5 +1,10 @@
 2009-04-12  Nicolas François  <nicolas.francois at centraliens.net>
 
+	* src/su.c: If there are no root account, or if the root account
+	has an UID != 0, default to the first UID 0 account.
+
+2009-04-12  Nicolas François  <nicolas.francois at centraliens.net>
+
 	* src/login.c: Restore the echoctl, echoke, onclr flags to the
 	terminal termio flags. Reset echoprt, noflsh, tostop. This
 	behavior seems to have change by mistake in earlier releases

Modified: upstream/trunk/src/su.c
===================================================================
--- upstream/trunk/src/su.c	2009-04-12 00:19:35 UTC (rev 2665)
+++ upstream/trunk/src/su.c	2009-04-12 00:28:32 UTC (rev 2666)
@@ -305,7 +305,7 @@
  * su - switch user id
  *
  *	su changes the user's ids to the values for the specified user.  if
- *	no new user name is specified, "root" is used by default.
+ *	no new user name is specified, "root" or UID 0 is used by default.
  *
  *	Any additional arguments are passed to the user's shell. In
  *	particular, the argument "-c" will cause the next argument to be
@@ -457,8 +457,18 @@
 			optind++;
 		}
 	}
-	if ('\0' == name[0]) {		/* use default user ID */
-		(void) strcpy (name, "root");
+	if ('\0' == name[0]) {		/* use default user */
+		struct passwd *root_pw = getpwnam("root");
+		if ((NULL != root_pw) && (0 == root_pw->pw_uid)) {
+			(void) strcpy (name, "root");
+		} else {
+			struct passwd *root_pw = getpwuid(0);
+			if (NULL == root_pw) {
+				SYSLOG((LOG_CRIT, "There is no UID 0 user."));
+				su_failure(tty);
+			}
+			(void) strcpy(name, root_pw->pw_name);
+		}
 	}
 
 	doshell = (argc == optind);	/* any arguments remaining? */




More information about the Pkg-shadow-commits mailing list