Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 28 Oct 2014 16:27:29 +0000 (UTC)
From:      Baptiste Daroussin <bapt@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r273791 - in head: lib/libutil usr.sbin/pw/tests
Message-ID:  <201410281627.s9SGRT7S041916@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: bapt
Date: Tue Oct 28 16:27:29 2014
New Revision: 273791
URL: https://svnweb.freebsd.org/changeset/base/273791

Log:
  Fix renaming a group via the gr_copy function
  
  Add a regression test to pw(8) because the bug was discovered via using:
  pw groupmod
  
  PR:		187189
  Reported by:	mcdouga9@egr.msu.edu
  Tested by:	mcdouga9@egr.msu.edu
  Patch by:	Marc de la Gueronniere

Modified:
  head/lib/libutil/gr_util.c
  head/usr.sbin/pw/tests/pw_modify.sh

Modified: head/lib/libutil/gr_util.c
==============================================================================
--- head/lib/libutil/gr_util.c	Tue Oct 28 16:24:44 2014	(r273790)
+++ head/lib/libutil/gr_util.c	Tue Oct 28 16:27:29 2014	(r273791)
@@ -170,14 +170,21 @@ gr_copy(int ffd, int tfd, const struct g
 	size_t len;
 	int eof, readlen;
 
-	sgr = gr;
+	if (old_gr == NULL && gr == NULL)
+		return(-1);
+
+	sgr = old_gr;
+	/* deleting a group */
 	if (gr == NULL) {
 		line = NULL;
-		if (old_gr == NULL)
+	} else {
+		if ((line = gr_make(gr)) == NULL)
 			return (-1);
-		sgr = old_gr;
-	} else if ((line = gr_make(gr)) == NULL)
-		return (-1);
+	}
+
+	/* adding a group */
+	if (sgr == NULL)
+		sgr = gr;
 
 	eof = 0;
 	len = 0;

Modified: head/usr.sbin/pw/tests/pw_modify.sh
==============================================================================
--- head/usr.sbin/pw/tests/pw_modify.sh	Tue Oct 28 16:24:44 2014	(r273790)
+++ head/usr.sbin/pw/tests/pw_modify.sh	Tue Oct 28 16:27:29 2014	(r273791)
@@ -58,9 +58,23 @@ usermod_bug_185666_body() {
 	atf_check -o inline:"testgroup2:*:1003:testuser\n" -x pw -V ${HOME} groupshow testgroup2
 }
 
+atf_test_case do_not_duplicate_group_on_gid_change
+do_not_duplicate_group_on_gid_change_head() {
+	atf_set "descr" "Do not duplicate group on gid change"
+}
+
+do_not_duplicate_group_on_gid_change_body() {
+	populate_etc_skel
+	atf_check -s exit:0 -x pw -V ${HOME} groupadd testgroup
+	atf_check -s exit:0 -x pw -V ${HOME} groupmod testgroup -g 12345
+	# use grep to see if the entry has not be duplicated
+	atf_check -o inline:"testgroup:*:12345:\n" -s exit:0 -x grep "^testgroup" ${HOME}/group
+}
+
 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
+	atf_add_test_case do_not_duplicate_group_on_gid_change
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201410281627.s9SGRT7S041916>