From 223ef3394cf724477520e801c506e253c3223c7d Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Sun, 7 Jun 2015 20:59:59 +0000 Subject: Fix setting uid/gid min/max via pw --- pw/pw.c | 17 ++++++++++--- pw/tests/Makefile | 3 ++- pw/tests/pw-modified.conf | 62 +++++++++++++++++++++++++++++++++++++++++++++++ pw/tests/pw_config.sh | 10 ++++++++ 4 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 pw/tests/pw-modified.conf diff --git a/pw/pw.c b/pw/pw.c index d8d8c03..30fb55b 100644 --- a/pw/pw.c +++ b/pw/pw.c @@ -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, diff --git a/pw/tests/Makefile b/pw/tests/Makefile index 09fe93c..193b8ab 100644 --- a/pw/tests/Makefile +++ b/pw/tests/Makefile @@ -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 diff --git a/pw/tests/pw-modified.conf b/pw/tests/pw-modified.conf new file mode 100644 index 0000000..84f44e7 --- /dev/null +++ b/pw/tests/pw-modified.conf @@ -0,0 +1,62 @@ +# +# pw.conf - user/group configuration defaults +# + +# Password for new users? no=nologin yes=loginid none=blank random=random +defaultpasswd = "no" + +# Reuse gaps in uid sequence? (yes or no) +reuseuids = "no" + +# Reuse gaps in gid sequence? (yes or no) +reusegids = "no" + +# Path to the NIS passwd file (blank or 'no' for none) +nispasswd = + +# Obtain default dotfiles from this directory +skeleton = "/usr/share/skel" + +# Mail this file to new user (/etc/newuser.msg or no) +newmail = "no" + +# Log add/change/remove information in this file +logfile = "/var/log/userlog" + +# Root directory in which $HOME directory is created +home = "/home" + +# Mode for the new $HOME directory, will be modified by umask +homemode = 0777 + +# Colon separated list of directories containing valid shells +shellpath = "/bin" + +# Comma separated list of available shells (without paths) +shells = "sh","csh","tcsh" + +# Default shell (without path) +defaultshell = "sh" + +# Default group (leave blank for new group per user) +defaultgroup = "" + +# Extra groups for new users +extragroups = + +# Default login class for new users +defaultclass = "" + +# Range of valid default user ids +minuid = 2000 +maxuid = 5000 + +# Range of valid default group ids +mingid = 2100 +maxgid = 6000 + +# Days after which account expires (0=disabled) +expire_days = 0 + +# Days after which password expires (0=disabled) +password_days = 0 diff --git a/pw/tests/pw_config.sh b/pw/tests/pw_config.sh index b5a4fad..fb6489a 100755 --- a/pw/tests/pw_config.sh +++ b/pw/tests/pw_config.sh @@ -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 } -- cgit v1.2.3-56-ge451