summaryrefslogtreecommitdiffstats
path: root/pw/pwupd.c
diff options
context:
space:
mode:
authorBaptiste Daroussin <bapt@FreeBSD.org>2015-05-10 09:11:12 +0000
committerBaptiste Daroussin <bapt@FreeBSD.org>2015-05-10 09:11:12 +0000
commit5691ab931306852c6c08a9d01a37abbaa5ddc7c0 (patch)
treeb7e963e29eec1eb96173486f2bcaf695386cedf5 /pw/pwupd.c
parent4d66b7efe222802d3efab85f54488efbc7f97602 (diff)
downloadpw-darwin-5691ab931306852c6c08a9d01a37abbaa5ddc7c0.tar.gz
pw-darwin-5691ab931306852c6c08a9d01a37abbaa5ddc7c0.tar.zst
pw-darwin-5691ab931306852c6c08a9d01a37abbaa5ddc7c0.zip
if the check of the pw db fails return the failed value
Diffstat (limited to 'pw/pwupd.c')
-rw-r--r--pw/pwupd.c72
1 files changed, 35 insertions, 37 deletions
diff --git a/pw/pwupd.c b/pw/pwupd.c
index e8defa3..51d732e 100644
--- a/pw/pwupd.c
+++ b/pw/pwupd.c
@@ -110,45 +110,43 @@ pwdb(char *arg,...)
static int
pw_update(struct passwd * pwd, char const * user)
{
- int rc = 0;
-
- rc = pwdb("-C", (char *)NULL); /* Check only */
- if (rc == 0) {
- int pfd, tfd;
- struct passwd *pw = NULL;
- struct passwd *old_pw = NULL;
-
- if (pwd != NULL)
- pw = pw_dup(pwd);
-
- if (user != NULL)
- old_pw = GETPWNAM(user);
-
- if (pw_init(pwpath, NULL))
- err(1, "pw_init()");
- if ((pfd = pw_lock()) == -1) {
- pw_fini();
- err(1, "pw_lock()");
- }
- if ((tfd = pw_tmp(-1)) == -1) {
- pw_fini();
- err(1, "pw_tmp()");
- }
- if (pw_copy(pfd, tfd, pw, old_pw) == -1) {
- pw_fini();
- err(1, "pw_copy()");
- }
- /*
- * in case of deletion of a user, the whole database
- * needs to be regenerated
- */
- if (pw_mkdb(pw != NULL ? pw->pw_name : NULL) == -1) {
- pw_fini();
- err(1, "pw_mkdb()");
- }
- free(pw);
+ struct passwd *pw = NULL;
+ struct passwd *old_pw = NULL;
+ int rc, pfd, tfd;
+
+ if ((rc = pwdb("-C", NULL)) != 0)
+ return (rc);
+
+ if (pwd != NULL)
+ pw = pw_dup(pwd);
+
+ if (user != NULL)
+ old_pw = GETPWNAM(user);
+
+ if (pw_init(pwpath, NULL))
+ err(1, "pw_init()");
+ if ((pfd = pw_lock()) == -1) {
+ pw_fini();
+ err(1, "pw_lock()");
+ }
+ if ((tfd = pw_tmp(-1)) == -1) {
+ pw_fini();
+ err(1, "pw_tmp()");
+ }
+ if (pw_copy(pfd, tfd, pw, old_pw) == -1) {
+ pw_fini();
+ err(1, "pw_copy()");
+ }
+ /*
+ * in case of deletion of a user, the whole database
+ * needs to be regenerated
+ */
+ if (pw_mkdb(pw != NULL ? pw->pw_name : NULL) == -1) {
pw_fini();
+ err(1, "pw_mkdb()");
}
+ free(pw);
+ pw_fini();
return (0);
}