Author: bapt
Date: Sat Jan 24 19:13:03 2015
New Revision: 277652
URL: https://svnweb.freebsd.org/changeset/base/277652

Log:
  Allow negative numbers in -u and -g options
  
  PR:           196514
  MFC after:    1 week

Added:
  head/usr.sbin/pw/tests/pw_groupshow.sh   (contents, props changed)
  head/usr.sbin/pw/tests/pw_usershow.sh   (contents, props changed)
Modified:
  head/usr.sbin/pw/pw_group.c
  head/usr.sbin/pw/pw_user.c
  head/usr.sbin/pw/tests/Makefile

Modified: head/usr.sbin/pw/pw_group.c
==============================================================================
--- head/usr.sbin/pw/pw_group.c Sat Jan 24 17:32:45 2015        (r277651)
+++ head/usr.sbin/pw/pw_group.c Sat Jan 24 19:13:03 2015        (r277652)
@@ -68,7 +68,11 @@ pw_group(struct userconf * cnf, int mode
        };
 
        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");
        }
 

Modified: head/usr.sbin/pw/pw_user.c
==============================================================================
--- head/usr.sbin/pw/pw_user.c  Sat Jan 24 17:32:45 2015        (r277651)
+++ head/usr.sbin/pw/pw_user.c  Sat Jan 24 19:13:03 2015        (r277652)
@@ -322,7 +322,10 @@ pw_user(struct userconf * cnf, int mode,
                        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");
        }
 

Modified: head/usr.sbin/pw/tests/Makefile
==============================================================================
--- head/usr.sbin/pw/tests/Makefile     Sat Jan 24 17:32:45 2015        
(r277651)
+++ head/usr.sbin/pw/tests/Makefile     Sat Jan 24 19:13:03 2015        
(r277652)
@@ -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"

Added: head/usr.sbin/pw/tests/pw_groupshow.sh
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/usr.sbin/pw/tests/pw_groupshow.sh      Sat Jan 24 19:13:03 2015        
(r277652)
@@ -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
+}

Added: head/usr.sbin/pw/tests/pw_usershow.sh
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/usr.sbin/pw/tests/pw_usershow.sh       Sat Jan 24 19:13:03 2015        
(r277652)
@@ -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
+}
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to