]> git.cameronkatri.com Git - pw-darwin.git/commitdiff
pw usermod: Properly deal with empty secondary group lists (-G '')
authorEd Maste <emaste@FreeBSD.org>
Sat, 19 Aug 2017 00:19:23 +0000 (00:19 +0000)
committerEd Maste <emaste@FreeBSD.org>
Sat, 19 Aug 2017 00:19:23 +0000 (00:19 +0000)
"pw usermod someuser -G ''" is supposed make sure that someuser
doesn't have any secondary group memberships.

Previouly it was a nop because split_groups() only intitialised
"groups" if at least one group was specified. As a result the
existing secondary group memberships were kept.

PR: 221417
Submitted by: Fabian Keil
Obtained from: ElectroBSD
MFC after: 1 week
Relnotes: yes

pw/pw_user.c

index 76849ba9554633ff4107423cf15b4616f3503ee6..a71be12def408c57dea6dc2af3084725f8d15fc6 100644 (file)
@@ -1087,10 +1087,10 @@ split_groups(StringList **groups, char *groupsstr)
        char *p;
        char tok[] = ", \t";
 
+       if (*groups == NULL)
+               *groups = sl_init();
        for (p = strtok(groupsstr, tok); p != NULL; p = strtok(NULL, tok)) {
                grp = group_from_name_or_id(p);
-               if (*groups == NULL)
-                       *groups = sl_init();
                sl_add(*groups, newstr(grp->gr_name));
        }
 }