diff options
author | bapt <bapt@FreeBSD.org> | 2014-11-12 22:27:53 +0000 |
---|---|---|
committer | bapt <bapt@FreeBSD.org> | 2014-11-12 22:27:53 +0000 |
commit | 76d74e0d6c9c33b393a180d72b3ad23ff17c9353 (patch) | |
tree | eabc82a38c7095200d26a38cbe569f6a317e08db /usr.sbin | |
parent | 67605a50d7b52c2bb0294fbb8bc5b62f7bfff1af (diff) | |
download | FreeBSD-src-76d74e0d6c9c33b393a180d72b3ad23ff17c9353.zip FreeBSD-src-76d74e0d6c9c33b393a180d72b3ad23ff17c9353.tar.gz |
Fix wrong message when using pw -V with a non existent directory
Add a regression test about it
PR: 194971
Submitted by: Freddy DISSAUX <bugzilla@dsx.bsdsx.fr>
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/pw/pw.c | 8 | ||||
-rw-r--r-- | usr.sbin/pw/tests/Makefile | 2 | ||||
-rwxr-xr-x | usr.sbin/pw/tests/pw_etcdir.sh | 18 |
3 files changed, 27 insertions, 1 deletions
diff --git a/usr.sbin/pw/pw.c b/usr.sbin/pw/pw.c index b0ac728..ff48db7 100644 --- a/usr.sbin/pw/pw.c +++ b/usr.sbin/pw/pw.c @@ -98,6 +98,7 @@ main(int argc, char *argv[]) int which = -1; char *config = NULL; struct userconf *cnf; + struct stat st; static const char *opts[W_NUM][M_NUM] = { @@ -143,6 +144,13 @@ main(int argc, char *argv[]) if (argv[1][1] == 'V') { optarg = &argv[1][2]; if (*optarg == '\0') { + if (stat(argv[2], &st) != 0) + errx(EX_OSFILE, \ + "no such directory `%s'", + argv[2]); + if (!S_ISDIR(st.st_mode)) + errx(EX_OSFILE, "`%s' not a " + "directory", argv[2]); optarg = argv[2]; ++argv; --argc; diff --git a/usr.sbin/pw/tests/Makefile b/usr.sbin/pw/tests/Makefile index fabf624..0391d1f 100644 --- a/usr.sbin/pw/tests/Makefile +++ b/usr.sbin/pw/tests/Makefile @@ -5,7 +5,7 @@ TESTSRC= ${.CURDIR}/../../../contrib/netbsd-tests/usr.sbin/useradd TESTSDIR= ${TESTSBASE}/usr.sbin/pw -ATF_TESTS_SH= pw_delete pw_modify +ATF_TESTS_SH= pw_delete pw_modify pw_etcdir TEST_METADATA.pw_delete+= required_user="root" TEST_METADATA.pw_modify+= required_user="root" diff --git a/usr.sbin/pw/tests/pw_etcdir.sh b/usr.sbin/pw/tests/pw_etcdir.sh new file mode 100755 index 0000000..edb97fe --- /dev/null +++ b/usr.sbin/pw/tests/pw_etcdir.sh @@ -0,0 +1,18 @@ +# $FreeBSD$ + +# When provide -V dir, dir must exists +atf_test_case etcdir_must_exists +etcdir_must_exists_head() { + atf_set "descr" "When provide -V dir, dir must exists" +} + +etcdir_must_exists_body() { + local fakedir="/this_directory_does_not_exists" + atf_check -e inline:"pw: no such directory \`$fakedir'\n" \ + -s exit:72 -x pw -V ${fakedir} usershow root +} + +atf_init_test_cases() { + atf_add_test_case etcdir_must_exists +} + |