summaryrefslogtreecommitdiffstats
path: root/pw/pwupd.c
diff options
context:
space:
mode:
authorDavid Nugent <davidn@FreeBSD.org>1999-10-26 04:27:14 +0000
committerDavid Nugent <davidn@FreeBSD.org>1999-10-26 04:27:14 +0000
commit406891bd852b21f4a6469bac735795902e2893dc (patch)
tree5d83217a5353ef4f097e2eb4f222a029a082cefb /pw/pwupd.c
parente8f6c5579cf8419e33bbcba0ceef55b1cdc34145 (diff)
downloadpw-darwin-406891bd852b21f4a6469bac735795902e2893dc.tar.gz
pw-darwin-406891bd852b21f4a6469bac735795902e2893dc.zip
Clean up error handling in fileupdate(), which now returns 0 on success
instead of a boolean. This replicated through he front-end sub-functions relating to add, delete, modify entries in passwd & group files Errno is now preserved so output of errc()/warnc() will be less obfuscated by subsequent errors when reporting the problem. Add more intelligent error handling when attempting to modify/delete NIS entries with no corresponding local database entry. [MFC to stable in a couple of weeks to keep both in sync]
Diffstat (limited to 'pw/pwupd.c')
-rw-r--r--pw/pwupd.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/pw/pwupd.c b/pw/pwupd.c
index 10a6066..baaf102 100644
--- a/pw/pwupd.c
+++ b/pw/pwupd.c
@@ -92,14 +92,14 @@ pwdb(char *arg,...)
args[i] = NULL;
if ((pid = fork()) == -1) /* Error (errno set) */
- i = -1;
+ i = errno;
else if (pid == 0) { /* Child */
execv(args[0], args);
_exit(1);
} else { /* Parent */
waitpid(pid, &i, 0);
- if ((i = WEXITSTATUS(i)) != 0)
- errno = EIO; /* set SOMETHING */
+ if (WEXITSTATUS(i))
+ i = EIO;
}
return i;
}
@@ -161,18 +161,21 @@ pw_update(struct passwd * pwd, char const * user, int mode)
*pwbuf = '\0';
else
fmtpwentry(pwbuf, pwd, PWF_PASSWD);
- if ((rc = fileupdate(getpwpath(_PASSWD), 0644, pwbuf, pfx, l, mode)) != 0) {
+
+ rc = fileupdate(getpwpath(_PASSWD), 0644, pwbuf, pfx, l, mode);
+ if (rc == 0) {
/*
* Then the master.passwd file
*/
if (pwd != NULL)
fmtpwentry(pwbuf, pwd, PWF_MASTER);
- if ((rc = fileupdate(getpwpath(_MASTERPASSWD), 0644, pwbuf, pfx, l, mode)) != 0) {
+ rc = fileupdate(getpwpath(_MASTERPASSWD), 0644, pwbuf, pfx, l, mode);
+ if (rc != 0) {
if (mode == UPD_DELETE)
- rc = pwdb(NULL) == 0;
+ rc = pwdb(NULL);
else
- rc = pwdb("-u", user, NULL) == 0;
+ rc = pwdb("-u", user, NULL);
}
}
}