summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEd Maste <emaste@FreeBSD.org>2017-08-19 00:19:23 +0000
committerEd Maste <emaste@FreeBSD.org>2017-08-19 00:19:23 +0000
commitadfec1630313d82cd79f0d7a2ecefc14629fd610 (patch)
tree21808d7275153c17d057b40c146c00b7b22b2ddd
parent7d4c28e4721cd108ebe5e39a581ec187d75cca8d (diff)
downloadpw-darwin-adfec1630313d82cd79f0d7a2ecefc14629fd610.tar.gz
pw-darwin-adfec1630313d82cd79f0d7a2ecefc14629fd610.tar.zst
pw-darwin-adfec1630313d82cd79f0d7a2ecefc14629fd610.zip
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
-rw-r--r--pw/pw_user.c4
-rwxr-xr-xpw/tests/pw_usermod_test.sh3
2 files changed, 5 insertions, 2 deletions
diff --git a/pw/pw_user.c b/pw/pw_user.c
index 76849ba..a71be12 100644
--- a/pw/pw_user.c
+++ b/pw/pw_user.c
@@ -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));
}
}
diff --git a/pw/tests/pw_usermod_test.sh b/pw/tests/pw_usermod_test.sh
index 6a13130..cf3622f 100755
--- a/pw/tests/pw_usermod_test.sh
+++ b/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