From 0bb61e3aefc32940d8578eb174bf6e39dca17c35 Mon Sep 17 00:00:00 2001 From: Alexander Holler Date: Fri, 4 Nov 2022 08:06:29 +0100 Subject: [PATCH] su: do not require /etc/shadow or a password there if called as root --- toys/lsb/su.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/toys/lsb/su.c b/toys/lsb/su.c index 74a87dbd..71df8a6b 100644 --- a/toys/lsb/su.c +++ b/toys/lsb/su.c @@ -45,7 +45,6 @@ void su_main() { char *name, *passhash = 0, **argu, **argv; struct passwd *up; - struct spwd *shp; if (*toys.optargs && !strcmp("-", *toys.optargs)) { toys.optflags |= FLAG_l; @@ -57,8 +56,10 @@ void su_main() loggit(LOG_NOTICE, "%s->%s", getusername(geteuid()), name); - if (!(shp = getspnam(name))) perror_exit("no '%s'", name); if (getuid()) { + struct spwd *shp; + + if (!(shp = getspnam(name))) perror_exit("no '%s'", name); if (*shp->sp_pwdp != '$') goto deny; if (read_password(toybuf, sizeof(toybuf), "Password: ")) goto deny; passhash = crypt(toybuf, shp->sp_pwdp); -- 2.39.2