summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBaptiste Daroussin <bapt@FreeBSD.org>2014-10-28 14:19:17 +0000
committerBaptiste Daroussin <bapt@FreeBSD.org>2014-10-28 14:19:17 +0000
commit39f09169dd46aff705fef66203a371be6bfd4814 (patch)
treefd4fc9c1a04784d4b7d866a135c81e8e6553f08b
parenta08b5497602c225f5c7ae8e8bbf2ac55615158f9 (diff)
downloadpw-darwin-39f09169dd46aff705fef66203a371be6bfd4814.tar.gz
pw-darwin-39f09169dd46aff705fef66203a371be6bfd4814.tar.zst
pw-darwin-39f09169dd46aff705fef66203a371be6bfd4814.zip
Fix a regression in pw usermod -G list
The user was perperly adding the to different groups from "list" but was not removed from the other groups it could have belong to. While here add a regression test about this bug PR: 185666 Reported by: sub.mesa@gmail.com MFC after: 1 week
-rw-r--r--pw/pw_user.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/pw/pw_user.c b/pw/pw_user.c
index efb2901..0b56b81 100644
--- a/pw/pw_user.c
+++ b/pw/pw_user.c
@@ -751,7 +751,25 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args)
*/
if (mode == M_ADD || getarg(args, 'G') != NULL) {
- int i;
+ int i, j;
+ /* First remove the user from all group */
+ SETGRENT();
+ while ((grp = GETGRENT()) != NULL) {
+ char group[MAXLOGNAME];
+ if (grp->gr_mem == NULL)
+ continue;
+ for (i = 0; grp->gr_mem[i] != NULL; i++) {
+ if (strcmp(grp->gr_mem[i] , pwd->pw_name) != 0)
+ continue;
+ for (j = i; grp->gr_mem[j] != NULL ; j++)
+ grp->gr_mem[j] = grp->gr_mem[j+1];
+ strlcpy(group, grp->gr_name, MAXLOGNAME);
+ chggrent(group, grp);
+ }
+ }
+ ENDGRENT();
+
+ /* now add to group where needed */
for (i = 0; cnf->groups[i] != NULL; i++) {
grp = GETGRNAM(cnf->groups[i]);
grp = gr_add(grp, pwd->pw_name);