summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBaptiste Daroussin <bapt@FreeBSD.org>2015-06-07 20:44:06 +0000
committerBaptiste Daroussin <bapt@FreeBSD.org>2015-06-07 20:44:06 +0000
commitd1593426badd25926a46d772133118bc1d3aab7b (patch)
tree56d4cb38ba7295ac4bfebaa0e5b1f889b8cbb569
parentacdde8a5fd9f78f37032cd8801a0731e96c5a119 (diff)
downloadpw-darwin-d1593426badd25926a46d772133118bc1d3aab7b.tar.gz
pw-darwin-d1593426badd25926a46d772133118bc1d3aab7b.tar.zst
pw-darwin-d1593426badd25926a46d772133118bc1d3aab7b.zip
Fix generating configuration file
-rw-r--r--pw/pw.c3
-rw-r--r--pw/pw_user.c7
-rw-r--r--pw/pwupd.h1
-rw-r--r--pw/tests/Makefile3
-rw-r--r--pw/tests/pw.conf62
-rwxr-xr-xpw/tests/pw_config.sh16
6 files changed, 86 insertions, 6 deletions
diff --git a/pw/pw.c b/pw/pw.c
index a311572..d8d8c03 100644
--- a/pw/pw.c
+++ b/pw/pw.c
@@ -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;
diff --git a/pw/pw_user.c b/pw/pw_user.c
index c567e68..c3b2751 100644
--- a/pw/pw_user.c
+++ b/pw/pw_user.c
@@ -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");
}
diff --git a/pw/pwupd.h b/pw/pwupd.h
index a67e6db..8f46e7d 100644
--- a/pw/pwupd.h
+++ b/pw/pwupd.h
@@ -84,6 +84,7 @@ struct pwconf {
char rootdir[MAXPATHLEN];
char etcpath[MAXPATHLEN];
char *newname;
+ char *config;
bool dryrun;
bool pretty;
bool v7;
diff --git a/pw/tests/Makefile b/pw/tests/Makefile
index 37d9c71..09fe93c 100644
--- a/pw/tests/Makefile
+++ b/pw/tests/Makefile
@@ -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
diff --git a/pw/tests/pw.conf b/pw/tests/pw.conf
new file mode 100644
index 0000000..4e493f6
--- /dev/null
+++ b/pw/tests/pw.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 = 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
diff --git a/pw/tests/pw_config.sh b/pw/tests/pw_config.sh
new file mode 100755
index 0000000..b5a4fad
--- /dev/null
+++ b/pw/tests/pw_config.sh
@@ -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
+}