svn commit: r273779 - in head/usr.sbin/pw: . tests
Baptiste Daroussin
bapt at FreeBSD.org
Tue Oct 28 14:19:19 UTC 2014
Author: bapt
Date: Tue Oct 28 14:19:17 2014
New Revision: 273779
URL: https://svnweb.freebsd.org/changeset/base/273779
Log:
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 at gmail.com
MFC after: 1 week
Modified:
head/usr.sbin/pw/pw_user.c
head/usr.sbin/pw/tests/pw_modify.sh
Modified: head/usr.sbin/pw/pw_user.c
==============================================================================
--- head/usr.sbin/pw/pw_user.c Tue Oct 28 14:11:54 2014 (r273778)
+++ head/usr.sbin/pw/pw_user.c Tue Oct 28 14:19:17 2014 (r273779)
@@ -751,7 +751,25 @@ pw_user(struct userconf * cnf, int mode,
*/
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);
Modified: head/usr.sbin/pw/tests/pw_modify.sh
==============================================================================
--- head/usr.sbin/pw/tests/pw_modify.sh Tue Oct 28 14:11:54 2014 (r273778)
+++ head/usr.sbin/pw/tests/pw_modify.sh Tue Oct 28 14:19:17 2014 (r273779)
@@ -38,8 +38,29 @@ groupmod_bug_193704_body() {
atf_check -s exit:65 -e match:"^pw: unknown group" -x pw -V ${HOME} groupshow test
}
+atf_test_case usermod_bug_185666
+usermod_bug_185666_head() {
+ atf_set "descr" "Regression test for the #185666 bug"
+}
+
+usermod_bug_185666_body() {
+ populate_etc_skel
+ atf_check -s exit:0 -x pw -V ${HOME} useradd testuser
+ atf_check -s exit:0 -x pw -V ${HOME} groupadd testgroup
+ atf_check -s exit:0 -x pw -V ${HOME} groupadd testgroup2
+ atf_check -s exit:0 -x pw -V ${HOME} usermod testuser -G testgroup
+ atf_check -o inline:"testuser:*:1001:\n" -x pw -V${HOME} groupshow testuser
+ atf_check -o inline:"testgroup:*:1002:testuser\n" -x pw -V ${HOME} groupshow testgroup
+ atf_check -o inline:"testgroup2:*:1003:\n" -x pw -V${HOME} groupshow testgroup2
+ atf_check -s exit:0 -x pw -V ${HOME} usermod testuser -G testgroup2
+ atf_check -o inline:"testuser:*:1001:\n" -x pw -V ${HOME} groupshow testuser
+ atf_check -o inline:"testgroup:*:1002:\n" -x pw -V ${HOME} groupshow testgroup
+ atf_check -o inline:"testgroup2:*:1003:testuser\n" -x pw -V ${HOME} groupshow testgroup2
+}
+
atf_init_test_cases() {
atf_add_test_case groupmod_user
atf_add_test_case groupmod_invalid_user
atf_add_test_case groupmod_bug_193704
+ atf_add_test_case usermod_bug_185666
}
More information about the svn-src-head
mailing list