summaryrefslogtreecommitdiffstats
path: root/pw/pw_user.c
diff options
context:
space:
mode:
authorDevin Teske <dteske@FreeBSD.org>2014-03-13 18:16:42 +0000
committerDevin Teske <dteske@FreeBSD.org>2014-03-13 18:16:42 +0000
commite6492afede9f8b4ea72e5f914d52ca1caf8d65b6 (patch)
tree4597a772ee54587127e1c70eef7a5e0678a883b4 /pw/pw_user.c
parent889d60cc0abedae41354ac84f92cbbb60cc1d5d7 (diff)
downloadpw-darwin-e6492afede9f8b4ea72e5f914d52ca1caf8d65b6.tar.gz
pw-darwin-e6492afede9f8b4ea72e5f914d52ca1caf8d65b6.tar.zst
pw-darwin-e6492afede9f8b4ea72e5f914d52ca1caf8d65b6.zip
Fix pw(8) deletion of group "username" on userdel even if group "username"
is not associated with user "username". E.g., user "foo" has primary group "wheel" and is unassociated with group "foo", yet userdel would delete the group "foo" when deleting user "foo" (despite the fact that user "foo" is not associated with group "foo" in any way). Patch committed with minor style(9) changes. PR: bin/169471 Submitted by: Alexander Pyhalov <apyhalov@gmail.com>
Diffstat (limited to 'pw/pw_user.c')
-rw-r--r--pw/pw_user.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/pw/pw_user.c b/pw/pw_user.c
index e49de18..4b3f550 100644
--- a/pw/pw_user.c
+++ b/pw/pw_user.c
@@ -380,6 +380,8 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args)
char file[MAXPATHLEN];
char home[MAXPATHLEN];
uid_t uid = pwd->pw_uid;
+ struct group *gr;
+ char grname[LOGNAMESIZE];
if (strcmp(pwd->pw_name, "root") == 0)
errx(EX_DATAERR, "cannot remove user 'root'");
@@ -406,6 +408,11 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args)
*/
sprintf(file, "%s/%s", _PATH_MAILDIR, pwd->pw_name);
strlcpy(home, pwd->pw_dir, sizeof(home));
+ gr = GETGRGID(pwd->pw_gid);
+ if (gr != NULL)
+ strlcpy(grname, gr->gr_name, LOGNAMESIZE);
+ else
+ grname[0] = '\0';
rc = delpwent(pwd);
if (rc == -1)
@@ -426,7 +433,8 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args)
grp = GETGRNAM(a_name->val);
if (grp != NULL &&
- (grp->gr_mem == NULL || *grp->gr_mem == NULL))
+ (grp->gr_mem == NULL || *grp->gr_mem == NULL) &&
+ strcmp(a_name->val, grname) == 0)
delgrent(GETGRNAM(a_name->val));
SETGRENT();
while ((grp = GETGRENT()) != NULL) {