mirror of
https://github.com/freebsd/freebsd-src
synced 2024-07-21 10:19:04 +00:00
pw: Ensure group membership is not duplicated
Fix the following problem:
1. A nonexistent user, someuser, is added to somegroup in /etc/group.
2. someuser is then created with membership in somegroup.
The entry for somegroup in /etc/group will then contain
somegroup:*:12345:someuser,someuser
With this fix, the entry will be
somegroup:*:12345:someuser
PR: 238995
Reviewed by: bapt, jrm
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D41076
(cherry picked from commit 17839f45d8
)
This commit is contained in:
parent
e5e6242f62
commit
3532d9c66e
|
@ -112,3 +112,5 @@ extern const char *Which[];
|
|||
|
||||
uintmax_t strtounum(const char * __restrict, uintmax_t, uintmax_t,
|
||||
const char ** __restrict);
|
||||
|
||||
bool grp_has_member(struct group *grp, const char *name);
|
||||
|
|
|
@ -413,7 +413,7 @@ pw_group_del(int argc, char **argv, char *arg1)
|
|||
return (EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
static bool
|
||||
bool
|
||||
grp_has_member(struct group *grp, const char *name)
|
||||
{
|
||||
int j;
|
||||
|
|
|
@ -1454,6 +1454,9 @@ pw_user_add(int argc, char **argv, char *arg1)
|
|||
if (cmdcnf->groups != NULL) {
|
||||
for (i = 0; i < cmdcnf->groups->sl_cur; i++) {
|
||||
grp = GETGRNAM(cmdcnf->groups->sl_str[i]);
|
||||
/* gr_add doesn't check if new member is already in group */
|
||||
if (grp_has_member(grp, pwd->pw_name))
|
||||
continue;
|
||||
grp = gr_add(grp, pwd->pw_name);
|
||||
/*
|
||||
* grp can only be NULL in 2 cases:
|
||||
|
|
Loading…
Reference in a new issue