summaryrefslogtreecommitdiffstats
path: root/pw
diff options
context:
space:
mode:
authorBaptiste Daroussin <bapt@FreeBSD.org>2015-01-24 19:13:03 +0000
committerBaptiste Daroussin <bapt@FreeBSD.org>2015-01-24 19:13:03 +0000
commit781a5b787624a2cd0208bf63bc1c0572e182a306 (patch)
treef71f92f914ca8bb490ff0c9a7db9c78426deb3bd /pw
parent9d27d4e8bf692d371fe7363d3e4b6613c5a8881a (diff)
downloadpw-darwin-781a5b787624a2cd0208bf63bc1c0572e182a306.tar.gz
pw-darwin-781a5b787624a2cd0208bf63bc1c0572e182a306.tar.zst
pw-darwin-781a5b787624a2cd0208bf63bc1c0572e182a306.zip
Allow negative numbers in -u and -g options
PR: 196514 MFC after: 1 week
Diffstat (limited to 'pw')
-rw-r--r--pw/pw_group.c6
-rw-r--r--pw/pw_user.c5
-rw-r--r--pw/tests/Makefile4
-rwxr-xr-xpw/tests/pw_groupshow.sh19
-rwxr-xr-xpw/tests/pw_usershow.sh19
5 files changed, 50 insertions, 3 deletions
diff --git a/pw/pw_group.c b/pw/pw_group.c
index b20ce88..51166cd 100644
--- a/pw/pw_group.c
+++ b/pw/pw_group.c
@@ -68,7 +68,11 @@ pw_group(struct userconf * cnf, int mode, struct cargs * args)
};
if (a_gid != NULL) {
- if (strspn(a_gid->val, "0123456789") != strlen(a_gid->val))
+ const char *teststr;
+ teststr = a_gid->val;
+ if (*teststr == '-')
+ teststr++;
+ if (strspn(teststr, "0123456789") != strlen(teststr))
errx(EX_USAGE, "-g expects a number");
}
diff --git a/pw/pw_user.c b/pw/pw_user.c
index 483148a..f146b46 100644
--- a/pw/pw_user.c
+++ b/pw/pw_user.c
@@ -322,7 +322,10 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args)
a_name = NULL;
}
} else {
- if (strspn(a_uid->val, "0123456789") != strlen(a_uid->val))
+ const char *teststr = a_uid->val;
+ if (*teststr == '-')
+ teststr++;
+ if (strspn(teststr, "0123456789") != strlen(teststr))
errx(EX_USAGE, "-u expects a number");
}
diff --git a/pw/tests/Makefile b/pw/tests/Makefile
index 1283ff2..c609884 100644
--- a/pw/tests/Makefile
+++ b/pw/tests/Makefile
@@ -9,9 +9,11 @@ ATF_TESTS_SH= pw_etcdir \
pw_lock \
pw_groupdel \
pw_groupmod \
+ pw_groupshow \
pw_useradd \
pw_userdel \
- pw_usermod
+ pw_usermod \
+ pw_usershow
.for tp in ${ATF_TESTS_SH}
TEST_METADATA.${tp}+= required_user="root"
diff --git a/pw/tests/pw_groupshow.sh b/pw/tests/pw_groupshow.sh
new file mode 100755
index 0000000..2ba53d6
--- /dev/null
+++ b/pw/tests/pw_groupshow.sh
@@ -0,0 +1,19 @@
+# $FreeBSD$
+
+# Import helper functions
+. $(atf_get_srcdir)/helper_functions.shin
+
+
+# Test negative uid are still valid
+# PR: 196514
+atf_test_case show_group_with_negative_number
+show_group_with_negative_number_body() {
+ populate_etc_skel
+ atf_check -s exit:0 \
+ -o inline:"wheel:*:0:root\n" \
+ ${PW} groupshow -n wheel -g -1
+}
+
+atf_init_test_cases() {
+ atf_add_test_case show_group_with_negative_number
+}
diff --git a/pw/tests/pw_usershow.sh b/pw/tests/pw_usershow.sh
new file mode 100755
index 0000000..4703644
--- /dev/null
+++ b/pw/tests/pw_usershow.sh
@@ -0,0 +1,19 @@
+# $FreeBSD$
+
+# Import helper functions
+. $(atf_get_srcdir)/helper_functions.shin
+
+
+# Test negative uid are still valid
+# PR: 196514
+atf_test_case show_user_with_negative_number
+show_user_with_negative_number_body() {
+ populate_etc_skel
+ atf_check -s exit:0 \
+ -o inline:"root:*:0:0::0:0:Charlie &:/root:/bin/csh\n" \
+ ${PW} usershow -n root -u -1
+}
+
+atf_init_test_cases() {
+ atf_add_test_case show_user_with_negative_number
+}