]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
newusers: Add missing error handling
authorAlejandro Colomar <alx@kernel.org>
Sat, 4 Feb 2023 19:52:54 +0000 (20:52 +0100)
committerSerge Hallyn <serge@hallyn.com>
Fri, 26 May 2023 02:22:08 +0000 (21:22 -0500)
Some errors were being reported in stderr, but then they weren't really
being treated as errors.

If mkdir(2) for EEXIST, it's possible that the sysadmin pre-created the
user dir; don't fail.  However, let's keep a log line, for having some
notice that it happened.

Also, run chmod(2) if mkdir(2) failed for EEXIST (so transform the
'else if' into an 'if').

Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
src/newusers.c

index dd6b442120a7a633b90c2e5458bd97f0de6afb62..7ff62c9cde3458d5a3a65917982c1b8be529e55e 100644 (file)
@@ -1252,13 +1252,20 @@ int main (int argc, char **argv)
                                         _("%s: line %d: mkdir %s failed: %s\n"),
                                         Prog, line, newpw.pw_dir,
                                         strerror (errno));
-                       } else if (chown (newpw.pw_dir,
+                               if (errno != EEXIST) {
+                                       errors++;
+                                       continue;
+                               }
+                       }
+                       if (chown (newpw.pw_dir,
                                          newpw.pw_uid,
                                          newpw.pw_gid) != 0) {
                                fprintf (stderr,
                                         _("%s: line %d: chown %s failed: %s\n"),
                                         Prog, line, newpw.pw_dir,
                                         strerror (errno));
+                               errors++;
+                               continue;
                        }
                }
 
@@ -1285,12 +1292,15 @@ int main (int argc, char **argv)
                                        fprintf (stderr,
                                                _("%s: failed to prepare new %s entry\n"),
                                                Prog, sub_uid_dbname ());
+                                       errors++;
+                                       continue;
                                }
                        } else {
                                fprintf (stderr,
                                        _("%s: can't find subordinate user range\n"),
                                        Prog);
                                errors++;
+                               continue;
                        }
                }
 
@@ -1305,12 +1315,15 @@ int main (int argc, char **argv)
                                        fprintf (stderr,
                                                _("%s: failed to prepare new %s entry\n"),
                                                Prog, sub_uid_dbname ());
+                                       errors++;
+                                       continue;
                                }
                        } else {
                                fprintf (stderr,
                                        _("%s: can't find subordinate group range\n"),
                                        Prog);
                                errors++;
+                               continue;
                        }
                }
 #endif                         /* ENABLE_SUBIDS */