diff options
author | emaste <emaste@FreeBSD.org> | 2017-09-08 21:16:23 +0000 |
---|---|---|
committer | emaste <emaste@FreeBSD.org> | 2017-09-08 21:16:23 +0000 |
commit | 9cbb330f2197dd7d1108f4ce49def97e3b3b22e0 (patch) | |
tree | a2ff3570323b97e2fa3bdc5db1adca3d7d9f8a06 | |
parent | 73846ec2976bad87e4e8059d5b0264b3b6827e02 (diff) | |
download | FreeBSD-src-9cbb330f2197dd7d1108f4ce49def97e3b3b22e0.zip FreeBSD-src-9cbb330f2197dd7d1108f4ce49def97e3b3b22e0.tar.gz |
MFC r322677: pw usermod: handle 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
Approved by: re (kib)
Obtained from: ElectroBSD
Relnotes: yes
-rw-r--r-- | usr.sbin/pw/pw_user.c | 4 | ||||
-rwxr-xr-x | usr.sbin/pw/tests/pw_usermod_test.sh | 3 |
2 files changed, 5 insertions, 2 deletions
diff --git a/usr.sbin/pw/pw_user.c b/usr.sbin/pw/pw_user.c index 98a9636..62d53a4 100644 --- a/usr.sbin/pw/pw_user.c +++ b/usr.sbin/pw/pw_user.c @@ -1089,10 +1089,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)); } } diff --git a/usr.sbin/pw/tests/pw_usermod_test.sh b/usr.sbin/pw/tests/pw_usermod_test.sh index 6a13130..cf3622f 100755 --- a/usr.sbin/pw/tests/pw_usermod_test.sh +++ b/usr.sbin/pw/tests/pw_usermod_test.sh @@ -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 |