Index: usr.sbin/pw/pw_conf.c =================================================================== --- usr.sbin/pw/pw_conf.c +++ usr.sbin/pw/pw_conf.c @@ -221,12 +221,14 @@ char const * boolean_str(int val) { - if (val == -1) - return "random"; - else if (val == -2) - return "none"; + if (val == P_NO) + return (boolfalse[0]); + else if (val == P_RANDOM) + return ("random"); + else if (val == P_NONE) + return ("none"); else - return val ? booltrue[0] : boolfalse[0]; + return (booltrue[0]); } char * @@ -417,9 +419,13 @@ int i, j; struct sbuf *buf; FILE *fp; + char defaultcfg[MAXPATHLEN]; - if (file == NULL) - file = _PATH_PW_CONF; + if (file == NULL) { + snprintf(defaultcfg, sizeof(defaultcfg), "%s/pw.conf", + conf.etcpath); + file = defaultcfg; + } if ((fd = open(file, O_CREAT|O_RDWR|O_TRUNC|O_EXLOCK, 0644)) == -1) return (0); @@ -428,7 +434,7 @@ close(fd); return (0); } - + buf = sbuf_new_auto(); for (i = _UC_NONE; i < _UC_FIELDS; i++) { int quote = 1; Index: usr.sbin/pw/tests/pw_useradd_test.sh =================================================================== --- usr.sbin/pw/tests/pw_useradd_test.sh +++ usr.sbin/pw/tests/pw_useradd_test.sh @@ -421,6 +421,7 @@ atf_check -s exit:0 \ ${PW} useradd foo -C ${HOME}/pw.conf } + atf_test_case user_add_defaultgroup user_add_defaultgroup_body() { @@ -435,6 +436,25 @@ ${PW} usershow foo } +atf_test_case user_add_defaultpasswd +user_add_defaultpasswd_body() +{ + populate_etc_skel + + atf_check -s exit:0 ${PW} useradd -D -w no + atf_check -o inline:"defaultpasswd = \"no\"\n" \ + grep defaultpasswd ${HOME}/pw.conf + atf_check -s exit:0 ${PW} useradd -D -w none + atf_check -o inline:"defaultpasswd = \"none\"\n" \ + grep defaultpasswd ${HOME}/pw.conf + atf_check -s exit:0 ${PW} useradd -D -w random + atf_check -o inline:"defaultpasswd = \"random\"\n" \ + grep defaultpasswd ${HOME}/pw.conf + atf_check -s exit:0 ${PW} useradd -D -w yes + atf_check -o inline:"defaultpasswd = \"yes\"\n" \ + grep defaultpasswd ${HOME}/pw.conf +} + atf_init_test_cases() { atf_add_test_case user_add atf_add_test_case user_add_noupdate @@ -472,4 +492,5 @@ atf_add_test_case user_add_w_yes atf_add_test_case user_add_with_pw_conf atf_add_test_case user_add_defaultgroup + atf_add_test_case user_add_defaultpasswd }