Fix setting uid/gid min/max via pw

This commit is contained in:
Baptiste Daroussin 2015-06-07 20:59:59 +00:00
parent a68fbadb63
commit 1718a38ffd
4 changed files with 87 additions and 5 deletions

View File

@ -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,

View File

@ -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

View File

@ -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

View File

@ -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
}