diff options
author | David Nugent <davidn@FreeBSD.org> | 1999-10-26 04:27:14 +0000 |
---|---|---|
committer | David Nugent <davidn@FreeBSD.org> | 1999-10-26 04:27:14 +0000 |
commit | a1f21c386dbe541a822f224ae7bdedc71ed3ec70 (patch) | |
tree | d014ed41896e364c56fd8b48ffe4aedbf76acf52 /pw/pwupd.c | |
parent | 94dc05fe8b863b3148807bd3c0c9ae4b5a216c39 (diff) | |
download | pw-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.c | 17 |
1 files changed, 10 insertions, 7 deletions
@@ -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); } } } |