diff options
author | Alejandro Colomar <alx@kernel.org> | 2023-02-04 20:52:54 +0100 |
---|---|---|
committer | Serge Hallyn <serge@hallyn.com> | 2023-05-25 21:22:08 -0500 |
commit | 1957c8c881e232843a8d1617d66f223bf1e229c9 (patch) | |
tree | f6511a250e84ab6b464c698e5205a58d20148726 | |
parent | 6491fef1e0be72661aa8ed60d3784d4426f41c76 (diff) |
newusers: Add missing error handling
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>
-rw-r--r-- | src/newusers.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/newusers.c b/src/newusers.c index dd6b4421..7ff62c9c 100644 --- a/src/newusers.c +++ b/src/newusers.c @@ -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 */ |