svn commit: r284137 - in head/usr.sbin/pw: . tests

Baptiste Daroussin bapt at FreeBSD.org
Sun Jun 7 21:00:01 UTC 2015


Author: bapt
Date: Sun Jun  7 20:59:59 2015
New Revision: 284137
URL: https://svnweb.freebsd.org/changeset/base/284137

Log:
  Fix setting uid/gid min/max via pw

Added:
  head/usr.sbin/pw/tests/pw-modified.conf
     - copied, changed from r284135, head/usr.sbin/pw/tests/pw.conf
Modified:
  head/usr.sbin/pw/pw.c
  head/usr.sbin/pw/tests/Makefile
  head/usr.sbin/pw/tests/pw_config.sh

Modified: head/usr.sbin/pw/pw.c
==============================================================================
--- head/usr.sbin/pw/pw.c	Sun Jun  7 20:45:13 2015	(r284136)
+++ head/usr.sbin/pw/pw.c	Sun Jun  7 20:59:59 2015	(r284137)
@@ -251,11 +251,20 @@ main(int argc, char *argv[])
 				addarg(&arglist, 'g', optarg);
 				break;
 			}
-			/* FALLTHROUGH */
-		case 'u':
 			if (strspn(optarg, "0123456789") != strlen(optarg))
-				errx(EX_USAGE, "%s expects a number",
-				    which == 1 ? "-g" : "-u" );
+				errx(EX_USAGE, "-g expects a number");
+			id = strtonum(optarg, 0, LONG_MAX, &errstr);
+			if (errstr != NULL)
+				errx(EX_USAGE, "Bad id '%s': %s", optarg,
+				    errstr);
+			break;
+		case 'u':
+			if (strspn(optarg, "0123456789,") != strlen(optarg))
+				errx(EX_USAGE, "-u expects a number");
+			if (strchr(optarg, ',') != NULL) {
+				addarg(&arglist, 'u', optarg);
+				break;
+			}
 			id = strtonum(optarg, 0, LONG_MAX, &errstr);
 			if (errstr != NULL)
 				errx(EX_USAGE, "Bad id '%s': %s", optarg,

Modified: head/usr.sbin/pw/tests/Makefile
==============================================================================
--- head/usr.sbin/pw/tests/Makefile	Sun Jun  7 20:45:13 2015	(r284136)
+++ head/usr.sbin/pw/tests/Makefile	Sun Jun  7 20:59:59 2015	(r284137)
@@ -19,7 +19,8 @@ ATF_TESTS_SH=	pw_etcdir \
 TEST_METADATA.${tp}+=	required_user="root"
 .endfor
 
-FILES=		group helper_functions.shin master.passwd pw.conf
+FILES=		group helper_functions.shin master.passwd pw.conf \
+		pw-modified.conf
 FILESDIR=       ${TESTSDIR}
 
 ATF_TESTS_SH+=	pw_test

Copied and modified: head/usr.sbin/pw/tests/pw-modified.conf (from r284135, head/usr.sbin/pw/tests/pw.conf)
==============================================================================
--- head/usr.sbin/pw/tests/pw.conf	Sun Jun  7 20:44:06 2015	(r284135, copy source)
+++ head/usr.sbin/pw/tests/pw-modified.conf	Sun Jun  7 20:59:59 2015	(r284137)
@@ -48,12 +48,12 @@ extragroups = 
 defaultclass = ""
 
 # Range of valid default user ids
-minuid = 1000
-maxuid = 32000
+minuid = 2000
+maxuid = 5000
 
 # Range of valid default group ids
-mingid = 1000
-maxgid = 32000
+mingid = 2100
+maxgid = 6000
 
 # Days after which account expires (0=disabled)
 expire_days = 0

Modified: head/usr.sbin/pw/tests/pw_config.sh
==============================================================================
--- head/usr.sbin/pw/tests/pw_config.sh	Sun Jun  7 20:45:13 2015	(r284136)
+++ head/usr.sbin/pw/tests/pw_config.sh	Sun Jun  7 20:59:59 2015	(r284137)
@@ -11,6 +11,16 @@ generate_config_body() {
 		cat ${HOME}/foo.conf
 }
 
+atf_test_case modify_config_uid_gid_boundaries
+modify_config_uid_gid_boundaries_body() {
+	atf_check -s exit:0 \
+		${PW} useradd -D -C ${HOME}/foo.conf \
+			-u 2000,5000 -i 2100,6000
+	atf_check -o file:$(atf_get_srcdir)/pw-modified.conf \
+		cat ${HOME}/foo.conf
+}
+
 atf_init_test_cases() {
 	atf_add_test_case generate_config
+	atf_add_test_case modify_config_uid_gid_boundaries
 }


More information about the svn-src-head mailing list