From owner-svn-src-head@FreeBSD.ORG Wed Nov 12 22:27:54 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id A8C19741; Wed, 12 Nov 2014 22:27:54 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 7B7181F8; Wed, 12 Nov 2014 22:27:54 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id sACMRsr0034350; Wed, 12 Nov 2014 22:27:54 GMT (envelope-from bapt@FreeBSD.org) Received: (from bapt@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id sACMRrwJ034345; Wed, 12 Nov 2014 22:27:53 GMT (envelope-from bapt@FreeBSD.org) Message-Id: <201411122227.sACMRrwJ034345@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: bapt set sender to bapt@FreeBSD.org using -f From: Baptiste Daroussin Date: Wed, 12 Nov 2014 22:27:53 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r274453 - in head/usr.sbin/pw: . tests X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 12 Nov 2014 22:27:54 -0000 Author: bapt Date: Wed Nov 12 22:27:53 2014 New Revision: 274453 URL: https://svnweb.freebsd.org/changeset/base/274453 Log: Fix wrong message when using pw -V with a non existent directory Add a regression test about it PR: 194971 Submitted by: Freddy DISSAUX Added: head/usr.sbin/pw/tests/pw_etcdir.sh (contents, props changed) Modified: head/usr.sbin/pw/pw.c head/usr.sbin/pw/tests/Makefile Modified: head/usr.sbin/pw/pw.c ============================================================================== --- head/usr.sbin/pw/pw.c Wed Nov 12 21:41:15 2014 (r274452) +++ head/usr.sbin/pw/pw.c Wed Nov 12 22:27:53 2014 (r274453) @@ -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; Modified: head/usr.sbin/pw/tests/Makefile ============================================================================== --- head/usr.sbin/pw/tests/Makefile Wed Nov 12 21:41:15 2014 (r274452) +++ head/usr.sbin/pw/tests/Makefile Wed Nov 12 22:27:53 2014 (r274453) @@ -5,7 +5,7 @@ TESTSRC= ${.CURDIR}/../../../contrib/net 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" Added: head/usr.sbin/pw/tests/pw_etcdir.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/usr.sbin/pw/tests/pw_etcdir.sh Wed Nov 12 22:27:53 2014 (r274453) @@ -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 +} +