Author: emaste
Date: Sat Aug 19 00:19:23 2017
New Revision: 322677
URL: https://svnweb.freebsd.org/changeset/base/322677

Log:
  pw usermod: Properly deal with empty secondary group lists (-G '')
  
  "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

Modified:
  head/usr.sbin/pw/pw_user.c
  head/usr.sbin/pw/tests/pw_usermod_test.sh

Modified: head/usr.sbin/pw/pw_user.c
==============================================================================
--- head/usr.sbin/pw/pw_user.c  Fri Aug 18 21:37:26 2017        (r322676)
+++ head/usr.sbin/pw/pw_user.c  Sat Aug 19 00:19:23 2017        (r322677)
@@ -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));
        }
 }

Modified: head/usr.sbin/pw/tests/pw_usermod_test.sh
==============================================================================
--- head/usr.sbin/pw/tests/pw_usermod_test.sh   Fri Aug 18 21:37:26 2017        
(r322676)
+++ head/usr.sbin/pw/tests/pw_usermod_test.sh   Sat Aug 19 00:19:23 2017        
(r322677)
@@ -128,6 +128,9 @@ user_mod_nogroups_body() {
        atf_check -s exit:0 ${PW} usermod foo -G test3,test4
        atf_check -s exit:0 -o inline:"test3\ntest4\n" \
                awk -F\: '$4 == "foo" { print $1 }' ${HOME}/group
+       atf_check -s exit:0 ${PW} usermod foo -G ""
+       atf_check -s exit:0 -o empty \
+               awk -F\: '$4 == "foo" { print $1 }' ${HOME}/group
 }
 
 atf_test_case user_mod_rename
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to