pw: Use existing group entry, even if it already has members

Fix the following problem:

1. A nonexistent user, someuser, is added to /etc/group as
   someuser:*:12345:someuser.
2. someuser is then created with the default login group.

A second group entry for someuser will be created.

   someuser:*:12345:someuser
   someuser:*:12346:

With this fix, the existing group entry will be used.

PR:		238995
Reviewed by:	bapt, jrm
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D41057
This commit is contained in:
Naman Sood 2023-07-19 10:06:06 -03:00 committed by Joseph Mingrone
parent 17839f45d8
commit 1a8d37b8cf
No known key found for this signature in database
GPG Key ID: 36A40C83B0D6EF9E

View File

@ -378,8 +378,7 @@ pw_gidpolicy(struct userconf *cnf, char *grname, char *nam, gid_t prefer, bool d
grp = GETGRGID(gid);
}
gid = grp->gr_gid;
} else if ((grp = GETGRNAM(nam)) != NULL &&
(grp->gr_mem == NULL || grp->gr_mem[0] == NULL)) {
} else if ((grp = GETGRNAM(nam)) != NULL) {
gid = grp->gr_gid; /* Already created? Use it anyway... */
} else {
intmax_t grid = -1;