Fix generating configuration file

This commit is contained in:
Baptiste Daroussin 2015-06-07 20:44:06 +00:00
parent 91860967e2
commit a68fbadb63
6 changed files with 86 additions and 6 deletions

View File

@ -229,7 +229,8 @@ main(int argc, char *argv[])
conf.v7 = true;
break;
case 'C':
config = optarg;
conf.config = optarg;
config = conf.config;
break;
case 'N':
conf.dryrun = true;

View File

@ -292,7 +292,7 @@ pw_user(int mode, char *name, long id, struct cargs * args)
if ((arg = getarg(args, 'w')) != NULL)
cnf->default_password = boolean_val(arg->val, cnf->default_password);
if (mode == M_ADD && getarg(args, 'D')) {
if (getarg(args, 'n') != NULL)
if (name != NULL)
errx(EX_DATAERR, "can't combine `-D' with `-n name'");
if ((arg = getarg(args, 'u')) != NULL && (p = strtok(arg->val, ", \t")) != NULL) {
if ((cnf->min_uid = (uid_t) atoi(p)) == 0)
@ -307,9 +307,8 @@ pw_user(int mode, char *name, long id, struct cargs * args)
cnf->max_gid = 32000;
}
arg = getarg(args, 'C');
if (write_userconfig(arg ? arg->val : NULL))
return EXIT_SUCCESS;
if (write_userconfig(conf.config))
return (EXIT_SUCCESS);
err(EX_IOERR, "config udpate");
}

View File

@ -84,6 +84,7 @@ struct pwconf {
char rootdir[MAXPATHLEN];
char etcpath[MAXPATHLEN];
char *newname;
char *config;
bool dryrun;
bool pretty;
bool v7;

View File

@ -7,6 +7,7 @@ TESTSDIR= ${TESTSBASE}/usr.sbin/pw
ATF_TESTS_SH= pw_etcdir \
pw_lock \
pw_config \
pw_groupdel \
pw_groupmod \
pw_useradd \
@ -18,7 +19,7 @@ ATF_TESTS_SH= pw_etcdir \
TEST_METADATA.${tp}+= required_user="root"
.endfor
FILES= group helper_functions.shin master.passwd
FILES= group helper_functions.shin master.passwd pw.conf
FILESDIR= ${TESTSDIR}
ATF_TESTS_SH+= pw_test

62
usr.sbin/pw/tests/pw.conf Normal file
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 = 1000
maxuid = 32000
# Range of valid default group ids
mingid = 1000
maxgid = 32000
# Days after which account expires (0=disabled)
expire_days = 0
# Days after which password expires (0=disabled)
password_days = 0

16
usr.sbin/pw/tests/pw_config.sh Executable file
View File

@ -0,0 +1,16 @@
# $FreeBSD$
# Import helper functions
. $(atf_get_srcdir)/helper_functions.shin
atf_test_case generate_config
generate_config_body() {
atf_check -s exit:0 \
${PW} useradd -D -C ${HOME}/foo.conf
atf_check -o file:$(atf_get_srcdir)/pw.conf \
cat ${HOME}/foo.conf
}
atf_init_test_cases() {
atf_add_test_case generate_config
}