]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
usermod: Update passwd entry when shadowing entry
authorTobias Stoeckmann <tobias@stoeckmann.org>
Sun, 15 Mar 2026 23:31:47 +0000 (00:31 +0100)
committerAlejandro Colomar <foss+github@alejandro-colomar.es>
Mon, 16 Mar 2026 11:03:04 +0000 (12:03 +0100)
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 <alx@kernel.org>
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
src/usermod.c

index 5be0cf9906d2c80e125986aff912a772c38f8cbb..30acde424cfa516153175a52a8ba3c5e8ed5685a 100644 (file)
@@ -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"),