if the check of the pw db fails return the failed value

This commit is contained in:
Baptiste Daroussin 2015-05-10 09:11:12 +00:00
parent f116422f38
commit b1a215787d

View File

@ -110,45 +110,43 @@ pwdb(char *arg,...)
static int static int
pw_update(struct passwd * pwd, char const * user) pw_update(struct passwd * pwd, char const * user)
{ {
int rc = 0; struct passwd *pw = NULL;
struct passwd *old_pw = NULL;
int rc, pfd, tfd;
rc = pwdb("-C", (char *)NULL); /* Check only */ if ((rc = pwdb("-C", NULL)) != 0)
if (rc == 0) { return (rc);
int pfd, tfd;
struct passwd *pw = NULL;
struct passwd *old_pw = NULL;
if (pwd != NULL) if (pwd != NULL)
pw = pw_dup(pwd); pw = pw_dup(pwd);
if (user != NULL) if (user != NULL)
old_pw = GETPWNAM(user); old_pw = GETPWNAM(user);
if (pw_init(pwpath, NULL)) if (pw_init(pwpath, NULL))
err(1, "pw_init()"); err(1, "pw_init()");
if ((pfd = pw_lock()) == -1) { 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(); 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); return (0);
} }