diff options
author | davidn <davidn@FreeBSD.org> | 1999-10-26 04:27:14 +0000 |
---|---|---|
committer | davidn <davidn@FreeBSD.org> | 1999-10-26 04:27:14 +0000 |
commit | 7f7ff280d14b2c60d92e922c66eb7f433fb633ce (patch) | |
tree | 668b7aa997740786ba3a4ea82d82763d8aabd19b /usr.sbin/pw/pw_group.c | |
parent | feb9306786b253f27c2d97a6a5bed74154eaf59a (diff) | |
download | FreeBSD-src-7f7ff280d14b2c60d92e922c66eb7f433fb633ce.zip FreeBSD-src-7f7ff280d14b2c60d92e922c66eb7f433fb633ce.tar.gz |
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 'usr.sbin/pw/pw_group.c')
-rw-r--r-- | usr.sbin/pw/pw_group.c | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/usr.sbin/pw/pw_group.c b/usr.sbin/pw/pw_group.c index 3385752f..54125d8 100644 --- a/usr.sbin/pw/pw_group.c +++ b/usr.sbin/pw/pw_group.c @@ -44,12 +44,13 @@ static gid_t gr_gidpolicy(struct userconf * cnf, struct cargs * args); int pw_group(struct userconf * cnf, int mode, struct cargs * args) { + int rc; struct carg *a_name = getarg(args, 'n'); struct carg *a_gid = getarg(args, 'g'); struct carg *arg; struct group *grp = NULL; int grmembers = 0; - char **members = NULL; + char **members = NULL; static struct group fakegroup = { @@ -116,8 +117,13 @@ pw_group(struct userconf * cnf, int mode, struct cargs * args) if (mode == M_DELETE) { gid_t gid = grp->gr_gid; - if (delgrent(grp) == -1) - err(EX_IOERR, "error updating group file"); + rc = delgrent(grp); + if (rc == -1) + err(EX_IOERR, "group '%s' not available (NIS?)", grp->gr_name); + else if (rc != 0) { + warnc(rc, "group update"); + return EX_IOERR; + } pw_log(cnf, mode, W_GROUP, "%s(%ld) removed", a_name->val, (long) gid); return EXIT_SUCCESS; } else if (mode == M_PRINT) @@ -231,8 +237,17 @@ pw_group(struct userconf * cnf, int mode, struct cargs * args) if (getarg(args, 'N') != NULL) return print_group(grp, getarg(args, 'P') != NULL); - if ((mode == M_ADD && !addgrent(grp)) || (mode == M_UPDATE && !chggrent(a_name->val, grp))) { - warn("group update"); + if (mode == M_ADD && (rc = addgrent(grp)) != 0) { + if (rc == -1) + warnx("group '%s' already exists", grp->gr_name); + else + warn("group update"); + return EX_IOERR; + } else if (mode == M_UPDATE && (rc = chggrent(a_name->val, grp)) != 0) { + if (rc == -1) + warnx("group '%s' not available (NIS?)", grp->gr_name); + else + warnc(rc, "group update"); return EX_IOERR; } /* grp may have been invalidated */ |