From 406891bd852b21f4a6469bac735795902e2893dc Mon Sep 17 00:00:00 2001 From: David Nugent Date: Tue, 26 Oct 1999 04:27:14 +0000 Subject: 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] --- pw/pwupd.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'pw/pwupd.c') 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); } } } -- cgit v1.2.3