diff options
author | bapt <bapt@FreeBSD.org> | 2015-05-10 09:11:12 +0000 |
---|---|---|
committer | bapt <bapt@FreeBSD.org> | 2015-05-10 09:11:12 +0000 |
commit | 15b9b89c4b7a0738de63352a135357af5773cc5a (patch) | |
tree | 0c9df1d0ecf9d2e79e2fbe415915b432f00501de /usr.sbin/pw | |
parent | d7675fcc44b57e392fd44556e318ef8711088c98 (diff) | |
download | FreeBSD-src-15b9b89c4b7a0738de63352a135357af5773cc5a.zip FreeBSD-src-15b9b89c4b7a0738de63352a135357af5773cc5a.tar.gz |
if the check of the pw db fails return the failed value
Diffstat (limited to 'usr.sbin/pw')
-rw-r--r-- | usr.sbin/pw/pwupd.c | 72 |
1 files changed, 35 insertions, 37 deletions
diff --git a/usr.sbin/pw/pwupd.c b/usr.sbin/pw/pwupd.c index e8defa3..51d732e 100644 --- a/usr.sbin/pw/pwupd.c +++ b/usr.sbin/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); } |