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
commita1f21c386dbe541a822f224ae7bdedc71ed3ec70 (patch)
treed014ed41896e364c56fd8b48ffe4aedbf76acf52 /pw/pwupd.c
parent94dc05fe8b863b3148807bd3c0c9ae4b5a216c39 (diff)
downloadpw-darwin-a1f21c386dbe541a822f224ae7bdedc71ed3ec70.tar.gz
pw-darwin-a1f21c386dbe541a822f224ae7bdedc71ed3ec70.tar.zst
pw-darwin-a1f21c386dbe541a822f224ae7bdedc71ed3ec70.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);
}
}
}