]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
usermod: only lock shadow file as needed
authorPat Riehecky <riehecky@fnal.gov>
Mon, 9 Mar 2026 16:43:12 +0000 (11:43 -0500)
committerAlejandro Colomar <foss+github@alejandro-colomar.es>
Mon, 16 Mar 2026 23:49:08 +0000 (00:49 +0100)
When setting user attributes that have nothing to do with shadow
we don't need to lock it.

Closes: https://github.com/shadow-maint/shadow/issues/1540
Signed-off-by: Pat Riehecky <riehecky@fnal.gov>
src/usermod.c

index 30acde424cfa516153175a52a8ba3c5e8ed5685a..27fba2bfb2872ad290bdbe61234a77399530676c 100644 (file)
@@ -1652,18 +1652,20 @@ static void open_files (bool process_selinux)
                         Prog, pw_dbname ());
                fail_exit (E_PW_UPDATE, process_selinux);
        }
-       if (is_shadow_pwd && (spw_lock () == 0)) {
-               fprintf (stderr,
-                        _("%s: cannot lock %s; try again later.\n"),
-                        Prog, spw_dbname ());
-               fail_exit (E_PW_UPDATE, process_selinux);
-       }
-       spw_locked = true;
-       if (is_shadow_pwd && (spw_open (O_CREAT | O_RDWR) == 0)) {
-               fprintf (stderr,
-                        _("%s: cannot open %s\n"),
-                        Prog, spw_dbname ());
-               fail_exit (E_PW_UPDATE, process_selinux);
+       if (is_shadow_pwd && (lflg || pflg || eflg || fflg || Lflg || Uflg)) {
+               if (spw_lock () == 0) {
+                       fprintf (stderr,
+                               _("%s: cannot lock %s; try again later.\n"),
+                               Prog, spw_dbname ());
+                       fail_exit (E_PW_UPDATE, process_selinux);
+               }
+               spw_locked = true;
+               if (is_shadow_pwd && (spw_open (O_CREAT | O_RDWR) == 0)) {
+                       fprintf (stderr,
+                               _("%s: cannot open %s\n"),
+                               Prog, spw_dbname ());
+                       fail_exit (E_PW_UPDATE, process_selinux);
+               }
        }
 
        if (Gflg || lflg) {