[Pkg-shadow-devel] patch for su - 2

Nicolas François nicolas.francois@centraliens.net
Fri, 3 Jun 2005 01:24:41 +0200


--Izn7cH1Com+I3R9J
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

cze=C5=9B=C4=87 Tomasz,

Another patch for su.

UID 0 is not necessary named root.
This patch retrieve the username of the user with UID 0.

More info at: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=3D81924

This patch is also against PLD's CVS.

Kind Regards,
--=20
Nekral

--Izn7cH1Com+I3R9J
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=008_su_uid_0_not_root

Goal: don't assume uid 0 == "root", use getpwuid to fetch it
Fixes: #81924

Status wrt upstream: It should be forwarded to upstream.

--- su.c.orig	2005-06-02 12:59:59.951911000 +0200
+++ su.c	2005-06-02 13:02:04.261911000 +0200
@@ -383,7 +383,14 @@
 		argv++;		/* shift ... */
 	}
 	if (!name[0])		/* use default user ID */
-		(void) strcpy (name, "root");
+	{
+		struct passwd *root_pw = getpwuid(0);
+		if (root_pw == NULL) {
+			SYSLOG((LOG_CRIT, "There is no UID 0 user."));
+			su_failure(tty)
+		}
+		strcpy(name, root_pw->pw_name);
+	}
 
 	doshell = argc == 0;	/* any arguments remaining? */
 

--Izn7cH1Com+I3R9J--