From: Tobias Stoeckmann Date: Sun, 15 Mar 2026 23:31:47 +0000 (+0100) Subject: usermod: Update passwd entry when shadowing entry X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fef30561bf497fc3b6241acdeb31fbc6b5407b20;p=thirdparty%2Fshadow.git usermod: Update passwd entry when shadowing entry If a new shadow entry is created, the passwd entry's password hash is moved into shadow file and replaced with an "x". If this happens, update the passwd file as well, otherwise the "x" is not written to disk. Resolves: https://github.com/shadow-maint/shadow/issues/1580 Reproducer (as root): ``` BASE=$(mktemp -d) mkdir -p $BASE/etc useradd -P $BASE user touch $BASE/etc/shadow usermod -P $BASE -e 0 user cat $BASE/etc/passwd ``` Incorrect output (before): ``` user:!:1000:1000::/home/user:/bin/bash ``` Correct output (after): ``` user:x:1000:1000::/home/user:/bin/bash ``` Reviewed-by: Alejandro Colomar Signed-off-by: Tobias Stoeckmann --- diff --git a/src/usermod.c b/src/usermod.c index 5be0cf990..30acde424 100644 --- a/src/usermod.c +++ b/src/usermod.c @@ -1807,7 +1807,7 @@ static void usr_update(const struct option_flags *flags) } if (lflg || uflg || gflg || cflg || dflg || sflg || pflg - || Lflg || Uflg) { + || Lflg || Uflg || spwd == &spent) { if (pw_update (&pwent) == 0) { fprintf (stderr, _("%s: failed to prepare the new %s entry '%s'\n"),