From 9a56205fc912cc30c498cd8ab536eef96373b16f Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Tue, 9 Sep 2014 02:50:09 +0000 Subject: [PATCH] Add vendor import for pjdfstest This vendor import code was obtained from https://github.com/pjd/pjdfstest/commit/abf03c3a47745d4521b0e4aa141317553ca48f91 Approved by: rpaulo (mentor) Phabric: D743 Sponsored by: EMC / Isilon Storage Division --- LICENSE | 27 + Makefile | 26 + README | 22 + pjdfstest.c | 1493 ++++++++++++++++++++++++++++++++++++++++++ tests/chflags/00.t | 178 +++++ tests/chflags/01.t | 22 + tests/chflags/02.t | 28 + tests/chflags/03.t | 32 + tests/chflags/04.t | 19 + tests/chflags/05.t | 35 + tests/chflags/06.t | 21 + tests/chflags/07.t | 50 ++ tests/chflags/08.t | 58 ++ tests/chflags/09.t | 66 ++ tests/chflags/10.t | 54 ++ tests/chflags/11.t | 58 ++ tests/chflags/12.t | 68 ++ tests/chflags/13.t | 14 + tests/chmod/00.t | 138 ++++ tests/chmod/01.t | 20 + tests/chmod/02.t | 24 + tests/chmod/03.t | 28 + tests/chmod/04.t | 29 + tests/chmod/05.t | 42 ++ tests/chmod/06.t | 29 + tests/chmod/07.t | 62 ++ tests/chmod/08.t | 98 +++ tests/chmod/09.t | 37 ++ tests/chmod/10.t | 20 + tests/chmod/11.t | 118 ++++ tests/chmod/12.t | 38 ++ tests/chmod/foo | 0 tests/chown/00.t | 458 +++++++++++++ tests/chown/01.t | 21 + tests/chown/02.t | 24 + tests/chown/03.t | 28 + tests/chown/04.t | 23 + tests/chown/05.t | 35 + tests/chown/06.t | 23 + tests/chown/07.t | 53 ++ tests/chown/08.t | 84 +++ tests/chown/09.t | 32 + tests/chown/10.t | 14 + tests/conf | 36 + tests/ftruncate/00.t | 58 ++ tests/ftruncate/01.t | 18 + tests/ftruncate/02.t | 18 + tests/ftruncate/03.t | 22 + tests/ftruncate/04.t | 17 + tests/ftruncate/05.t | 32 + tests/ftruncate/06.t | 24 + tests/ftruncate/07.t | 19 + tests/ftruncate/08.t | 78 +++ tests/ftruncate/09.t | 15 + tests/ftruncate/10.t | 32 + tests/ftruncate/11.t | 18 + tests/ftruncate/12.t | 27 + tests/ftruncate/13.t | 16 + tests/ftruncate/14.t | 12 + tests/granular/00.t | 112 ++++ tests/granular/01.t | 37 ++ tests/granular/02.t | 144 ++++ tests/granular/03.t | 134 ++++ tests/granular/04.t | 80 +++ tests/granular/05.t | 149 +++++ tests/link/00.t | 93 +++ tests/link/01.t | 24 + tests/link/02.t | 25 + tests/link/03.t | 31 + tests/link/04.t | 20 + tests/link/05.t | 36 + tests/link/06.t | 43 ++ tests/link/07.t | 41 ++ tests/link/08.t | 24 + tests/link/09.t | 18 + tests/link/10.t | 26 + tests/link/11.t | 41 ++ tests/link/12.t | 95 +++ tests/link/13.t | 86 +++ tests/link/14.t | 29 + tests/link/15.t | 33 + tests/link/16.t | 34 + tests/link/17.t | 20 + tests/misc.sh | 221 +++++++ tests/mkdir/00.t | 73 +++ tests/mkdir/01.t | 20 + tests/mkdir/02.t | 16 + tests/mkdir/03.t | 20 + tests/mkdir/04.t | 16 + tests/mkdir/05.t | 29 + tests/mkdir/06.t | 29 + tests/mkdir/07.t | 19 + tests/mkdir/08.t | 66 ++ tests/mkdir/09.t | 29 + tests/mkdir/10.t | 21 + tests/mkdir/11.t | 31 + tests/mkdir/12.t | 12 + tests/mkfifo/00.t | 73 +++ tests/mkfifo/01.t | 20 + tests/mkfifo/02.t | 17 + tests/mkfifo/03.t | 21 + tests/mkfifo/04.t | 16 + tests/mkfifo/05.t | 29 + tests/mkfifo/06.t | 29 + tests/mkfifo/07.t | 19 + tests/mkfifo/08.t | 29 + tests/mkfifo/09.t | 21 + tests/mkfifo/10.t | 66 ++ tests/mkfifo/11.t | 31 + tests/mkfifo/12.t | 12 + tests/mknod/00.t | 73 +++ tests/mknod/01.t | 22 + tests/mknod/02.t | 27 + tests/mknod/03.t | 31 + tests/mknod/04.t | 16 + tests/mknod/05.t | 29 + tests/mknod/06.t | 29 + tests/mknod/07.t | 19 + tests/mknod/08.t | 23 + tests/mknod/09.t | 64 ++ tests/mknod/10.t | 12 + tests/mknod/11.t | 79 +++ tests/open/00.t | 99 +++ tests/open/01.t | 21 + tests/open/02.t | 17 + tests/open/03.t | 21 + tests/open/04.t | 17 + tests/open/05.t | 29 + tests/open/06.t | 187 ++++++ tests/open/07.t | 45 ++ tests/open/08.t | 19 + tests/open/09.t | 66 ++ tests/open/10.t | 58 ++ tests/open/11.t | 56 ++ tests/open/12.t | 19 + tests/open/13.t | 24 + tests/open/14.t | 32 + tests/open/15.t | 27 + tests/open/16.t | 19 + tests/open/17.t | 15 + tests/open/18.t | 20 + tests/open/19.t | 31 + tests/open/20.t | 20 + tests/open/21.t | 12 + tests/open/22.t | 21 + tests/open/23.t | 17 + tests/open/24.t | 17 + tests/rename/00.t | 91 +++ tests/rename/01.t | 23 + tests/rename/02.t | 24 + tests/rename/03.t | 20 + tests/rename/04.t | 43 ++ tests/rename/05.t | 41 ++ tests/rename/06.t | 61 ++ tests/rename/07.t | 66 ++ tests/rename/08.t | 63 ++ tests/rename/09.t | 191 ++++++ tests/rename/10.t | 156 +++++ tests/rename/11.t | 24 + tests/rename/12.t | 24 + tests/rename/13.t | 24 + tests/rename/14.t | 24 + tests/rename/15.t | 34 + tests/rename/16.t | 32 + tests/rename/17.t | 20 + tests/rename/18.t | 22 + tests/rename/19.t | 22 + tests/rename/20.t | 29 + tests/rename/21.t | 47 ++ tests/rmdir/00.t | 28 + tests/rmdir/01.t | 30 + tests/rmdir/02.t | 17 + tests/rmdir/03.t | 22 + tests/rmdir/04.t | 17 + tests/rmdir/05.t | 19 + tests/rmdir/06.t | 24 + tests/rmdir/07.t | 27 + tests/rmdir/08.t | 27 + tests/rmdir/09.t | 65 ++ tests/rmdir/10.t | 67 ++ tests/rmdir/11.t | 57 ++ tests/rmdir/12.t | 20 + tests/rmdir/13.t | 22 + tests/rmdir/14.t | 27 + tests/rmdir/15.t | 12 + tests/symlink/00.t | 32 + tests/symlink/01.t | 18 + tests/symlink/02.t | 22 + tests/symlink/03.t | 22 + tests/symlink/04.t | 16 + tests/symlink/05.t | 34 + tests/symlink/06.t | 34 + tests/symlink/07.t | 19 + tests/symlink/08.t | 21 + tests/symlink/09.t | 66 ++ tests/symlink/10.t | 32 + tests/symlink/11.t | 31 + tests/symlink/12.t | 18 + tests/truncate/00.t | 51 ++ tests/truncate/01.t | 18 + tests/truncate/02.t | 18 + tests/truncate/03.t | 22 + tests/truncate/04.t | 17 + tests/truncate/05.t | 32 + tests/truncate/06.t | 24 + tests/truncate/07.t | 19 + tests/truncate/08.t | 78 +++ tests/truncate/09.t | 15 + tests/truncate/10.t | 32 + tests/truncate/11.t | 18 + tests/truncate/12.t | 27 + tests/truncate/13.t | 16 + tests/truncate/14.t | 12 + tests/unlink/00.t | 212 ++++++ tests/unlink/01.t | 18 + tests/unlink/02.t | 17 + tests/unlink/03.t | 21 + tests/unlink/04.t | 17 + tests/unlink/05.t | 27 + tests/unlink/06.t | 27 + tests/unlink/07.t | 19 + tests/unlink/08.t | 16 + tests/unlink/09.t | 65 ++ tests/unlink/10.t | 67 ++ tests/unlink/11.t | 63 ++ tests/unlink/12.t | 27 + tests/unlink/13.t | 12 + 227 files changed, 10818 insertions(+) create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 README create mode 100644 pjdfstest.c create mode 100644 tests/chflags/00.t create mode 100644 tests/chflags/01.t create mode 100644 tests/chflags/02.t create mode 100644 tests/chflags/03.t create mode 100644 tests/chflags/04.t create mode 100644 tests/chflags/05.t create mode 100644 tests/chflags/06.t create mode 100644 tests/chflags/07.t create mode 100644 tests/chflags/08.t create mode 100644 tests/chflags/09.t create mode 100644 tests/chflags/10.t create mode 100644 tests/chflags/11.t create mode 100644 tests/chflags/12.t create mode 100644 tests/chflags/13.t create mode 100644 tests/chmod/00.t create mode 100644 tests/chmod/01.t create mode 100644 tests/chmod/02.t create mode 100644 tests/chmod/03.t create mode 100644 tests/chmod/04.t create mode 100644 tests/chmod/05.t create mode 100644 tests/chmod/06.t create mode 100644 tests/chmod/07.t create mode 100644 tests/chmod/08.t create mode 100644 tests/chmod/09.t create mode 100644 tests/chmod/10.t create mode 100644 tests/chmod/11.t create mode 100644 tests/chmod/12.t create mode 100755 tests/chmod/foo create mode 100644 tests/chown/00.t create mode 100644 tests/chown/01.t create mode 100644 tests/chown/02.t create mode 100644 tests/chown/03.t create mode 100644 tests/chown/04.t create mode 100644 tests/chown/05.t create mode 100644 tests/chown/06.t create mode 100644 tests/chown/07.t create mode 100644 tests/chown/08.t create mode 100644 tests/chown/09.t create mode 100644 tests/chown/10.t create mode 100644 tests/conf create mode 100644 tests/ftruncate/00.t create mode 100644 tests/ftruncate/01.t create mode 100644 tests/ftruncate/02.t create mode 100644 tests/ftruncate/03.t create mode 100644 tests/ftruncate/04.t create mode 100644 tests/ftruncate/05.t create mode 100644 tests/ftruncate/06.t create mode 100644 tests/ftruncate/07.t create mode 100644 tests/ftruncate/08.t create mode 100644 tests/ftruncate/09.t create mode 100644 tests/ftruncate/10.t create mode 100644 tests/ftruncate/11.t create mode 100644 tests/ftruncate/12.t create mode 100644 tests/ftruncate/13.t create mode 100644 tests/ftruncate/14.t create mode 100644 tests/granular/00.t create mode 100644 tests/granular/01.t create mode 100644 tests/granular/02.t create mode 100644 tests/granular/03.t create mode 100644 tests/granular/04.t create mode 100644 tests/granular/05.t create mode 100644 tests/link/00.t create mode 100644 tests/link/01.t create mode 100644 tests/link/02.t create mode 100644 tests/link/03.t create mode 100644 tests/link/04.t create mode 100644 tests/link/05.t create mode 100644 tests/link/06.t create mode 100644 tests/link/07.t create mode 100644 tests/link/08.t create mode 100644 tests/link/09.t create mode 100644 tests/link/10.t create mode 100644 tests/link/11.t create mode 100644 tests/link/12.t create mode 100644 tests/link/13.t create mode 100644 tests/link/14.t create mode 100644 tests/link/15.t create mode 100644 tests/link/16.t create mode 100644 tests/link/17.t create mode 100755 tests/misc.sh create mode 100644 tests/mkdir/00.t create mode 100644 tests/mkdir/01.t create mode 100644 tests/mkdir/02.t create mode 100644 tests/mkdir/03.t create mode 100644 tests/mkdir/04.t create mode 100644 tests/mkdir/05.t create mode 100644 tests/mkdir/06.t create mode 100644 tests/mkdir/07.t create mode 100644 tests/mkdir/08.t create mode 100644 tests/mkdir/09.t create mode 100644 tests/mkdir/10.t create mode 100644 tests/mkdir/11.t create mode 100644 tests/mkdir/12.t create mode 100644 tests/mkfifo/00.t create mode 100644 tests/mkfifo/01.t create mode 100644 tests/mkfifo/02.t create mode 100644 tests/mkfifo/03.t create mode 100644 tests/mkfifo/04.t create mode 100644 tests/mkfifo/05.t create mode 100644 tests/mkfifo/06.t create mode 100644 tests/mkfifo/07.t create mode 100644 tests/mkfifo/08.t create mode 100644 tests/mkfifo/09.t create mode 100644 tests/mkfifo/10.t create mode 100644 tests/mkfifo/11.t create mode 100644 tests/mkfifo/12.t create mode 100644 tests/mknod/00.t create mode 100644 tests/mknod/01.t create mode 100644 tests/mknod/02.t create mode 100644 tests/mknod/03.t create mode 100644 tests/mknod/04.t create mode 100644 tests/mknod/05.t create mode 100644 tests/mknod/06.t create mode 100644 tests/mknod/07.t create mode 100644 tests/mknod/08.t create mode 100644 tests/mknod/09.t create mode 100644 tests/mknod/10.t create mode 100644 tests/mknod/11.t create mode 100644 tests/open/00.t create mode 100644 tests/open/01.t create mode 100644 tests/open/02.t create mode 100644 tests/open/03.t create mode 100644 tests/open/04.t create mode 100644 tests/open/05.t create mode 100644 tests/open/06.t create mode 100644 tests/open/07.t create mode 100644 tests/open/08.t create mode 100644 tests/open/09.t create mode 100644 tests/open/10.t create mode 100644 tests/open/11.t create mode 100644 tests/open/12.t create mode 100644 tests/open/13.t create mode 100644 tests/open/14.t create mode 100644 tests/open/15.t create mode 100644 tests/open/16.t create mode 100644 tests/open/17.t create mode 100644 tests/open/18.t create mode 100644 tests/open/19.t create mode 100644 tests/open/20.t create mode 100644 tests/open/21.t create mode 100644 tests/open/22.t create mode 100644 tests/open/23.t create mode 100644 tests/open/24.t create mode 100644 tests/rename/00.t create mode 100644 tests/rename/01.t create mode 100644 tests/rename/02.t create mode 100644 tests/rename/03.t create mode 100644 tests/rename/04.t create mode 100644 tests/rename/05.t create mode 100644 tests/rename/06.t create mode 100644 tests/rename/07.t create mode 100644 tests/rename/08.t create mode 100644 tests/rename/09.t create mode 100644 tests/rename/10.t create mode 100644 tests/rename/11.t create mode 100644 tests/rename/12.t create mode 100644 tests/rename/13.t create mode 100644 tests/rename/14.t create mode 100644 tests/rename/15.t create mode 100644 tests/rename/16.t create mode 100644 tests/rename/17.t create mode 100644 tests/rename/18.t create mode 100644 tests/rename/19.t create mode 100644 tests/rename/20.t create mode 100644 tests/rename/21.t create mode 100644 tests/rmdir/00.t create mode 100644 tests/rmdir/01.t create mode 100644 tests/rmdir/02.t create mode 100644 tests/rmdir/03.t create mode 100644 tests/rmdir/04.t create mode 100644 tests/rmdir/05.t create mode 100644 tests/rmdir/06.t create mode 100644 tests/rmdir/07.t create mode 100644 tests/rmdir/08.t create mode 100644 tests/rmdir/09.t create mode 100644 tests/rmdir/10.t create mode 100644 tests/rmdir/11.t create mode 100644 tests/rmdir/12.t create mode 100644 tests/rmdir/13.t create mode 100644 tests/rmdir/14.t create mode 100644 tests/rmdir/15.t create mode 100644 tests/symlink/00.t create mode 100644 tests/symlink/01.t create mode 100644 tests/symlink/02.t create mode 100644 tests/symlink/03.t create mode 100644 tests/symlink/04.t create mode 100644 tests/symlink/05.t create mode 100644 tests/symlink/06.t create mode 100644 tests/symlink/07.t create mode 100644 tests/symlink/08.t create mode 100644 tests/symlink/09.t create mode 100644 tests/symlink/10.t create mode 100644 tests/symlink/11.t create mode 100644 tests/symlink/12.t create mode 100644 tests/truncate/00.t create mode 100644 tests/truncate/01.t create mode 100644 tests/truncate/02.t create mode 100644 tests/truncate/03.t create mode 100644 tests/truncate/04.t create mode 100644 tests/truncate/05.t create mode 100644 tests/truncate/06.t create mode 100644 tests/truncate/07.t create mode 100644 tests/truncate/08.t create mode 100644 tests/truncate/09.t create mode 100644 tests/truncate/10.t create mode 100644 tests/truncate/11.t create mode 100644 tests/truncate/12.t create mode 100644 tests/truncate/13.t create mode 100644 tests/truncate/14.t create mode 100644 tests/unlink/00.t create mode 100644 tests/unlink/01.t create mode 100644 tests/unlink/02.t create mode 100644 tests/unlink/03.t create mode 100644 tests/unlink/04.t create mode 100644 tests/unlink/05.t create mode 100644 tests/unlink/06.t create mode 100644 tests/unlink/07.t create mode 100644 tests/unlink/08.t create mode 100644 tests/unlink/09.t create mode 100644 tests/unlink/10.t create mode 100644 tests/unlink/11.t create mode 100644 tests/unlink/12.t create mode 100644 tests/unlink/13.t diff --git a/LICENSE b/LICENSE new file mode 100644 index 000000000000..f91e71b37bf4 --- /dev/null +++ b/LICENSE @@ -0,0 +1,27 @@ +$FreeBSD: head/tools/regression/pjdfstest/LICENSE 211354 2010-08-15 21:29:03Z pjd $ + +License for all regression tests available with pjdfstest: + +Copyright (c) 2006-2012 Pawel Jakub Dawidek +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +SUCH DAMAGE. diff --git a/Makefile b/Makefile new file mode 100644 index 000000000000..a3e35f89b382 --- /dev/null +++ b/Makefile @@ -0,0 +1,26 @@ +# $FreeBSD$ + +PROG= pjdfstest + +${PROG}: ${PROG}.c + @OSTYPE=`uname`; \ + CFLAGS=-D__OS_$${OSTYPE}__; \ + if [ $$OSTYPE = "FreeBSD" ]; then \ + CFLAGS="$$CFLAGS -DHAS_LCHMOD -DHAS_CHFLAGS -DHAS_FCHFLAGS -DHAS_CHFLAGSAT -DHAS_LCHFLAGS -DHAS_FREEBSD_ACL -DHAS_BINDAT -DHAS_CONNECTAT -DHAS_LPATHCONF"; \ + elif [ $$OSTYPE = "SunOS" ]; then \ + CFLAGS="$$CFLAGS -DHAS_TRUNCATE64 -DHAS_STAT64"; \ + CFLAGS="$$CFLAGS -lsocket"; \ + elif [ $$OSTYPE = "Darwin" ]; then \ + CFLAGS="$$CFLAGS -DHAS_LCHMOD -DHAS_CHFLAGS -DHAS_LCHFLAGS"; \ + elif [ $$OSTYPE == "Linux" ]; then \ + CFLAGS="$$CFLAGS -D_GNU_SOURCE"; \ + else \ + echo "Unsupported operating system: ${OSTYPE}."; \ + exit 1; \ + fi; \ + cmd="gcc -Wall $$CFLAGS ${PROG}.c -o ${PROG}"; \ + echo $$cmd; \ + $$cmd + +clean: + rm -f ${PROG} diff --git a/README b/README new file mode 100644 index 000000000000..dcc5a64ba3f4 --- /dev/null +++ b/README @@ -0,0 +1,22 @@ +$FreeBSD: head/tools/regression/pjdfstest/README 211354 2010-08-15 21:29:03Z pjd $ + +Few notes on how to use pjdfstest in short steps: + + # cd pjdfstest + # vi tests/conf + Change 'fs' to file system type you want to test (UFS or ZFS). + # vi Makefile + You need to manually tweak few things by editing CFLAGS lines + at the top of the file. + # make + It will compile pjdfstest utility which is used by regression tests. + # cd /path/to/file/system/you/want/to/test/ + # prove -r /path/to/pjdfstest/tests + +That's all. Enjoy. + +Currently supported operating systems: FreeBSD, Solaris. +Currently supported file system types: UFS, ZFS. + +-- +Pawel Jakub Dawidek diff --git a/pjdfstest.c b/pjdfstest.c new file mode 100644 index 000000000000..046df490e4f7 --- /dev/null +++ b/pjdfstest.c @@ -0,0 +1,1493 @@ +/*- + * Copyright (c) 2006-2010 Pawel Jakub Dawidek + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include +#include +#include +#include +#include +#ifndef makedev +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef HAS_TRUNCATE64 +#define truncate64 truncate +#define ftruncate64 ftruncate +#endif +#ifndef HAS_STAT64 +#define stat64 stat +#define fstat64 fstat +#define lstat64 lstat +#endif +#ifdef HAS_FREEBSD_ACL +#include +#endif + +#ifndef ALLPERMS +#define ALLPERMS (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO) +#endif + +enum action { + ACTION_OPEN, + ACTION_OPENAT, + ACTION_CREATE, + ACTION_UNLINK, + ACTION_UNLINKAT, + ACTION_MKDIR, + ACTION_MKDIRAT, + ACTION_RMDIR, + ACTION_LINK, + ACTION_LINKAT, + ACTION_SYMLINK, + ACTION_SYMLINKAT, + ACTION_RENAME, + ACTION_RENAMEAT, + ACTION_MKFIFO, + ACTION_MKFIFOAT, + ACTION_MKNOD, + ACTION_MKNODAT, + ACTION_BIND, +#ifdef HAS_BINDAT + ACTION_BINDAT, +#endif + ACTION_CONNECT, +#ifdef HAS_CONNECTAT + ACTION_CONNECTAT, +#endif + ACTION_CHMOD, + ACTION_FCHMOD, +#ifdef HAS_LCHMOD + ACTION_LCHMOD, +#endif + ACTION_FCHMODAT, + ACTION_CHOWN, + ACTION_FCHOWN, + ACTION_LCHOWN, + ACTION_FCHOWNAT, +#ifdef HAS_CHFLAGS + ACTION_CHFLAGS, +#endif +#ifdef HAS_FCHFLAGS + ACTION_FCHFLAGS, +#endif +#ifdef HAS_CHFLAGSAT + ACTION_CHFLAGSAT, +#endif +#ifdef HAS_LCHFLAGS + ACTION_LCHFLAGS, +#endif + ACTION_TRUNCATE, + ACTION_FTRUNCATE, + ACTION_STAT, + ACTION_FSTAT, + ACTION_LSTAT, + ACTION_FSTATAT, + ACTION_PATHCONF, + ACTION_FPATHCONF, +#ifdef HAS_LPATHCONF + ACTION_LPATHCONF, +#endif +#ifdef HAS_FREEBSD_ACL + ACTION_PREPENDACL, + ACTION_READACL, +#endif + ACTION_WRITE, +}; + +#define TYPE_NONE 0x0000 +#define TYPE_STRING 0x0001 +#define TYPE_NUMBER 0x0002 +#define TYPE_DESCRIPTOR 0x0003 +#define TYPE_MASK 0x000f + +#define TYPE_OPTIONAL 0x0100 + +#define MAX_ARGS 8 + +struct syscall_desc { + const char *sd_name; + enum action sd_action; + int sd_args[MAX_ARGS]; +}; + +static struct syscall_desc syscalls[] = { + { "open", ACTION_OPEN, { TYPE_STRING, TYPE_STRING, TYPE_NUMBER | TYPE_OPTIONAL, TYPE_NONE } }, + { "openat", ACTION_OPENAT, { TYPE_DESCRIPTOR, TYPE_STRING, TYPE_STRING, TYPE_NUMBER | TYPE_OPTIONAL, TYPE_NONE } }, + { "create", ACTION_CREATE, { TYPE_STRING, TYPE_NUMBER, TYPE_NONE } }, + { "unlink", ACTION_UNLINK, { TYPE_STRING, TYPE_NONE } }, + { "unlinkat", ACTION_UNLINKAT, { TYPE_DESCRIPTOR, TYPE_STRING, TYPE_STRING, TYPE_NONE } }, + { "mkdir", ACTION_MKDIR, { TYPE_STRING, TYPE_NUMBER, TYPE_NONE } }, + { "mkdirat", ACTION_MKDIRAT, { TYPE_DESCRIPTOR, TYPE_STRING, TYPE_NUMBER, TYPE_NONE } }, + { "rmdir", ACTION_RMDIR, { TYPE_STRING, TYPE_NONE } }, + { "link", ACTION_LINK, { TYPE_STRING, TYPE_STRING, TYPE_NONE } }, + { "linkat", ACTION_LINKAT, { TYPE_DESCRIPTOR, TYPE_STRING, TYPE_DESCRIPTOR, TYPE_STRING, TYPE_STRING, TYPE_NONE } }, + { "symlink", ACTION_SYMLINK, { TYPE_STRING, TYPE_STRING, TYPE_NONE } }, + { "symlinkat", ACTION_SYMLINKAT, { TYPE_STRING, TYPE_DESCRIPTOR, TYPE_STRING, TYPE_NONE } }, + { "rename", ACTION_RENAME, { TYPE_STRING, TYPE_STRING, TYPE_NONE } }, + { "renameat", ACTION_RENAMEAT, { TYPE_DESCRIPTOR, TYPE_STRING, TYPE_DESCRIPTOR, TYPE_STRING, TYPE_NONE } }, + { "mkfifo", ACTION_MKFIFO, { TYPE_STRING, TYPE_NUMBER, TYPE_NONE } }, + { "mkfifoat", ACTION_MKFIFOAT, { TYPE_DESCRIPTOR, TYPE_STRING, TYPE_NUMBER, TYPE_NONE } }, + { "mknod", ACTION_MKNOD, { TYPE_STRING, TYPE_STRING, TYPE_NUMBER, TYPE_NUMBER, TYPE_NUMBER, TYPE_NONE} }, + { "mknodat", ACTION_MKNODAT, { TYPE_DESCRIPTOR, TYPE_STRING, TYPE_STRING, TYPE_NUMBER, TYPE_NUMBER, TYPE_NUMBER, TYPE_NONE} }, + { "bind", ACTION_BIND, { TYPE_STRING, TYPE_NONE } }, +#ifdef HAS_BINDAT + { "bindat", ACTION_BINDAT, { TYPE_DESCRIPTOR, TYPE_STRING, TYPE_NONE } }, +#endif + { "connect", ACTION_CONNECT, { TYPE_STRING, TYPE_NONE } }, +#ifdef HAS_CONNECTAT + { "connectat", ACTION_CONNECTAT, { TYPE_DESCRIPTOR, TYPE_STRING, TYPE_NONE } }, +#endif + { "chmod", ACTION_CHMOD, { TYPE_STRING, TYPE_NUMBER, TYPE_NONE } }, + { "fchmod", ACTION_FCHMOD, { TYPE_DESCRIPTOR, TYPE_NUMBER, TYPE_NONE } }, +#ifdef HAS_LCHMOD + { "lchmod", ACTION_LCHMOD, { TYPE_STRING, TYPE_NUMBER, TYPE_NONE } }, +#endif + { "fchmodat", ACTION_FCHMODAT, { TYPE_DESCRIPTOR, TYPE_STRING, TYPE_NUMBER, TYPE_STRING, TYPE_NONE } }, + { "chown", ACTION_CHOWN, { TYPE_STRING, TYPE_NUMBER, TYPE_NUMBER, TYPE_NONE } }, + { "fchown", ACTION_FCHOWN, { TYPE_DESCRIPTOR, TYPE_NUMBER, TYPE_NUMBER, TYPE_NONE } }, + { "lchown", ACTION_LCHOWN, { TYPE_STRING, TYPE_NUMBER, TYPE_NUMBER, TYPE_NONE } }, + { "fchownat", ACTION_FCHOWNAT, { TYPE_DESCRIPTOR, TYPE_STRING, TYPE_NUMBER, TYPE_NUMBER, TYPE_STRING, TYPE_NONE } }, +#ifdef HAS_CHFLAGS + { "chflags", ACTION_CHFLAGS, { TYPE_STRING, TYPE_STRING, TYPE_NONE } }, +#endif +#ifdef HAS_FCHFLAGS + { "fchflags", ACTION_FCHFLAGS, { TYPE_DESCRIPTOR, TYPE_STRING, TYPE_NONE } }, +#endif +#ifdef HAS_CHFLAGSAT + { "chflagsat", ACTION_CHFLAGSAT, { TYPE_DESCRIPTOR, TYPE_STRING, TYPE_STRING, TYPE_STRING, TYPE_NONE } }, +#endif +#ifdef HAS_LCHFLAGS + { "lchflags", ACTION_LCHFLAGS, { TYPE_STRING, TYPE_STRING, TYPE_NONE } }, +#endif + { "truncate", ACTION_TRUNCATE, { TYPE_STRING, TYPE_NUMBER, TYPE_NONE } }, + { "ftruncate", ACTION_FTRUNCATE, { TYPE_DESCRIPTOR, TYPE_NUMBER, TYPE_NONE } }, + { "stat", ACTION_STAT, { TYPE_STRING, TYPE_STRING, TYPE_NONE } }, + { "fstat", ACTION_FSTAT, { TYPE_DESCRIPTOR, TYPE_STRING, TYPE_NONE } }, + { "lstat", ACTION_LSTAT, { TYPE_STRING, TYPE_STRING, TYPE_NONE } }, + { "fstatat", ACTION_FSTATAT, { TYPE_DESCRIPTOR, TYPE_STRING, TYPE_STRING, TYPE_STRING, TYPE_NONE } }, + { "pathconf", ACTION_PATHCONF, { TYPE_STRING, TYPE_STRING, TYPE_NONE } }, + { "fpathconf", ACTION_FPATHCONF, { TYPE_DESCRIPTOR, TYPE_STRING, TYPE_NONE } }, +#ifdef HAS_LPATHCONF + { "lpathconf", ACTION_LPATHCONF, { TYPE_STRING, TYPE_STRING, TYPE_NONE } }, +#endif +#ifdef HAS_FREEBSD_ACL + { "prependacl", ACTION_PREPENDACL, { TYPE_STRING, TYPE_STRING, TYPE_NONE } }, + { "readacl", ACTION_READACL, { TYPE_STRING, TYPE_NONE } }, +#endif + { "write", ACTION_WRITE, { TYPE_DESCRIPTOR, TYPE_STRING, TYPE_NONE } }, + { NULL, -1, { TYPE_NONE } } +}; + +struct flag { + long long f_flag; + const char *f_str; +}; + +static struct flag open_flags[] = { +#ifdef O_RDONLY + { O_RDONLY, "O_RDONLY" }, +#endif +#ifdef O_WRONLY + { O_WRONLY, "O_WRONLY" }, +#endif +#ifdef O_RDWR + { O_RDWR, "O_RDWR" }, +#endif +#ifdef O_NONBLOCK + { O_NONBLOCK, "O_NONBLOCK" }, +#endif +#ifdef O_APPEND + { O_APPEND, "O_APPEND" }, +#endif +#ifdef O_CREAT + { O_CREAT, "O_CREAT" }, +#endif +#ifdef O_TRUNC + { O_TRUNC, "O_TRUNC" }, +#endif +#ifdef O_EXCL + { O_EXCL, "O_EXCL" }, +#endif +#ifdef O_SHLOCK + { O_SHLOCK, "O_SHLOCK" }, +#endif +#ifdef O_EXLOCK + { O_EXLOCK, "O_EXLOCK" }, +#endif +#ifdef O_DIRECT + { O_DIRECT, "O_DIRECT" }, +#endif +#ifdef O_FSYNC + { O_FSYNC, "O_FSYNC" }, +#endif +#ifdef O_SYNC + { O_SYNC, "O_SYNC" }, +#endif +#ifdef O_NOFOLLOW + { O_NOFOLLOW, "O_NOFOLLOW" }, +#endif +#ifdef O_NOCTTY + { O_NOCTTY, "O_NOCTTY" }, +#endif +#ifdef O_DIRECTORY + { O_DIRECTORY, "O_DIRECTORY" }, +#endif + { 0, NULL } +}; + +#ifdef HAS_CHFLAGS +static struct flag chflags_flags[] = { +#ifdef UF_NODUMP + { UF_NODUMP, "UF_NODUMP" }, +#endif +#ifdef UF_IMMUTABLE + { UF_IMMUTABLE, "UF_IMMUTABLE" }, +#endif +#ifdef UF_APPEND + { UF_APPEND, "UF_APPEND" }, +#endif +#ifdef UF_NOUNLINK + { UF_NOUNLINK, "UF_NOUNLINK" }, +#endif +#ifdef UF_OPAQUE + { UF_OPAQUE, "UF_OPAQUE" }, +#endif +#ifdef SF_ARCHIVED + { SF_ARCHIVED, "SF_ARCHIVED" }, +#endif +#ifdef SF_IMMUTABLE + { SF_IMMUTABLE, "SF_IMMUTABLE" }, +#endif +#ifdef SF_APPEND + { SF_APPEND, "SF_APPEND" }, +#endif +#ifdef SF_NOUNLINK + { SF_NOUNLINK, "SF_NOUNLINK" }, +#endif +#ifdef SF_SNAPSHOT + { SF_SNAPSHOT, "SF_SNAPSHOT" }, +#endif + { 0, NULL } +}; +#endif + +static struct flag unlinkat_flags[] = { + { AT_REMOVEDIR, "AT_REMOVEDIR" }, + { 0, NULL } +}; + +static struct flag linkat_flags[] = { + { AT_SYMLINK_FOLLOW, "AT_SYMLINK_FOLLOW" }, + { 0, NULL } +}; + +static struct flag chflagsat_flags[] = { + { AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" }, + { 0, NULL } +}; + +static struct flag fchmodat_flags[] = { + { AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" }, + { 0, NULL } +}; + +static struct flag fchownat_flags[] = { + { AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" }, + { 0, NULL } +}; + +static struct flag fstatat_flags[] = { + { AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" }, + { 0, NULL } +}; + +struct name { + int n_name; + const char *n_str; +}; + +static struct name pathconf_names[] = { +#ifdef _PC_LINK_MAX + { _PC_LINK_MAX, "_PC_LINK_MAX" }, +#endif +#ifdef _PC_NAME_MAX + { _PC_NAME_MAX, "_PC_NAME_MAX" }, +#endif +#ifdef _PC_PATH_MAX + { _PC_PATH_MAX, "_PC_PATH_MAX" }, +#endif +#ifdef _PC_SYMLINK_MAX + { _PC_SYMLINK_MAX, "_PC_SYMLINK_MAX" }, +#endif + { 0, NULL } +}; + +static const char *err2str(int error); + +static int *descriptors; +static int ndescriptors; + +static void +usage(void) +{ + + fprintf(stderr, "usage: pjdfstest [-U umask] [-u uid] [-g gid1[,gid2[...]]] syscall args ...\n"); + exit(1); +} + +static long long +str2flags(struct flag *tflags, char *sflags) +{ + long long flags = 0; + unsigned int i; + char *f; + + /* 'none' or '0' means no flags */ + if (strcmp(sflags, "none") == 0 || strcmp(sflags, "0") == 0) + return (0); + for (f = strtok(sflags, ",|"); f != NULL; f = strtok(NULL, ",|")) { + for (i = 0; tflags[i].f_str != NULL; i++) { + if (strcmp(tflags[i].f_str, f) == 0) + break; + } + if (tflags[i].f_str == NULL) { + fprintf(stderr, "unknown flag '%s'\n", f); + exit(1); + } + flags |= tflags[i].f_flag; + } + return (flags); +} + +#ifdef HAS_CHFLAGS +static char * +flags2str(struct flag *tflags, long long flags) +{ + static char sflags[1024]; + unsigned int i; + + sflags[0] = '\0'; + for (i = 0; tflags[i].f_str != NULL; i++) { + if (flags & tflags[i].f_flag) { + if (sflags[0] != '\0') + strlcat(sflags, ",", sizeof(sflags)); + strlcat(sflags, tflags[i].f_str, sizeof(sflags)); + } + } + if (sflags[0] == '\0') + strlcpy(sflags, "none", sizeof(sflags)); + return (sflags); +} +#endif + +static int +str2name(struct name *names, char *name) +{ + unsigned int i; + + for (i = 0; names[i].n_str != NULL; i++) { + if (strcmp(names[i].n_str, name) == 0) + return (names[i].n_name); + } + return (-1); +} + +static struct syscall_desc * +find_syscall(const char *name) +{ + int i; + + for (i = 0; syscalls[i].sd_name != NULL; i++) { + if (strcmp(syscalls[i].sd_name, name) == 0) + return (&syscalls[i]); + } + return (NULL); +} + +static void +show_stat(struct stat64 *sp, const char *what) +{ + + if (strcmp(what, "mode") == 0) + printf("0%o", (unsigned int)(sp->st_mode & ALLPERMS)); + else if (strcmp(what, "inode") == 0) + printf("%lld", (long long)sp->st_ino); + else if (strcmp(what, "nlink") == 0) + printf("%lld", (long long)sp->st_nlink); + else if (strcmp(what, "uid") == 0) + printf("%d", (int)sp->st_uid); + else if (strcmp(what, "gid") == 0) + printf("%d", (int)sp->st_gid); + else if (strcmp(what, "size") == 0) + printf("%lld", (long long)sp->st_size); + else if (strcmp(what, "blocks") == 0) + printf("%lld", (long long)sp->st_blocks); + else if (strcmp(what, "atime") == 0) + printf("%lld", (long long)sp->st_atime); + else if (strcmp(what, "mtime") == 0) + printf("%lld", (long long)sp->st_mtime); + else if (strcmp(what, "ctime") == 0) + printf("%lld", (long long)sp->st_ctime); +#ifdef HAS_CHFLAGS + else if (strcmp(what, "flags") == 0) + printf("%s", flags2str(chflags_flags, (long long)sp->st_flags)); +#endif + else if (strcmp(what, "major") == 0) + printf("%u", (unsigned int)major(sp->st_rdev)); + else if (strcmp(what, "minor") == 0) + printf("%u", (unsigned int)minor(sp->st_rdev)); + else if (strcmp(what, "type") == 0) { + switch (sp->st_mode & S_IFMT) { + case S_IFIFO: + printf("fifo"); + break; + case S_IFCHR: + printf("char"); + break; + case S_IFDIR: + printf("dir"); + break; + case S_IFBLK: + printf("block"); + break; + case S_IFREG: + printf("regular"); + break; + case S_IFLNK: + printf("symlink"); + break; + case S_IFSOCK: + printf("socket"); + break; + default: + printf("unknown"); + break; + } + } else { + printf("unknown"); + } +} + +static void +show_stats(struct stat64 *sp, char *what) +{ + const char *s = ""; + char *w; + + for (w = strtok(what, ","); w != NULL; w = strtok(NULL, ",")) { + printf("%s", s); + show_stat(sp, w); + s = ","; + } + printf("\n"); +} + +static void +descriptor_add(int fd) +{ + + ndescriptors++; + if (descriptors == NULL) { + descriptors = malloc(sizeof(descriptors[0]) * ndescriptors); + } else { + descriptors = realloc(descriptors, + sizeof(descriptors[0]) * ndescriptors); + } + assert(descriptors != NULL); + descriptors[ndescriptors - 1] = fd; +} + +static int +descriptor_get(int pos) +{ + + if (pos < 0 || pos >= ndescriptors) { + fprintf(stderr, "invalid descriptor %d\n", pos); + exit(1); + } + + return (descriptors[pos]); +} + +static unsigned int +call_syscall(struct syscall_desc *scall, char *argv[]) +{ + struct stat64 sb; + long long flags; + unsigned int i; + char *endp; + int name, rval; + union { + char *str; + long long num; + } args[MAX_ARGS]; +#ifdef HAS_FREEBSD_ACL + int entry_id = ACL_FIRST_ENTRY; + acl_t acl, newacl; + acl_entry_t entry, newentry; +#endif + + /* + * Verify correctness of the arguments. + */ + for (i = 0; i < sizeof(args)/sizeof(args[0]); i++) { + if (scall->sd_args[i] == TYPE_NONE) { + if (argv[i] == NULL || strcmp(argv[i], ":") == 0) + break; + fprintf(stderr, "too many arguments [%s]\n", argv[i]); + exit(1); + } else { + if (argv[i] == NULL || strcmp(argv[i], ":") == 0) { + if (scall->sd_args[i] & TYPE_OPTIONAL) + break; + fprintf(stderr, "too few arguments\n"); + exit(1); + } + if ((scall->sd_args[i] & TYPE_MASK) == TYPE_STRING) { + if (strcmp(argv[i], "NULL") == 0) + args[i].str = NULL; + else if (strcmp(argv[i], "DEADCODE") == 0) + args[i].str = (void *)0xdeadc0de; + else + args[i].str = argv[i]; + } else if ((scall->sd_args[i] & TYPE_MASK) == + TYPE_NUMBER) { + args[i].num = strtoll(argv[i], &endp, 0); + if (*endp != '\0' && + !isspace((unsigned char)*endp)) { + fprintf(stderr, + "invalid argument %u, number expected [%s]\n", + i, endp); + exit(1); + } + } else if ((scall->sd_args[i] & TYPE_MASK) == + TYPE_DESCRIPTOR) { + if (strcmp(argv[i], "AT_FDCWD") == 0) { + args[i].num = AT_FDCWD; + } else if (strcmp(argv[i], "BADFD") == 0) { + /* In case AT_FDCWD is -1 on some systems... */ + if (AT_FDCWD == -1) + args[i].num = -2; + else + args[i].num = -1; + } else { + int pos; + + pos = strtoll(argv[i], &endp, 0); + if (*endp != '\0' && + !isspace((unsigned char)*endp)) { + fprintf(stderr, + "invalid argument %u, number expected [%s]\n", + i, endp); + exit(1); + } + args[i].num = descriptor_get(pos); + } + } + } + } + /* + * Call the given syscall. + */ +#define NUM(n) (args[(n)].num) +#define STR(n) (args[(n)].str) + switch (scall->sd_action) { + case ACTION_OPEN: + flags = str2flags(open_flags, STR(1)); + if (flags & O_CREAT) { + if (i == 2) { + fprintf(stderr, "too few arguments\n"); + exit(1); + } + rval = open(STR(0), (int)flags, (mode_t)NUM(2)); + } else { + if (i == 3) { + fprintf(stderr, "too many arguments\n"); + exit(1); + } + rval = open(STR(0), (int)flags); + } + if (rval >= 0) + descriptor_add(rval); + break; + case ACTION_OPENAT: + flags = str2flags(open_flags, STR(2)); + if (flags & O_CREAT) { + if (i == 3) { + fprintf(stderr, "too few arguments\n"); + exit(1); + } + rval = openat(NUM(0), STR(1), (int)flags, + (mode_t)NUM(3)); + } else { + if (i == 4) { + fprintf(stderr, "too many arguments\n"); + exit(1); + } + rval = openat(NUM(0), STR(1), (int)flags); + } + if (rval >= 0) + descriptor_add(rval); + break; + case ACTION_CREATE: + rval = open(STR(0), O_CREAT | O_EXCL, (mode_t)NUM(1)); + if (rval >= 0) + close(rval); + break; + case ACTION_UNLINK: + rval = unlink(STR(0)); + break; + case ACTION_UNLINKAT: + rval = unlinkat(NUM(0), STR(1), + (int)str2flags(unlinkat_flags, STR(2))); + break; + case ACTION_MKDIR: + rval = mkdir(STR(0), (mode_t)NUM(1)); + break; + case ACTION_MKDIRAT: + rval = mkdirat(NUM(0), STR(1), (mode_t)NUM(2)); + break; + case ACTION_RMDIR: + rval = rmdir(STR(0)); + break; + case ACTION_LINK: + rval = link(STR(0), STR(1)); + break; + case ACTION_LINKAT: + rval = linkat(NUM(0), STR(1), NUM(2), STR(3), + (int)str2flags(linkat_flags, STR(4))); + break; + case ACTION_SYMLINK: + rval = symlink(STR(0), STR(1)); + break; + case ACTION_SYMLINKAT: + rval = symlinkat(STR(0), NUM(1), STR(2)); + break; + case ACTION_RENAME: + rval = rename(STR(0), STR(1)); + break; + case ACTION_RENAMEAT: + rval = renameat(NUM(0), STR(1), NUM(2), STR(3)); + break; + case ACTION_MKFIFO: + rval = mkfifo(STR(0), (mode_t)NUM(1)); + break; + case ACTION_MKFIFOAT: + rval = mkfifoat(NUM(0), STR(1), (mode_t)NUM(2)); + break; + case ACTION_MKNOD: + case ACTION_MKNODAT: + { + mode_t ntype; + dev_t dev; + int fa; + + switch (scall->sd_action) { + case ACTION_MKNOD: + fa = 0; + break; + case ACTION_MKNODAT: + fa = 1; + break; + default: + abort(); + } + + dev = makedev(NUM(fa + 3), NUM(fa + 4)); + if (strcmp(STR(fa + 1), "c") == 0) /* character device */ + ntype = S_IFCHR; + else if (strcmp(STR(fa + 1), "b") == 0) /* block device */ + ntype = S_IFBLK; + else if (strcmp(STR(fa + 1), "f") == 0) /* fifo special */ + ntype = S_IFIFO; + else if (strcmp(STR(fa + 1), "d") == 0) /* directory */ + ntype = S_IFDIR; + else if (strcmp(STR(fa + 1), "o") == 0) /* regular file */ + ntype = S_IFREG; + else { + fprintf(stderr, "wrong argument 1\n"); + exit(1); + } + switch (scall->sd_action) { + case ACTION_MKNOD: + rval = mknod(STR(0), ntype | NUM(2), dev); + break; + case ACTION_MKNODAT: + rval = mknodat(NUM(0), STR(1), ntype | NUM(3), dev); + break; + default: + abort(); + } + break; + } + case ACTION_BIND: + { + struct sockaddr_un sunx; + + sunx.sun_family = AF_UNIX; + strncpy(sunx.sun_path, STR(0), sizeof(sunx.sun_path) - 1); + sunx.sun_path[sizeof(sunx.sun_path) - 1] = '\0'; + rval = socket(AF_UNIX, SOCK_STREAM, 0); + if (rval < 0) + break; + rval = bind(rval, (struct sockaddr *)&sunx, sizeof(sunx)); + break; + } +#ifdef HAS_BINDAT + case ACTION_BINDAT: + { + struct sockaddr_un sunx; + + sunx.sun_family = AF_UNIX; + strncpy(sunx.sun_path, STR(1), sizeof(sunx.sun_path) - 1); + sunx.sun_path[sizeof(sunx.sun_path) - 1] = '\0'; + rval = socket(AF_UNIX, SOCK_STREAM, 0); + if (rval < 0) + break; + rval = bindat(NUM(0), rval, (struct sockaddr *)&sunx, + sizeof(sunx)); + break; + } +#endif + case ACTION_CONNECT: + { + struct sockaddr_un sunx; + + sunx.sun_family = AF_UNIX; + strncpy(sunx.sun_path, STR(0), sizeof(sunx.sun_path) - 1); + sunx.sun_path[sizeof(sunx.sun_path) - 1] = '\0'; + rval = socket(AF_UNIX, SOCK_STREAM, 0); + if (rval < 0) + break; + rval = connect(rval, (struct sockaddr *)&sunx, sizeof(sunx)); + break; + } +#ifdef HAS_CONNECTAT + case ACTION_CONNECTAT: + { + struct sockaddr_un sunx; + + sunx.sun_family = AF_UNIX; + strncpy(sunx.sun_path, STR(1), sizeof(sunx.sun_path) - 1); + sunx.sun_path[sizeof(sunx.sun_path) - 1] = '\0'; + rval = socket(AF_UNIX, SOCK_STREAM, 0); + if (rval < 0) + break; + rval = connectat(NUM(0), rval, (struct sockaddr *)&sunx, + sizeof(sunx)); + break; + } +#endif + case ACTION_CHMOD: + rval = chmod(STR(0), (mode_t)NUM(1)); + break; + case ACTION_FCHMOD: + rval = fchmod(NUM(0), (mode_t)NUM(1)); + break; +#ifdef HAS_LCHMOD + case ACTION_LCHMOD: + rval = lchmod(STR(0), (mode_t)NUM(1)); + break; +#endif + case ACTION_FCHMODAT: + rval = fchmodat(NUM(0), STR(1), (mode_t)NUM(2), + str2flags(fchmodat_flags, STR(3))); + break; + case ACTION_CHOWN: + rval = chown(STR(0), (uid_t)NUM(1), (gid_t)NUM(2)); + break; + case ACTION_FCHOWN: + rval = fchown(NUM(0), (uid_t)NUM(1), (gid_t)NUM(2)); + break; + case ACTION_LCHOWN: + rval = lchown(STR(0), (uid_t)NUM(1), (gid_t)NUM(2)); + break; + case ACTION_FCHOWNAT: + rval = fchownat(NUM(0), STR(1), (uid_t)NUM(2), (gid_t)NUM(3), + (int)str2flags(fchownat_flags, STR(4))); + break; +#ifdef HAS_CHFLAGS + case ACTION_CHFLAGS: + rval = chflags(STR(0), + (unsigned long)str2flags(chflags_flags, STR(1))); + break; +#endif +#ifdef HAS_FCHFLAGS + case ACTION_FCHFLAGS: + rval = fchflags(NUM(0), + (unsigned long)str2flags(chflags_flags, STR(1))); + break; +#endif +#ifdef HAS_CHFLAGSAT + case ACTION_CHFLAGSAT: + rval = chflagsat(NUM(0), STR(1), + (unsigned long)str2flags(chflags_flags, STR(2)), + (int)str2flags(chflagsat_flags, STR(3))); + break; +#endif +#ifdef HAS_LCHFLAGS + case ACTION_LCHFLAGS: + rval = lchflags(STR(0), + (unsigned long)str2flags(chflags_flags, STR(1))); + break; +#endif + case ACTION_TRUNCATE: + rval = truncate64(STR(0), NUM(1)); + break; + case ACTION_FTRUNCATE: + rval = ftruncate64(NUM(0), NUM(1)); + break; + case ACTION_STAT: + rval = stat64(STR(0), &sb); + if (rval == 0) { + show_stats(&sb, STR(1)); + return (i); + } + break; + case ACTION_FSTAT: + rval = fstat64(NUM(0), &sb); + if (rval == 0) { + show_stats(&sb, STR(1)); + return (i); + } + break; + case ACTION_LSTAT: + rval = lstat64(STR(0), &sb); + if (rval == 0) { + show_stats(&sb, STR(1)); + return (i); + } + break; + case ACTION_FSTATAT: + rval = fstatat(NUM(0), STR(1), &sb, + (int)str2flags(fstatat_flags, STR(2))); + if (rval == 0) { + show_stats(&sb, STR(3)); + return (i); + } + break; + case ACTION_PATHCONF: + case ACTION_FPATHCONF: +#ifdef HAS_LPATHCONF + case ACTION_LPATHCONF: +#endif + { + long lrval; + + name = str2name(pathconf_names, STR(1)); + if (name == -1) { + fprintf(stderr, "unknown name %s", STR(1)); + exit(1); + } + errno = 0; + switch (scall->sd_action) { + case ACTION_PATHCONF: + lrval = pathconf(STR(0), name); + break; + case ACTION_FPATHCONF: + lrval = fpathconf(NUM(0), name); + break; +#ifdef HAS_LPATHCONF + case ACTION_LPATHCONF: + lrval = lpathconf(STR(0), name); + break; +#endif + default: + abort(); + } + if (lrval == -1 && errno == 0) { + printf("unlimited\n"); + return (i); + } else if (lrval >= 0) { + printf("%ld\n", lrval); + return (i); + } + rval = -1; + break; + } +#ifdef HAS_FREEBSD_ACL + case ACTION_PREPENDACL: + rval = -1; + + acl = acl_get_file(STR(0), ACL_TYPE_NFS4); + if (acl == NULL) + break; + + newacl = acl_from_text(STR(1)); + if (acl == NULL) + break; + + while (acl_get_entry(newacl, entry_id, &newentry) == 1) { + entry_id = ACL_NEXT_ENTRY; + + if (acl_create_entry_np(&acl, &entry, 0)) + break; + + if (acl_copy_entry(entry, newentry)) + break; + } + + rval = acl_set_file(STR(0), ACL_TYPE_NFS4, acl); + break; + case ACTION_READACL: + acl = acl_get_file(STR(0), ACL_TYPE_NFS4); + if (acl == NULL) + rval = -1; + else + rval = 0; + break; +#endif + case ACTION_WRITE: + rval = write(NUM(0), STR(1), strlen(STR(1))); + break; + default: + fprintf(stderr, "unsupported syscall\n"); + exit(1); + } +#undef STR +#undef NUM + if (rval < 0) { + const char *serrno; + + serrno = err2str(errno); + fprintf(stderr, "%s returned %d\n", scall->sd_name, rval); + printf("%s\n", serrno); + exit(1); + } + printf("0\n"); + return (i); +} + +static void +set_gids(char *gids) +{ + gid_t *gidset; + long ngroups; + char *g, *endp; + unsigned i; + + ngroups = sysconf(_SC_NGROUPS_MAX); + assert(ngroups > 0); + gidset = malloc(sizeof(*gidset) * ngroups); + assert(gidset != NULL); + for (i = 0, g = strtok(gids, ","); g != NULL; + g = strtok(NULL, ","), i++) { + if (i >= ngroups) { + fprintf(stderr, "too many gids\n"); + exit(1); + } + gidset[i] = strtol(g, &endp, 0); + if (*endp != '\0' && !isspace((unsigned char)*endp)) { + fprintf(stderr, "invalid gid '%s' - number expected\n", + g); + exit(1); + } + } + if (setgroups(i, gidset) < 0) { + fprintf(stderr, "cannot change groups: %s\n", strerror(errno)); + exit(1); + } + if (setegid(gidset[0]) < 0) { + fprintf(stderr, "cannot change effective gid: %s\n", + strerror(errno)); + exit(1); + } + free(gidset); +} + +int +main(int argc, char *argv[]) +{ + struct syscall_desc *scall; + unsigned int n; + char *gids, *endp; + int uid, umsk, ch; + + uid = -1; + gids = NULL; + umsk = 0; + + while ((ch = getopt(argc, argv, "g:u:U:")) != -1) { + switch(ch) { + case 'g': + gids = optarg; + break; + case 'u': + uid = (int)strtol(optarg, &endp, 0); + if (*endp != '\0' && !isspace((unsigned char)*endp)) { + fprintf(stderr, "invalid uid '%s' - number " + "expected\n", optarg); + exit(1); + } + break; + case 'U': + umsk = (int)strtol(optarg, &endp, 0); + if (*endp != '\0' && !isspace((unsigned char)*endp)) { + fprintf(stderr, "invalid umask '%s' - number " + "expected\n", optarg); + exit(1); + } + break; + default: + usage(); + } + } + argc -= optind; + argv += optind; + + if (argc < 1) { + fprintf(stderr, "too few arguments\n"); + usage(); + } + + if (gids != NULL) { + fprintf(stderr, "changing groups to %s\n", gids); + set_gids(gids); + } + if (uid != -1) { + fprintf(stderr, "changing uid to %d\n", uid); + if (setuid(uid) < 0) { + fprintf(stderr, "cannot change uid: %s\n", + strerror(errno)); + exit(1); + } + } + + /* Change umask to requested value or to 0, if not requested. */ + umask(umsk); + + for (;;) { + scall = find_syscall(argv[0]); + if (scall == NULL) { + fprintf(stderr, "syscall '%s' not supported\n", + argv[0]); + exit(1); + } + argc++; + argv++; + n = call_syscall(scall, argv); + argc += n; + argv += n; + if (argv[0] == NULL) + break; + argc++; + argv++; + } + + exit(0); +} + +static const char * +err2str(int error) +{ + static char errnum[8]; + + switch (error) { +#ifdef EPERM + case EPERM: + return ("EPERM"); +#endif +#ifdef ENOENT + case ENOENT: + return ("ENOENT"); +#endif +#ifdef ESRCH + case ESRCH: + return ("ESRCH"); +#endif +#ifdef EINTR + case EINTR: + return ("EINTR"); +#endif +#ifdef EIO + case EIO: + return ("EIO"); +#endif +#ifdef ENXIO + case ENXIO: + return ("ENXIO"); +#endif +#ifdef E2BIG + case E2BIG: + return ("E2BIG"); +#endif +#ifdef ENOEXEC + case ENOEXEC: + return ("ENOEXEC"); +#endif +#ifdef EBADF + case EBADF: + return ("EBADF"); +#endif +#ifdef ECHILD + case ECHILD: + return ("ECHILD"); +#endif +#ifdef EDEADLK + case EDEADLK: + return ("EDEADLK"); +#endif +#ifdef ENOMEM + case ENOMEM: + return ("ENOMEM"); +#endif +#ifdef EACCES + case EACCES: + return ("EACCES"); +#endif +#ifdef EFAULT + case EFAULT: + return ("EFAULT"); +#endif +#ifdef ENOTBLK + case ENOTBLK: + return ("ENOTBLK"); +#endif +#ifdef EBUSY + case EBUSY: + return ("EBUSY"); +#endif +#ifdef EEXIST + case EEXIST: + return ("EEXIST"); +#endif +#ifdef EXDEV + case EXDEV: + return ("EXDEV"); +#endif +#ifdef ENODEV + case ENODEV: + return ("ENODEV"); +#endif +#ifdef ENOTDIR + case ENOTDIR: + return ("ENOTDIR"); +#endif +#ifdef EISDIR + case EISDIR: + return ("EISDIR"); +#endif +#ifdef EINVAL + case EINVAL: + return ("EINVAL"); +#endif +#ifdef ENFILE + case ENFILE: + return ("ENFILE"); +#endif +#ifdef EMFILE + case EMFILE: + return ("EMFILE"); +#endif +#ifdef ENOTTY + case ENOTTY: + return ("ENOTTY"); +#endif +#ifdef ETXTBSY + case ETXTBSY: + return ("ETXTBSY"); +#endif +#ifdef EFBIG + case EFBIG: + return ("EFBIG"); +#endif +#ifdef ENOSPC + case ENOSPC: + return ("ENOSPC"); +#endif +#ifdef ESPIPE + case ESPIPE: + return ("ESPIPE"); +#endif +#ifdef EROFS + case EROFS: + return ("EROFS"); +#endif +#ifdef EMLINK + case EMLINK: + return ("EMLINK"); +#endif +#ifdef EPIPE + case EPIPE: + return ("EPIPE"); +#endif +#ifdef EDOM + case EDOM: + return ("EDOM"); +#endif +#ifdef ERANGE + case ERANGE: + return ("ERANGE"); +#endif +#ifdef EAGAIN + case EAGAIN: + return ("EAGAIN"); +#endif +#ifdef EINPROGRESS + case EINPROGRESS: + return ("EINPROGRESS"); +#endif +#ifdef EALREADY + case EALREADY: + return ("EALREADY"); +#endif +#ifdef ENOTSOCK + case ENOTSOCK: + return ("ENOTSOCK"); +#endif +#ifdef EDESTADDRREQ + case EDESTADDRREQ: + return ("EDESTADDRREQ"); +#endif +#ifdef EMSGSIZE + case EMSGSIZE: + return ("EMSGSIZE"); +#endif +#ifdef EPROTOTYPE + case EPROTOTYPE: + return ("EPROTOTYPE"); +#endif +#ifdef ENOPROTOOPT + case ENOPROTOOPT: + return ("ENOPROTOOPT"); +#endif +#ifdef EPROTONOSUPPORT + case EPROTONOSUPPORT: + return ("EPROTONOSUPPORT"); +#endif +#ifdef ESOCKTNOSUPPORT + case ESOCKTNOSUPPORT: + return ("ESOCKTNOSUPPORT"); +#endif +#ifdef EOPNOTSUPP + case EOPNOTSUPP: + return ("EOPNOTSUPP"); +#endif +#ifdef EPFNOSUPPORT + case EPFNOSUPPORT: + return ("EPFNOSUPPORT"); +#endif +#ifdef EAFNOSUPPORT + case EAFNOSUPPORT: + return ("EAFNOSUPPORT"); +#endif +#ifdef EADDRINUSE + case EADDRINUSE: + return ("EADDRINUSE"); +#endif +#ifdef EADDRNOTAVAIL + case EADDRNOTAVAIL: + return ("EADDRNOTAVAIL"); +#endif +#ifdef ENETDOWN + case ENETDOWN: + return ("ENETDOWN"); +#endif +#ifdef ENETUNREACH + case ENETUNREACH: + return ("ENETUNREACH"); +#endif +#ifdef ENETRESET + case ENETRESET: + return ("ENETRESET"); +#endif +#ifdef ECONNABORTED + case ECONNABORTED: + return ("ECONNABORTED"); +#endif +#ifdef ECONNRESET + case ECONNRESET: + return ("ECONNRESET"); +#endif +#ifdef ENOBUFS + case ENOBUFS: + return ("ENOBUFS"); +#endif +#ifdef EISCONN + case EISCONN: + return ("EISCONN"); +#endif +#ifdef ENOTCONN + case ENOTCONN: + return ("ENOTCONN"); +#endif +#ifdef ESHUTDOWN + case ESHUTDOWN: + return ("ESHUTDOWN"); +#endif +#ifdef ETOOMANYREFS + case ETOOMANYREFS: + return ("ETOOMANYREFS"); +#endif +#ifdef ETIMEDOUT + case ETIMEDOUT: + return ("ETIMEDOUT"); +#endif +#ifdef ECONNREFUSED + case ECONNREFUSED: + return ("ECONNREFUSED"); +#endif +#ifdef ELOOP + case ELOOP: + return ("ELOOP"); +#endif +#ifdef ENAMETOOLONG + case ENAMETOOLONG: + return ("ENAMETOOLONG"); +#endif +#ifdef EHOSTDOWN + case EHOSTDOWN: + return ("EHOSTDOWN"); +#endif +#ifdef EHOSTUNREACH + case EHOSTUNREACH: + return ("EHOSTUNREACH"); +#endif +#ifdef ENOTEMPTY + case ENOTEMPTY: + return ("ENOTEMPTY"); +#endif +#ifdef EPROCLIM + case EPROCLIM: + return ("EPROCLIM"); +#endif +#ifdef EUSERS + case EUSERS: + return ("EUSERS"); +#endif +#ifdef EDQUOT + case EDQUOT: + return ("EDQUOT"); +#endif +#ifdef ESTALE + case ESTALE: + return ("ESTALE"); +#endif +#ifdef EREMOTE + case EREMOTE: + return ("EREMOTE"); +#endif +#ifdef EBADRPC + case EBADRPC: + return ("EBADRPC"); +#endif +#ifdef ERPCMISMATCH + case ERPCMISMATCH: + return ("ERPCMISMATCH"); +#endif +#ifdef EPROGUNAVAIL + case EPROGUNAVAIL: + return ("EPROGUNAVAIL"); +#endif +#ifdef EPROGMISMATCH + case EPROGMISMATCH: + return ("EPROGMISMATCH"); +#endif +#ifdef EPROCUNAVAIL + case EPROCUNAVAIL: + return ("EPROCUNAVAIL"); +#endif +#ifdef ENOLCK + case ENOLCK: + return ("ENOLCK"); +#endif +#ifdef ENOSYS + case ENOSYS: + return ("ENOSYS"); +#endif +#ifdef EFTYPE + case EFTYPE: + return ("EFTYPE"); +#endif +#ifdef EAUTH + case EAUTH: + return ("EAUTH"); +#endif +#ifdef ENEEDAUTH + case ENEEDAUTH: + return ("ENEEDAUTH"); +#endif +#ifdef EIDRM + case EIDRM: + return ("EIDRM"); +#endif +#ifdef ENOMSG + case ENOMSG: + return ("ENOMSG"); +#endif +#ifdef EOVERFLOW + case EOVERFLOW: + return ("EOVERFLOW"); +#endif +#ifdef ECANCELED + case ECANCELED: + return ("ECANCELED"); +#endif +#ifdef EILSEQ + case EILSEQ: + return ("EILSEQ"); +#endif +#ifdef ENOATTR + case ENOATTR: + return ("ENOATTR"); +#endif +#ifdef EDOOFUS + case EDOOFUS: + return ("EDOOFUS"); +#endif +#ifdef EBADMSG + case EBADMSG: + return ("EBADMSG"); +#endif +#ifdef EMULTIHOP + case EMULTIHOP: + return ("EMULTIHOP"); +#endif +#ifdef ENOLINK + case ENOLINK: + return ("ENOLINK"); +#endif +#ifdef EPROTO + case EPROTO: + return ("EPROTO"); +#endif + default: + snprintf(errnum, sizeof(errnum), "%d", error); + return (errnum); + } +} diff --git a/tests/chflags/00.t b/tests/chflags/00.t new file mode 100644 index 000000000000..4d7b4c9a3464 --- /dev/null +++ b/tests/chflags/00.t @@ -0,0 +1,178 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/chflags/00.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="chflags changes flags" + +dir=`dirname $0` +. ${dir}/../misc.sh + +require chflags + +case "${os}:${fs}" in +FreeBSD:UFS) + allflags="UF_NODUMP,UF_IMMUTABLE,UF_APPEND,UF_NOUNLINK,UF_OPAQUE,SF_ARCHIVED,SF_IMMUTABLE,SF_APPEND,SF_NOUNLINK" + userflags="UF_NODUMP,UF_IMMUTABLE,UF_APPEND,UF_NOUNLINK,UF_OPAQUE" + systemflags="SF_ARCHIVED,SF_IMMUTABLE,SF_APPEND,SF_NOUNLINK" + + echo "1..742" + ;; +FreeBSD:ZFS) + allflags="UF_NODUMP,SF_IMMUTABLE,SF_APPEND,SF_NOUNLINK" + userflags="UF_NODUMP" + systemflags="SF_IMMUTABLE,SF_APPEND,SF_NOUNLINK" + + echo "1..482" + ;; +*) + quick_exit + ;; +esac + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n2} 0755 +cdir=`pwd` +cd ${n2} + +for type in regular dir fifo block char socket; do + create_file ${type} ${n0} + expect none stat ${n0} flags + expect 0 chflags ${n0} ${allflags} + expect ${allflags} stat ${n0} flags + expect 0 chflags ${n0} ${userflags} + expect ${userflags} stat ${n0} flags + expect 0 chflags ${n0} ${systemflags} + expect ${systemflags} stat ${n0} flags + expect 0 chflags ${n0} none + expect none stat ${n0} flags + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n0} + else + expect 0 unlink ${n0} + fi + + create_file ${type} ${n0} + expect none stat ${n0} flags + expect 0 lchflags ${n0} ${allflags} + expect ${allflags} stat ${n0} flags + expect 0 lchflags ${n0} ${userflags} + expect ${userflags} stat ${n0} flags + expect 0 lchflags ${n0} ${systemflags} + expect ${systemflags} stat ${n0} flags + expect 0 lchflags ${n0} none + expect none stat ${n0} flags + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n0} + else + expect 0 unlink ${n0} + fi +done + +expect 0 create ${n0} 0644 +expect 0 symlink ${n0} ${n1} +expect none stat ${n1} flags +expect none lstat ${n1} flags +expect 0 chflags ${n1} ${allflags} +expect ${allflags} stat ${n1} flags +expect none lstat ${n1} flags +expect 0 chflags ${n1} ${userflags} +expect ${userflags} stat ${n1} flags +expect none lstat ${n1} flags +expect 0 chflags ${n1} ${systemflags} +expect ${systemflags} stat ${n1} flags +expect none lstat ${n1} flags +expect 0 chflags ${n1} none +expect none stat ${n1} flags +expect none lstat ${n1} flags +expect 0 unlink ${n1} +expect 0 unlink ${n0} + +expect 0 create ${n0} 0644 +expect 0 symlink ${n0} ${n1} +expect none stat ${n1} flags +expect none lstat ${n1} flags +expect 0 lchflags ${n1} ${allflags} +expect ${allflags} lstat ${n1} flags +expect none stat ${n1} flags +expect 0 lchflags ${n1} ${userflags} +expect ${userflags} lstat ${n1} flags +expect none stat ${n1} flags +expect 0 lchflags ${n1} ${systemflags} +expect ${systemflags} lstat ${n1} flags +expect none stat ${n1} flags +expect 0 lchflags ${n1} none +expect none lstat ${n1} flags +expect none stat ${n1} flags +expect 0 unlink ${n1} +expect 0 unlink ${n0} + +# successful chflags(2) updates ctime. +for type in regular dir fifo block char socket symlink; do + if [ "${type}" != "symlink" ]; then + create_file ${type} ${n0} + for flag in `echo ${allflags},none | tr ',' ' '`; do + ctime1=`${fstest} stat ${n0} ctime` + sleep 1 + expect 0 chflags ${n0} ${flag} + ctime2=`${fstest} stat ${n0} ctime` + test_check $ctime1 -lt $ctime2 + done + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n0} + else + expect 0 unlink ${n0} + fi + fi + + create_file ${type} ${n0} + for flag in `echo ${allflags},none | tr ',' ' '`; do + ctime1=`${fstest} lstat ${n0} ctime` + sleep 1 + expect 0 lchflags ${n0} ${flag} + ctime2=`${fstest} lstat ${n0} ctime` + test_check $ctime1 -lt $ctime2 + done + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n0} + else + expect 0 unlink ${n0} + fi +done + +# unsuccessful chflags(2) does not update ctime. +for type in regular dir fifo block char socket symlink; do + if [ "${type}" != "symlink" ]; then + create_file ${type} ${n0} + for flag in `echo ${allflags},none | tr ',' ' '`; do + ctime1=`${fstest} stat ${n0} ctime` + sleep 1 + expect EPERM -u 65534 chflags ${n0} ${flag} + ctime2=`${fstest} stat ${n0} ctime` + test_check $ctime1 -eq $ctime2 + done + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n0} + else + expect 0 unlink ${n0} + fi + fi + + create_file ${type} ${n0} + for flag in `echo ${allflags},none | tr ',' ' '`; do + ctime1=`${fstest} lstat ${n0} ctime` + sleep 1 + expect EPERM -u 65534 lchflags ${n0} ${flag} + ctime2=`${fstest} lstat ${n0} ctime` + test_check $ctime1 -eq $ctime2 + done + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n0} + else + expect 0 unlink ${n0} + fi +done + +cd ${cdir} +expect 0 rmdir ${n2} diff --git a/tests/chflags/01.t b/tests/chflags/01.t new file mode 100644 index 000000000000..62713fd0347a --- /dev/null +++ b/tests/chflags/01.t @@ -0,0 +1,22 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/chflags/01.t 211474 2010-08-18 22:06:43Z pjd $ + +desc="chflags returns ENOTDIR if a component of the path prefix is not a directory" + +dir=`dirname $0` +. ${dir}/../misc.sh + +require chflags + +echo "1..17" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +for type in regular fifo block char socket; do + create_file ${type} ${n0}/${n1} + expect ENOTDIR chflags ${n0}/${n1}/test SF_IMMUTABLE + expect 0 unlink ${n0}/${n1} +done +expect 0 rmdir ${n0} diff --git a/tests/chflags/02.t b/tests/chflags/02.t new file mode 100644 index 000000000000..d4a0b371b094 --- /dev/null +++ b/tests/chflags/02.t @@ -0,0 +1,28 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/chflags/02.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="chflags returns ENAMETOOLONG if a component of a pathname exceeded {NAME_MAX} characters" + +dir=`dirname $0` +. ${dir}/../misc.sh + +require chflags + +echo "1..12" + +nx=`namegen_max` +nxx="${nx}x" + +expect 0 create ${nx} 0644 +expect 0 chflags ${nx} SF_IMMUTABLE +expect SF_IMMUTABLE stat ${nx} flags +expect 0 chflags ${nx} none +expect 0 unlink ${nx} +expect ENAMETOOLONG chflags ${nxx} SF_IMMUTABLE + +expect 0 create ${nx} 0644 +expect 0 lchflags ${nx} SF_IMMUTABLE +expect SF_IMMUTABLE stat ${nx} flags +expect 0 lchflags ${nx} none +expect 0 unlink ${nx} +expect ENAMETOOLONG lchflags ${nxx} SF_IMMUTABLE diff --git a/tests/chflags/03.t b/tests/chflags/03.t new file mode 100644 index 000000000000..87a62029509b --- /dev/null +++ b/tests/chflags/03.t @@ -0,0 +1,32 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/chflags/03.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="chflags returns ENAMETOOLONG if an entire path name exceeded {PATH_MAX} characters" + +dir=`dirname $0` +. ${dir}/../misc.sh + +require chflags + +echo "1..12" + +nx=`dirgen_max` +nxx="${nx}x" + +mkdir -p "${nx%/*}" + +expect 0 create ${nx} 0644 +expect 0 chflags ${nx} SF_IMMUTABLE +expect SF_IMMUTABLE stat ${nx} flags +expect 0 chflags ${nx} none +expect 0 unlink ${nx} +expect ENAMETOOLONG chflags ${nxx} SF_IMMUTABLE + +expect 0 create ${nx} 0644 +expect 0 lchflags ${nx} SF_IMMUTABLE +expect SF_IMMUTABLE stat ${nx} flags +expect 0 lchflags ${nx} none +expect 0 unlink ${nx} +expect ENAMETOOLONG lchflags ${nxx} SF_IMMUTABLE + +rm -rf "${nx%%/*}" diff --git a/tests/chflags/04.t b/tests/chflags/04.t new file mode 100644 index 000000000000..3d5aa3b42ba3 --- /dev/null +++ b/tests/chflags/04.t @@ -0,0 +1,19 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/chflags/04.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="chflags returns ENOENT if the named file does not exist" + +dir=`dirname $0` +. ${dir}/../misc.sh + +require chflags + +echo "1..4" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +expect ENOENT chflags ${n0}/${n1}/test SF_IMMUTABLE +expect ENOENT chflags ${n0}/${n1} SF_IMMUTABLE +expect 0 rmdir ${n0} diff --git a/tests/chflags/05.t b/tests/chflags/05.t new file mode 100644 index 000000000000..cc3e04b3ec57 --- /dev/null +++ b/tests/chflags/05.t @@ -0,0 +1,35 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/chflags/05.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="chflags returns EACCES when search permission is denied for a component of the path prefix" + +dir=`dirname $0` +. ${dir}/../misc.sh + +require chflags + +echo "1..16" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n0} 0755 +cdir=`pwd` +cd ${n0} +expect 0 mkdir ${n1} 0755 +expect 0 chown ${n1} 65534 65534 +expect 0 -u 65534 -g 65534 create ${n1}/${n2} 0644 +expect 0 -u 65534 -g 65534 chflags ${n1}/${n2} UF_NODUMP +expect UF_NODUMP -u 65534 -g 65534 stat ${n1}/${n2} flags +expect 0 -u 65534 -g 65534 chflags ${n1}/${n2} none +expect 0 chmod ${n1} 0644 +expect EACCES -u 65534 -g 65534 chflags ${n1}/${n2} UF_NODUMP +expect 0 chmod ${n1} 0755 +expect 0 -u 65534 -g 65534 chflags ${n1}/${n2} UF_NODUMP +expect UF_NODUMP -u 65534 -g 65534 stat ${n1}/${n2} flags +expect 0 -u 65534 -g 65534 chflags ${n1}/${n2} none +expect 0 -u 65534 -g 65534 unlink ${n1}/${n2} +expect 0 rmdir ${n1} +cd ${cdir} +expect 0 rmdir ${n0} diff --git a/tests/chflags/06.t b/tests/chflags/06.t new file mode 100644 index 000000000000..e4899eb7642e --- /dev/null +++ b/tests/chflags/06.t @@ -0,0 +1,21 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/chflags/06.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="chflags returns ELOOP if too many symbolic links were encountered in translating the pathname" + +dir=`dirname $0` +. ${dir}/../misc.sh + +require chflags + +echo "1..6" + +n0=`namegen` +n1=`namegen` + +expect 0 symlink ${n0} ${n1} +expect 0 symlink ${n1} ${n0} +expect ELOOP chflags ${n0}/test SF_IMMUTABLE +expect ELOOP chflags ${n1}/test SF_IMMUTABLE +expect 0 unlink ${n0} +expect 0 unlink ${n1} diff --git a/tests/chflags/07.t b/tests/chflags/07.t new file mode 100644 index 000000000000..c2d0af2447b9 --- /dev/null +++ b/tests/chflags/07.t @@ -0,0 +1,50 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/chflags/07.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="chflags returns EPERM when the effective user ID does not match the owner of the file and the effective user ID is not the super-user" + +dir=`dirname $0` +. ${dir}/../misc.sh + +require chflags + +echo "1..93" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n0} 0755 +cdir=`pwd` +cd ${n0} + +for type in regular dir fifo block char socket symlink; do + if [ "${type}" != "symlink" ]; then + create_file ${type} ${n1} + expect EPERM -u 65534 -g 65534 chflags ${n1} UF_NODUMP + expect none stat ${n1} flags + expect 0 chown ${n1} 65534 65534 + expect EPERM -u 65533 -g 65533 chflags ${n1} UF_NODUMP + expect none stat ${n1} flags + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n1} + else + expect 0 unlink ${n1} + fi + fi + + create_file ${type} ${n1} + expect EPERM -u 65534 -g 65534 lchflags ${n1} UF_NODUMP + expect none lstat ${n1} flags + expect 0 lchown ${n1} 65534 65534 + expect EPERM -u 65533 -g 65533 lchflags ${n1} UF_NODUMP + expect none lstat ${n1} flags + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n1} + else + expect 0 unlink ${n1} + fi +done + +cd ${cdir} +expect 0 rmdir ${n0} diff --git a/tests/chflags/08.t b/tests/chflags/08.t new file mode 100644 index 000000000000..62ed480feec0 --- /dev/null +++ b/tests/chflags/08.t @@ -0,0 +1,58 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/chflags/08.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="chflags returns EPERM when one of SF_IMMUTABLE, SF_APPEND, or SF_NOUNLINK is set and the user is not the super-user" + +dir=`dirname $0` +. ${dir}/../misc.sh + +require chflags + +echo "1..249" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n0} 0755 +cdir=`pwd` +cd ${n0} + +for type in regular dir fifo block char socket symlink; do + if [ "${type}" != "symlink" ]; then + create_file ${type} ${n1} + expect 0 chown ${n1} 65534 65534 + for flag in SF_IMMUTABLE SF_APPEND SF_NOUNLINK; do + expect 0 chflags ${n1} ${flag} + expect EPERM -u 65533 -g 65533 chflags ${n1} UF_NODUMP + expect ${flag} stat ${n1} flags + expect EPERM -u 65534 -g 65534 chflags ${n1} UF_NODUMP + expect ${flag} stat ${n1} flags + done + expect 0 chflags ${n1} none + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n1} + else + expect 0 unlink ${n1} + fi + fi + + create_file ${type} ${n1} + expect 0 lchown ${n1} 65534 65534 + for flag in SF_IMMUTABLE SF_APPEND SF_NOUNLINK; do + expect 0 lchflags ${n1} ${flag} + expect EPERM -u 65533 -g 65533 lchflags ${n1} UF_NODUMP + expect ${flag} lstat ${n1} flags + expect EPERM -u 65534 -g 65534 lchflags ${n1} UF_NODUMP + expect ${flag} lstat ${n1} flags + done + expect 0 lchflags ${n1} none + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n1} + else + expect 0 unlink ${n1} + fi +done + +cd ${cdir} +expect 0 rmdir ${n0} diff --git a/tests/chflags/09.t b/tests/chflags/09.t new file mode 100644 index 000000000000..e7bd5cc8d660 --- /dev/null +++ b/tests/chflags/09.t @@ -0,0 +1,66 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/chflags/09.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="chflags returns EPERM when one of SF_IMMUTABLE, SF_APPEND, or SF_NOUNLINK is set and securelevel is greater than 0" + +dir=`dirname $0` +. ${dir}/../misc.sh + +require chflags + +echo "1..327" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +old=`sysctl -n security.jail.chflags_allowed` +sysctl security.jail.chflags_allowed=1 >/dev/null + +expect 0 mkdir ${n0} 0755 +cdir=`pwd` +cd ${n0} + +for type in regular dir fifo block char socket symlink; do + if [ "${type}" != "symlink" ]; then + create_file ${type} ${n1} + expect 0 chown ${n1} 65534 65534 + for flag in SF_IMMUTABLE SF_APPEND SF_NOUNLINK; do + expect 0 chflags ${n1} ${flag} + jexpect 1 `pwd` EPERM chflags ${n1} UF_NODUMP + expect ${flag} stat ${n1} flags + jexpect 1 `pwd` EPERM -u 65533 -g 65533 chflags ${n1} UF_NODUMP + expect ${flag} stat ${n1} flags + jexpect 1 `pwd` EPERM -u 65534 -g 65534 chflags ${n1} UF_NODUMP + expect ${flag} stat ${n1} flags + done + expect 0 chflags ${n1} none + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n1} + else + expect 0 unlink ${n1} + fi + fi + + create_file ${type} ${n1} + expect 0 lchown ${n1} 65534 65534 + for flag in SF_IMMUTABLE SF_APPEND SF_NOUNLINK; do + expect 0 lchflags ${n1} ${flag} + jexpect 1 `pwd` EPERM lchflags ${n1} UF_NODUMP + expect ${flag} lstat ${n1} flags + jexpect 1 `pwd` EPERM -u 65533 -g 65533 lchflags ${n1} UF_NODUMP + expect ${flag} lstat ${n1} flags + jexpect 1 `pwd` EPERM -u 65534 -g 65534 lchflags ${n1} UF_NODUMP + expect ${flag} lstat ${n1} flags + done + expect 0 lchflags ${n1} none + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n1} + else + expect 0 unlink ${n1} + fi +done + +sysctl security.jail.chflags_allowed=${old} >/dev/null +cd ${cdir} +expect 0 rmdir ${n0} diff --git a/tests/chflags/10.t b/tests/chflags/10.t new file mode 100644 index 000000000000..11ce36b4d0ab --- /dev/null +++ b/tests/chflags/10.t @@ -0,0 +1,54 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/chflags/10.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="chflags returns EPERM if non-super-user tries to set one of SF_IMMUTABLE, SF_APPEND, or SF_NOUNLINK" + +dir=`dirname $0` +. ${dir}/../misc.sh + +require chflags + +echo "1..197" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n0} 0755 +cdir=`pwd` +cd ${n0} + +for type in regular dir fifo block char socket symlink; do + if [ "${type}" != "symlink" ]; then + create_file ${type} ${n1} + expect 0 chown ${n1} 65534 65534 + for flag in SF_IMMUTABLE SF_APPEND SF_NOUNLINK; do + expect EPERM -u 65533 -g 65533 chflags ${n1} ${flag} + expect none stat ${n1} flags + expect EPERM -u 65534 -g 65534 chflags ${n1} ${flag} + expect none stat ${n1} flags + done + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n1} + else + expect 0 unlink ${n1} + fi + fi + + create_file ${type} ${n1} + expect 0 lchown ${n1} 65534 65534 + for flag in SF_IMMUTABLE SF_APPEND SF_NOUNLINK; do + expect EPERM -u 65533 -g 65533 lchflags ${n1} ${flag} + expect none lstat ${n1} flags + expect EPERM -u 65534 -g 65534 lchflags ${n1} ${flag} + expect none lstat ${n1} flags + done + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n1} + else + expect 0 unlink ${n1} + fi +done + +cd ${cdir} +expect 0 rmdir ${n0} diff --git a/tests/chflags/11.t b/tests/chflags/11.t new file mode 100644 index 000000000000..33acca7f327a --- /dev/null +++ b/tests/chflags/11.t @@ -0,0 +1,58 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/chflags/11.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="chflags returns EPERM if a user tries to set or remove the SF_SNAPSHOT flag" + +dir=`dirname $0` +. ${dir}/../misc.sh + +require chflags_SF_SNAPSHOT + +echo "1..145" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n0} 0755 +cdir=`pwd` +cd ${n0} + +for type in regular dir fifo block char socket symlink; do + if [ "${type}" != "symlink" ]; then + create_file ${type} ${n1} + expect EPERM -u 65534 -g 65534 chflags ${n1} SF_SNAPSHOT + expect none stat ${n1} flags + expect EPERM chflags ${n1} SF_SNAPSHOT + expect none stat ${n1} flags + expect 0 chown ${n1} 65534 65534 + expect EPERM -u 65534 -g 65534 chflags ${n1} SF_SNAPSHOT + expect none stat ${n1} flags + expect EPERM chflags ${n1} SF_SNAPSHOT + expect none stat ${n1} flags + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n1} + else + expect 0 unlink ${n1} + fi + fi + + create_file ${type} ${n1} + expect EPERM -u 65534 -g 65534 lchflags ${n1} SF_SNAPSHOT + expect none lstat ${n1} flags + expect EPERM lchflags ${n1} SF_SNAPSHOT + expect none lstat ${n1} flags + expect 0 lchown ${n1} 65534 65534 + expect EPERM -u 65534 -g 65534 lchflags ${n1} SF_SNAPSHOT + expect none lstat ${n1} flags + expect EPERM lchflags ${n1} SF_SNAPSHOT + expect none lstat ${n1} flags + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n1} + else + expect 0 unlink ${n1} + fi +done + +cd ${cdir} +expect 0 rmdir ${n0} diff --git a/tests/chflags/12.t b/tests/chflags/12.t new file mode 100644 index 000000000000..8af941c59ef0 --- /dev/null +++ b/tests/chflags/12.t @@ -0,0 +1,68 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/chflags/12.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="chflags returns EROFS if the named file resides on a read-only file system" + +dir=`dirname $0` +. ${dir}/../misc.sh + +require chflags + +case "${os}:${fs}" in +FreeBSD:UFS) + echo "1..14" + + n0=`namegen` + n1=`namegen` + + expect 0 mkdir ${n0} 0755 + n=`mdconfig -a -n -t malloc -s 1m` + newfs /dev/md${n} >/dev/null + mount /dev/md${n} ${n0} + expect 0 create ${n0}/${n1} 0644 + expect 0 chflags ${n0}/${n1} UF_IMMUTABLE + expect UF_IMMUTABLE stat ${n0}/${n1} flags + expect 0 chflags ${n0}/${n1} none + expect none stat ${n0}/${n1} flags + mount -ur /dev/md${n} + expect EROFS chflags ${n0}/${n1} UF_IMMUTABLE + expect none stat ${n0}/${n1} flags + mount -uw /dev/md${n} + expect 0 chflags ${n0}/${n1} UF_IMMUTABLE + expect UF_IMMUTABLE stat ${n0}/${n1} flags + expect 0 chflags ${n0}/${n1} none + expect none stat ${n0}/${n1} flags + expect 0 unlink ${n0}/${n1} + umount /dev/md${n} + mdconfig -d -u ${n} + expect 0 rmdir ${n0} + ;; +FreeBSD:ZFS) + echo "1..12" + + n0=`namegen` + n1=`namegen` + + n=`mdconfig -a -n -t malloc -s 128m` + zpool create ${n0} /dev/md${n} + expect 0 create /${n0}/${n1} 0644 + expect 0 chflags /${n0}/${n1} UF_NODUMP + expect UF_NODUMP stat /${n0}/${n1} flags + expect 0 chflags /${n0}/${n1} none + expect none stat /${n0}/${n1} flags + zfs set readonly=on ${n0} + expect EROFS chflags /${n0}/${n1} UF_NODUMP + expect none stat /${n0}/${n1} flags + zfs set readonly=off ${n0} + expect 0 chflags /${n0}/${n1} UF_NODUMP + expect UF_NODUMP stat /${n0}/${n1} flags + expect 0 chflags /${n0}/${n1} none + expect none stat /${n0}/${n1} flags + expect 0 unlink /${n0}/${n1} + zpool destroy ${n0} + mdconfig -d -u ${n} + ;; +*) + quick_exit + ;; +esac diff --git a/tests/chflags/13.t b/tests/chflags/13.t new file mode 100644 index 000000000000..981122c8b3be --- /dev/null +++ b/tests/chflags/13.t @@ -0,0 +1,14 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/chflags/13.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="chflags returns EFAULT if the path argument points outside the process's allocated address space" + +dir=`dirname $0` +. ${dir}/../misc.sh + +require chflags + +echo "1..2" + +expect EFAULT chflags NULL UF_NODUMP +expect EFAULT chflags DEADCODE UF_NODUMP diff --git a/tests/chmod/00.t b/tests/chmod/00.t new file mode 100644 index 000000000000..d68d0cf4e652 --- /dev/null +++ b/tests/chmod/00.t @@ -0,0 +1,138 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/chmod/00.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="chmod changes permission" + +dir=`dirname $0` +. ${dir}/../misc.sh + +if supported lchmod; then + echo "1..203" +else + echo "1..119" +fi + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n2} 0755 +cdir=`pwd` +cd ${n2} + +for type in regular dir fifo block char socket symlink; do + if [ "${type}" != "symlink" ]; then + create_file ${type} ${n0} + expect 0 chmod ${n0} 0111 + expect 0111 stat ${n0} mode + + expect 0 symlink ${n0} ${n1} + mode=`${fstest} lstat ${n1} mode` + expect 0 chmod ${n1} 0222 + expect 0222 stat ${n1} mode + expect 0222 stat ${n0} mode + expect ${mode} lstat ${n1} mode + expect 0 unlink ${n1} + + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n0} + else + expect 0 unlink ${n0} + fi + fi + + if supported lchmod; then + create_file ${type} ${n0} + expect 0 lchmod ${n0} 0111 + expect 0111 lstat ${n0} mode + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n0} + else + expect 0 unlink ${n0} + fi + fi +done + +# successful chmod(2) updates ctime. +for type in regular dir fifo block char socket symlink; do + if [ "${type}" != "symlink" ]; then + create_file ${type} ${n0} + ctime1=`${fstest} stat ${n0} ctime` + sleep 1 + expect 0 chmod ${n0} 0111 + ctime2=`${fstest} stat ${n0} ctime` + test_check $ctime1 -lt $ctime2 + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n0} + else + expect 0 unlink ${n0} + fi + fi + + if supported lchmod; then + create_file ${type} ${n0} + ctime1=`${fstest} lstat ${n0} ctime` + sleep 1 + expect 0 lchmod ${n0} 0111 + ctime2=`${fstest} lstat ${n0} ctime` + test_check $ctime1 -lt $ctime2 + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n0} + else + expect 0 unlink ${n0} + fi + fi +done + +# unsuccessful chmod(2) does not update ctime. +for type in regular dir fifo block char socket symlink; do + if [ "${type}" != "symlink" ]; then + create_file ${type} ${n0} + ctime1=`${fstest} stat ${n0} ctime` + sleep 1 + expect EPERM -u 65534 chmod ${n0} 0111 + ctime2=`${fstest} stat ${n0} ctime` + test_check $ctime1 -eq $ctime2 + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n0} + else + expect 0 unlink ${n0} + fi + fi + + if supported lchmod; then + create_file ${type} ${n0} + ctime1=`${fstest} lstat ${n0} ctime` + sleep 1 + expect EPERM -u 65534 lchmod ${n0} 0321 + ctime2=`${fstest} lstat ${n0} ctime` + test_check $ctime1 -eq $ctime2 + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n0} + else + expect 0 unlink ${n0} + fi + fi +done + +# POSIX: If the calling process does not have appropriate privileges, and if +# the group ID of the file does not match the effective group ID or one of the +# supplementary group IDs and if the file is a regular file, bit S_ISGID +# (set-group-ID on execution) in the file's mode shall be cleared upon +# successful return from chmod(). + +expect 0 create ${n0} 0755 +expect 0 chown ${n0} 65535 65535 +expect 0 -u 65535 -g 65535 chmod ${n0} 02755 +expect 02755 stat ${n0} mode +expect 0 -u 65535 -g 65535 chmod ${n0} 0755 +expect 0755 stat ${n0} mode + +todo FreeBSD "S_ISGID should be removed and chmod(2) should success and FreeBSD returns EPERM." +expect 0 -u 65535 -g 65534 chmod ${n0} 02755 +expect 0755 stat ${n0} mode + +expect 0 unlink ${n0} + +cd ${cdir} +expect 0 rmdir ${n2} diff --git a/tests/chmod/01.t b/tests/chmod/01.t new file mode 100644 index 000000000000..85802fca2439 --- /dev/null +++ b/tests/chmod/01.t @@ -0,0 +1,20 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/chmod/01.t 211474 2010-08-18 22:06:43Z pjd $ + +desc="chmod returns ENOTDIR if a component of the path prefix is not a directory" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..17" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +for type in regular fifo block char socket; do + create_file ${type} ${n0}/${n1} + expect ENOTDIR chmod ${n0}/${n1}/test 0644 + expect 0 unlink ${n0}/${n1} +done +expect 0 rmdir ${n0} diff --git a/tests/chmod/02.t b/tests/chmod/02.t new file mode 100644 index 000000000000..0cadec29bf0c --- /dev/null +++ b/tests/chmod/02.t @@ -0,0 +1,24 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/chmod/02.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="chmod returns ENAMETOOLONG if a component of a pathname exceeded {NAME_MAX} characters" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..10" + +nx=`namegen_max` +nxx="${nx}x" + +expect 0 create ${nx} 0644 +expect 0 chmod ${nx} 0620 +expect 0620 stat ${nx} mode +expect 0 unlink ${nx} +expect ENAMETOOLONG chmod ${nxx} 0620 + +expect 0 create ${nx} 0644 +expect 0 lchmod ${nx} 0620 +expect 0620 stat ${nx} mode +expect 0 unlink ${nx} +expect ENAMETOOLONG lchmod ${nxx} 0620 diff --git a/tests/chmod/03.t b/tests/chmod/03.t new file mode 100644 index 000000000000..fa4580fbcfeb --- /dev/null +++ b/tests/chmod/03.t @@ -0,0 +1,28 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/chmod/03.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="chmod returns ENAMETOOLONG if an entire path name exceeded {PATH_MAX} characters" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..10" + +nx=`dirgen_max` +nxx="${nx}x" + +mkdir -p "${nx%/*}" + +expect 0 create ${nx} 0644 +expect 0 chmod ${nx} 0642 +expect 0642 stat ${nx} mode +expect 0 unlink ${nx} +expect ENAMETOOLONG chmod ${nxx} 0642 + +expect 0 create ${nx} 0644 +expect 0 lchmod ${nx} 0642 +expect 0642 stat ${nx} mode +expect 0 unlink ${nx} +expect ENAMETOOLONG lchmod ${nxx} 0642 + +rm -rf "${nx%%/*}" diff --git a/tests/chmod/04.t b/tests/chmod/04.t new file mode 100644 index 000000000000..9386c9a3e6ba --- /dev/null +++ b/tests/chmod/04.t @@ -0,0 +1,29 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/chmod/04.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="chmod returns ENOENT if the named file does not exist" + +dir=`dirname $0` +. ${dir}/../misc.sh + +if supported lchmod; then + echo "1..9" +else + echo "1..7" +fi + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n0} 0755 +expect ENOENT chmod ${n0}/${n1}/test 0644 +expect ENOENT chmod ${n0}/${n1} 0644 +if supported lchmod; then + expect ENOENT lchmod ${n0}/${n1}/test 0644 + expect ENOENT lchmod ${n0}/${n1} 0644 +fi +expect 0 symlink ${n2} ${n0}/${n1} +expect ENOENT chmod ${n0}/${n1} 0644 +expect 0 unlink ${n0}/${n1} +expect 0 rmdir ${n0} diff --git a/tests/chmod/05.t b/tests/chmod/05.t new file mode 100644 index 000000000000..5648e46eef8b --- /dev/null +++ b/tests/chmod/05.t @@ -0,0 +1,42 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/chmod/05.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="chmod returns EACCES when search permission is denied for a component of the path prefix" + +dir=`dirname $0` +. ${dir}/../misc.sh + +if supported lchmod; then + echo "1..19" +else + echo "1..14" +fi + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n0} 0755 +cdir=`pwd` +cd ${n0} +expect 0 mkdir ${n1} 0755 +expect 0 chown ${n1} 65534 65534 +expect 0 -u 65534 -g 65534 create ${n1}/${n2} 0644 +expect 0 -u 65534 -g 65534 chmod ${n1}/${n2} 0642 +expect 0642 -u 65534 -g 65534 stat ${n1}/${n2} mode +expect 0 chmod ${n1} 0644 +expect EACCES -u 65534 -g 65534 chmod ${n1}/${n2} 0620 +expect 0 chmod ${n1} 0755 +expect 0 -u 65534 -g 65534 chmod ${n1}/${n2} 0420 +expect 0420 -u 65534 -g 65534 stat ${n1}/${n2} mode +if supported lchmod; then + expect 0 chmod ${n1} 0644 + expect EACCES -u 65534 -g 65534 lchmod ${n1}/${n2} 0410 + expect 0 chmod ${n1} 0755 + expect 0 -u 65534 -g 65534 lchmod ${n1}/${n2} 0710 + expect 0710 -u 65534 -g 65534 stat ${n1}/${n2} mode +fi +expect 0 -u 65534 -g 65534 unlink ${n1}/${n2} +expect 0 rmdir ${n1} +cd ${cdir} +expect 0 rmdir ${n0} diff --git a/tests/chmod/06.t b/tests/chmod/06.t new file mode 100644 index 000000000000..d44b3cb1ea52 --- /dev/null +++ b/tests/chmod/06.t @@ -0,0 +1,29 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/chmod/06.t 211474 2010-08-18 22:06:43Z pjd $ + +desc="chmod returns ELOOP if too many symbolic links were encountered in translating the pathname" + +dir=`dirname $0` +. ${dir}/../misc.sh + +if supported lchmod; then + echo "1..10" +else + echo "1..8" +fi + +n0=`namegen` +n1=`namegen` + +expect 0 symlink ${n0} ${n1} +expect 0 symlink ${n1} ${n0} +expect ELOOP chmod ${n0} 0644 +expect ELOOP chmod ${n1} 0644 +expect ELOOP chmod ${n0}/test 0644 +expect ELOOP chmod ${n1}/test 0644 +if supported lchmod; then + expect ELOOP lchmod ${n0}/test 0644 + expect ELOOP lchmod ${n1}/test 0644 +fi +expect 0 unlink ${n0} +expect 0 unlink ${n1} diff --git a/tests/chmod/07.t b/tests/chmod/07.t new file mode 100644 index 000000000000..012e59a97bb5 --- /dev/null +++ b/tests/chmod/07.t @@ -0,0 +1,62 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/chmod/07.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="chmod returns EPERM if the operation would change the ownership, but the effective user ID is not the super-user" + +dir=`dirname $0` +. ${dir}/../misc.sh + +if supported lchmod; then + echo "1..34" +else + echo "1..25" +fi + +n0=`namegen` +n1=`namegen` +n2=`namegen` +n3=`namegen` + +expect 0 mkdir ${n0} 0755 +cdir=`pwd` +cd ${n0} +expect 0 mkdir ${n1} 0755 +expect 0 chown ${n1} 65534 65534 + +expect 0 -u 65534 -g 65534 create ${n1}/${n2} 0644 +expect 0 -u 65534 -g 65534 chmod ${n1}/${n2} 0642 +expect 0642 stat ${n1}/${n2} mode +expect EPERM -u 65533 -g 65533 chmod ${n1}/${n2} 0641 +expect 0642 stat ${n1}/${n2} mode +expect 0 chown ${n1}/${n2} 0 0 +expect EPERM -u 65534 -g 65534 chmod ${n1}/${n2} 0641 +expect 0642 stat ${n1}/${n2} mode +expect 0 unlink ${n1}/${n2} + +expect 0 -u 65534 -g 65534 create ${n1}/${n2} 0644 +expect 0 -u 65534 -g 65534 symlink ${n2} ${n1}/${n3} +expect 0 -u 65534 -g 65534 chmod ${n1}/${n3} 0642 +expect 0642,65534,65534 stat ${n1}/${n2} mode,uid,gid +expect EPERM -u 65533 -g 65533 chmod ${n1}/${n3} 0641 +expect 0642,65534,65534 stat ${n1}/${n2} mode,uid,gid +expect 0 chown ${n1}/${n3} 0 0 +expect EPERM -u 65534 -g 65534 chmod ${n1}/${n3} 0641 +expect 0642,0,0 stat ${n1}/${n2} mode,uid,gid +expect 0 unlink ${n1}/${n2} +expect 0 unlink ${n1}/${n3} + +if supported lchmod; then + expect 0 -u 65534 -g 65534 create ${n1}/${n2} 0644 + expect 0 -u 65534 -g 65534 lchmod ${n1}/${n2} 0642 + expect 0642 stat ${n1}/${n2} mode + expect EPERM -u 65533 -g 65533 lchmod ${n1}/${n2} 0641 + expect 0642 stat ${n1}/${n2} mode + expect 0 chown ${n1}/${n2} 0 0 + expect EPERM -u 65534 -g 65534 lchmod ${n1}/${n2} 0641 + expect 0642 stat ${n1}/${n2} mode + expect 0 unlink ${n1}/${n2} +fi + +expect 0 rmdir ${n1} +cd ${cdir} +expect 0 rmdir ${n0} diff --git a/tests/chmod/08.t b/tests/chmod/08.t new file mode 100644 index 000000000000..5b37569a82d7 --- /dev/null +++ b/tests/chmod/08.t @@ -0,0 +1,98 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/chmod/08.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="chmod returns EPERM if the named file has its immutable or append-only flag set" + +dir=`dirname $0` +. ${dir}/../misc.sh + +require chflags + +case "${os}:${fs}" in +FreeBSD:ZFS) + echo "1..29" + ;; +FreeBSD:UFS) + echo "1..54" + ;; +*) + quick_exit +esac + +n0=`namegen` + +expect 0 create ${n0} 0644 +expect 0 chflags ${n0} SF_IMMUTABLE +expect EPERM chmod ${n0} 0600 +supported lchmod && expect EPERM lchmod ${n0} 0600 +expect 0644 stat ${n0} mode +expect 0 chflags ${n0} none +expect 0 chmod ${n0} 0600 +expect 0600 stat ${n0} mode +supported lchmod && expect 0 lchmod ${n0} 0400 +supported lchmod && expect 0400 stat ${n0} mode +expect 0 unlink ${n0} + +expect 0 create ${n0} 0644 +expect 0 chflags ${n0} SF_NOUNLINK +expect 0 chmod ${n0} 0600 +expect 0600 stat ${n0} mode +supported lchmod && expect 0 lchmod ${n0} 0400 +supported lchmod && expect 0400 stat ${n0} mode +expect 0 chflags ${n0} none +expect 0 unlink ${n0} + +case "${os}:${fs}" in +FreeBSD:ZFS) + expect 0 create ${n0} 0644 + expect 0 chflags ${n0} SF_APPEND + expect 0 chmod ${n0} 0600 + expect 0600 stat ${n0} mode + supported lchmod && expect 0 lchmod ${n0} 0500 + supported lchmod && expect 0500 stat ${n0} mode + expect 0 chflags ${n0} none + expect 0 chmod ${n0} 0400 + expect 0400 stat ${n0} mode + expect 0 unlink ${n0} + ;; +FreeBSD:UFS) + expect 0 create ${n0} 0644 + expect 0 chflags ${n0} SF_APPEND + expect EPERM chmod ${n0} 0600 + supported lchmod && expect EPERM lchmod ${n0} 0600 + expect 0644 stat ${n0} mode + expect 0 chflags ${n0} none + expect 0 chmod ${n0} 0600 + expect 0600 stat ${n0} mode + expect 0 unlink ${n0} + + expect 0 create ${n0} 0644 + expect 0 chflags ${n0} UF_IMMUTABLE + expect EPERM chmod ${n0} 0600 + supported lchmod && expect EPERM lchmod ${n0} 0600 + expect 0644 stat ${n0} mode + expect 0 chflags ${n0} none + expect 0 chmod ${n0} 0600 + expect 0600 stat ${n0} mode + expect 0 unlink ${n0} + + expect 0 create ${n0} 0644 + expect 0 chflags ${n0} UF_NOUNLINK + expect 0 chmod ${n0} 0600 + expect 0600 stat ${n0} mode + supported lchmod && expect 0 lchmod ${n0} 0400 + supported lchmod && expect 0400 stat ${n0} mode + expect 0 chflags ${n0} none + expect 0 unlink ${n0} + + expect 0 create ${n0} 0644 + expect 0 chflags ${n0} UF_APPEND + expect EPERM chmod ${n0} 0600 + supported lchmod && expect EPERM lchmod ${n0} 0600 + expect 0644 stat ${n0} mode + expect 0 chflags ${n0} none + expect 0 chmod ${n0} 0600 + expect 0600 stat ${n0} mode + expect 0 unlink ${n0} + ;; +esac diff --git a/tests/chmod/09.t b/tests/chmod/09.t new file mode 100644 index 000000000000..c62b908f5802 --- /dev/null +++ b/tests/chmod/09.t @@ -0,0 +1,37 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/chmod/09.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="chmod returns EROFS if the named file resides on a read-only file system" + +dir=`dirname $0` +. ${dir}/../misc.sh + +[ "${os}:${fs}" = "FreeBSD:UFS" ] || quick_exit + +echo "1..15" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +n=`mdconfig -a -n -t malloc -s 1m` +newfs /dev/md${n} >/dev/null +mount /dev/md${n} ${n0} +expect 0 create ${n0}/${n1} 0644 +expect 0 chmod ${n0}/${n1} 0640 +expect 0640 stat ${n0}/${n1} mode +expect 0 lchmod ${n0}/${n1} 0530 +expect 0530 stat ${n0}/${n1} mode +mount -ur /dev/md${n} +expect EROFS chmod ${n0}/${n1} 0600 +expect EROFS lchmod ${n0}/${n1} 0600 +expect 0530 stat ${n0}/${n1} mode +mount -uw /dev/md${n} +expect 0 chmod ${n0}/${n1} 0600 +expect 0600 stat ${n0}/${n1} mode +expect 0 lchmod ${n0}/${n1} 0640 +expect 0640 stat ${n0}/${n1} mode +expect 0 unlink ${n0}/${n1} +umount /dev/md${n} +mdconfig -d -u ${n} +expect 0 rmdir ${n0} diff --git a/tests/chmod/10.t b/tests/chmod/10.t new file mode 100644 index 000000000000..1153429ac1dc --- /dev/null +++ b/tests/chmod/10.t @@ -0,0 +1,20 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/chmod/10.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="chmod returns EFAULT if the path argument points outside the process's allocated address space" + +dir=`dirname $0` +. ${dir}/../misc.sh + +if supported lchmod; then + echo "1..4" +else + echo "1..2" +fi + +expect EFAULT chmod NULL 0644 +expect EFAULT chmod DEADCODE 0644 +if supported lchmod; then + expect EFAULT lchmod NULL 0644 + expect EFAULT lchmod DEADCODE 0644 +fi diff --git a/tests/chmod/11.t b/tests/chmod/11.t new file mode 100644 index 000000000000..94c5e5f4f319 --- /dev/null +++ b/tests/chmod/11.t @@ -0,0 +1,118 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/chmod/11.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="chmod returns EFTYPE if the effective user ID is not the super-user, the mode includes the sticky bit (S_ISVTX), and path does not refer to a directory" + +dir=`dirname $0` +. ${dir}/../misc.sh + +if supported lchmod; then + echo "1..173" +else + echo "1..109" +fi + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n0} 0755 +cdir=`pwd` +cd ${n0} + +for type in regular dir fifo block char socket symlink; do + if [ "${type}" != "symlink" ]; then + create_file ${type} ${n1} + expect 0 chmod ${n1} 01621 + expect 01621 stat ${n1} mode + expect 0 symlink ${n1} ${n2} + expect 0 chmod ${n2} 01700 + expect 01700 stat ${n1} mode + expect 0 unlink ${n2} + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n1} + else + expect 0 unlink ${n1} + fi + fi + + if supported lchmod; then + create_file ${type} ${n1} + expect 0 lchmod ${n1} 01621 + expect 01621 lstat ${n1} mode + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n1} + else + expect 0 unlink ${n1} + fi + fi +done + +expect 0 mkdir ${n1} 0755 +expect 0 chown ${n1} 65534 65534 +expect 0 -u 65534 -g 65534 chmod ${n1} 01755 +expect 01755 stat ${n1} mode +expect 0 symlink ${n1} ${n2} +expect 0 chmod ${n2} 01700 +expect 01700 stat ${n1} mode +expect 0 unlink ${n2} +expect 0 rmdir ${n1} + +for type in regular fifo block char socket symlink; do + if [ "${type}" != "symlink" ]; then + create_file ${type} ${n1} 0640 65534 65534 + expect 0 symlink ${n1} ${n2} + case "${os}" in + FreeBSD) + expect EFTYPE -u 65534 -g 65534 chmod ${n1} 01644 + expect 0640 stat ${n1} mode + expect EFTYPE -u 65534 -g 65534 chmod ${n2} 01644 + expect 0640 stat ${n1} mode + ;; + SunOS) + expect 0 -u 65534 -g 65534 chmod ${n1} 01644 + expect 0644 stat ${n1} mode + expect 0 -u 65534 -g 65534 chmod ${n2} 01640 + expect 0640 stat ${n1} mode + ;; + Linux) + expect 0 -u 65534 -g 65534 chmod ${n1} 01644 + expect 01644 stat ${n1} mode + expect 0 -u 65534 -g 65534 chmod ${n2} 01640 + expect 01640 stat ${n1} mode + ;; + esac + expect 0 unlink ${n2} + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n1} + else + expect 0 unlink ${n1} + fi + fi + + if supported lchmod; then + create_file ${type} ${n1} 0640 65534 65534 + case "${os}" in + FreeBSD) + expect EFTYPE -u 65534 -g 65534 lchmod ${n1} 01644 + expect 0640 lstat ${n1} mode + ;; + SunOS) + expect 0 -u 65534 -g 65534 lchmod ${n1} 01644 + expect 0644 lstat ${n1} mode + ;; + Linux) + expect 0 -u 65534 -g 65534 lchmod ${n1} 01644 + expect 01644 lstat ${n1} mode + ;; + esac + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n1} + else + expect 0 unlink ${n1} + fi + fi +done + +cd ${cdir} +expect 0 rmdir ${n0} diff --git a/tests/chmod/12.t b/tests/chmod/12.t new file mode 100644 index 000000000000..b7f7d67997fb --- /dev/null +++ b/tests/chmod/12.t @@ -0,0 +1,38 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/chmod/12.t 219463 2011-03-10 20:59:02Z pjd $ + +desc="verify SUID/SGID bit behaviour" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..14" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n2} 0755 +cdir=`pwd` +cd ${n2} + +# Check whether writing to the file by non-owner clears the SUID. +expect 0 create ${n0} 04777 +expect 0777 -u 65534 -g 65534 open ${n0} O_WRONLY : write 0 x : fstat 0 mode +expect 0777 stat ${n0} mode +expect 0 unlink ${n0} + +# Check whether writing to the file by non-owner clears the SGID. +expect 0 create ${n0} 02777 +expect 0777 -u 65534 -g 65534 open ${n0} O_RDWR : write 0 x : fstat 0 mode +expect 0777 stat ${n0} mode +expect 0 unlink ${n0} + +# Check whether writing to the file by non-owner clears the SUID+SGID. +expect 0 create ${n0} 06777 +expect 0777 -u 65534 -g 65534 open ${n0} O_RDWR : write 0 x : fstat 0 mode +expect 0777 stat ${n0} mode +expect 0 unlink ${n0} + +cd ${cdir} +expect 0 rmdir ${n2} diff --git a/tests/chmod/foo b/tests/chmod/foo new file mode 100755 index 000000000000..e69de29bb2d1 diff --git a/tests/chown/00.t b/tests/chown/00.t new file mode 100644 index 000000000000..5c6be97d66dd --- /dev/null +++ b/tests/chown/00.t @@ -0,0 +1,458 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/chown/00.t 228975 2011-12-30 00:04:11Z uqs $ + +desc="chown changes ownership" + +dir=`dirname $0` +. ${dir}/../misc.sh + +if supported lchmod; then + echo "1..1349" +else + echo "1..1323" +fi + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n2} 0755 +cdir=`pwd` +cd ${n2} + +# super-user can always modify ownership +for type in regular dir fifo block char socket symlink; do + if [ "${type}" != "symlink" ]; then + create_file ${type} ${n0} + + expect 0 chown ${n0} 123 456 + expect 123,456 lstat ${n0} uid,gid + expect 0 chown ${n0} 0 0 + expect 0,0 lstat ${n0} uid,gid + + expect 0 symlink ${n0} ${n1} + uidgid=`${fstest} lstat ${n1} uid,gid` + expect 0 chown ${n1} 123 456 + expect 123,456 stat ${n1} uid,gid + expect 123,456 stat ${n0} uid,gid + expect ${uidgid} lstat ${n1} uid,gid + expect 0 unlink ${n1} + + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n0} + else + expect 0 unlink ${n0} + fi + fi + + create_file ${type} ${n0} + expect 0 lchown ${n0} 123 456 + expect 123,456 lstat ${n0} uid,gid + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n0} + else + expect 0 unlink ${n0} + fi +done + +# non-super-user can modify file group if he is owner of a file and +# gid he is setting is in his groups list. +for type in regular dir fifo block char socket symlink; do + if [ "${type}" != "symlink" ]; then + create_file ${type} ${n0} + + expect 0 chown ${n0} 65534 65533 + expect 65534,65533 lstat ${n0} uid,gid + expect 0 -u 65534 -g 65532,65531 -- chown ${n0} -1 65532 + expect 65534,65532 lstat ${n0} uid,gid + expect 0 -u 65534 -g 65532,65531 chown ${n0} 65534 65531 + expect 65534,65531 lstat ${n0} uid,gid + + expect 0 symlink ${n0} ${n1} + uidgid=`${fstest} lstat ${n1} uid,gid` + expect 0 chown ${n1} 65534 65533 + expect 65534,65533 stat ${n0} uid,gid + expect 65534,65533 stat ${n1} uid,gid + expect ${uidgid} lstat ${n1} uid,gid + expect 0 -u 65534 -g 65532,65531 -- chown ${n1} -1 65532 + expect 65534,65532 stat ${n0} uid,gid + expect 65534,65532 stat ${n1} uid,gid + expect ${uidgid} lstat ${n1} uid,gid + expect 0 -u 65534 -g 65532,65531 chown ${n1} 65534 65531 + expect 65534,65531 stat ${n0} uid,gid + expect 65534,65531 stat ${n1} uid,gid + expect ${uidgid} lstat ${n1} uid,gid + expect 0 unlink ${n1} + + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n0} + else + expect 0 unlink ${n0} + fi + fi + + create_file ${type} ${n0} + expect 0 lchown ${n0} 65534 65533 + expect 65534,65533 lstat ${n0} uid,gid + expect 0 -u 65534 -g 65532,65531 -- lchown ${n0} -1 65532 + expect 65534,65532 lstat ${n0} uid,gid + expect 0 -u 65534 -g 65532,65531 lchown ${n0} 65534 65531 + expect 65534,65531 lstat ${n0} uid,gid + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n0} + else + expect 0 unlink ${n0} + fi +done + +# chown(2) return 0 if user is not owner of a file, but chown(2) is called +# with both uid and gid equal to -1. +for type in regular dir fifo block char socket symlink; do + if [ "${type}" != "symlink" ]; then + create_file ${type} ${n0} + + expect 0 chown ${n0} 65534 65533 + expect 0 -u 65532 -g 65531 -- chown ${n0} -1 -1 + expect 65534,65533 stat ${n0} uid,gid + + expect 0 symlink ${n0} ${n1} + uidgid=`${fstest} lstat ${n1} uid,gid` + expect 0 chown ${n1} 65534 65533 + expect 65534,65533 stat ${n0} uid,gid + expect 65534,65533 stat ${n1} uid,gid + expect ${uidgid} lstat ${n1} uid,gid + expect 0 -u 65532 -g 65531 -- chown ${n0} -1 -1 + expect 65534,65533 stat ${n0} uid,gid + expect 65534,65533 stat ${n1} uid,gid + expect ${uidgid} lstat ${n1} uid,gid + expect 0 unlink ${n1} + + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n0} + else + expect 0 unlink ${n0} + fi + fi + + create_file ${type} ${n0} + expect 0 lchown ${n0} 65534 65533 + expect 0 -u 65532 -g 65531 -- lchown ${n0} -1 -1 + expect 65534,65533 lstat ${n0} uid,gid + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n0} + else + expect 0 unlink ${n0} + fi +done + +# when super-user calls chown(2), set-uid and set-gid bits may be removed. +for type in regular dir fifo block char socket symlink; do + if [ "${type}" != "symlink" ]; then + create_file ${type} ${n0} + + expect 0 chown ${n0} 65534 65533 + expect 0 chmod ${n0} 06555 + expect 06555,65534,65533 stat ${n0} mode,uid,gid + expect 0 chown ${n0} 65532 65531 + expect "(06555|0555),65532,65531" stat ${n0} mode,uid,gid + expect 0 chmod ${n0} 06555 + expect 06555,65532,65531 stat ${n0} mode,uid,gid + expect 0 chown ${n0} 0 0 + expect "(06555|0555),0,0" stat ${n0} mode,uid,gid + + expect 0 symlink ${n0} ${n1} + expect 0 chown ${n1} 65534 65533 + expect 0 chmod ${n1} 06555 + expect 06555,65534,65533 stat ${n0} mode,uid,gid + expect 06555,65534,65533 stat ${n1} mode,uid,gid + expect 0 chown ${n1} 65532 65531 + expect "(06555|0555),65532,65531" stat ${n0} mode,uid,gid + expect "(06555|0555),65532,65531" stat ${n1} mode,uid,gid + expect 0 chmod ${n1} 06555 + expect 06555,65532,65531 stat ${n0} mode,uid,gid + expect 06555,65532,65531 stat ${n1} mode,uid,gid + expect 0 chown ${n1} 0 0 + expect "(06555|0555),0,0" stat ${n0} mode,uid,gid + expect "(06555|0555),0,0" stat ${n1} mode,uid,gid + expect 0 unlink ${n1} + + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n0} + else + expect 0 unlink ${n0} + fi + fi + + if [ "${type}" != "symlink" ] || supported lchmod; then + create_file ${type} ${n0} + expect 0 lchown ${n0} 65534 65533 + if supported lchmod; then + expect 0 lchmod ${n0} 06555 + else + expect 0 chmod ${n0} 06555 + fi + expect 06555,65534,65533 lstat ${n0} mode,uid,gid + expect 0 lchown ${n0} 65532 65531 + expect "(06555|0555),65532,65531" lstat ${n0} mode,uid,gid + if supported lchmod; then + expect 0 lchmod ${n0} 06555 + else + expect 0 chmod ${n0} 06555 + fi + expect 06555,65532,65531 lstat ${n0} mode,uid,gid + expect 0 lchown ${n0} 0 0 + expect "(06555|0555),0,0" lstat ${n0} mode,uid,gid + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n0} + else + expect 0 unlink ${n0} + fi + fi +done + +# when non-super-user calls chown(2) successfully, set-uid and set-gid bits may +# be removed, except when both uid and gid are equal to -1. +for type in regular dir fifo block char socket symlink; do + if [ "${type}" != "symlink" ]; then + create_file ${type} ${n0} + + expect 0 chown ${n0} 65534 65533 + expect 0 chmod ${n0} 06555 + expect 06555,65534,65533 stat ${n0} mode,uid,gid + expect 0 -u 65534 -g 65533,65532 chown ${n0} 65534 65532 + expect 0555,65534,65532 stat ${n0} mode,uid,gid + expect 0 chmod ${n0} 06555 + expect 06555,65534,65532 stat ${n0} mode,uid,gid + expect 0 -u 65534 -g 65533,65532 -- chown ${n0} -1 65533 + expect 0555,65534,65533 stat ${n0} mode,uid,gid + expect 0 chmod ${n0} 06555 + expect 06555,65534,65533 stat ${n0} mode,uid,gid + expect 0 -u 65534 -g 65533,65532 -- chown ${n0} -1 -1 + expect "(06555|0555),65534,65533" stat ${n0} mode,uid,gid + + expect 0 symlink ${n0} ${n1} + expect 0 chown ${n1} 65534 65533 + expect 0 chmod ${n1} 06555 + expect 06555,65534,65533 stat ${n0} mode,uid,gid + expect 06555,65534,65533 stat ${n1} mode,uid,gid + expect 0 -u 65534 -g 65533,65532 chown ${n1} 65534 65532 + expect 0555,65534,65532 stat ${n0} mode,uid,gid + expect 0555,65534,65532 stat ${n1} mode,uid,gid + expect 0 chmod ${n1} 06555 + expect 06555,65534,65532 stat ${n0} mode,uid,gid + expect 06555,65534,65532 stat ${n1} mode,uid,gid + expect 0 -u 65534 -g 65533,65532 -- chown ${n1} -1 65533 + expect 0555,65534,65533 stat ${n0} mode,uid,gid + expect 0555,65534,65533 stat ${n1} mode,uid,gid + expect 0 chmod ${n1} 06555 + expect 06555,65534,65533 stat ${n0} mode,uid,gid + expect 06555,65534,65533 stat ${n1} mode,uid,gid + expect 0 -u 65534 -g 65533,65532 -- chown ${n1} -1 -1 + expect "(06555|0555),65534,65533" stat ${n0} mode,uid,gid + expect "(06555|0555),65534,65533" stat ${n1} mode,uid,gid + expect 0 unlink ${n1} + + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n0} + else + expect 0 unlink ${n0} + fi + fi + + if [ "${type}" != "symlink" ] || supported lchmod; then + create_file ${type} ${n0} + + expect 0 lchown ${n0} 65534 65533 + if supported lchmod; then + expect 0 lchmod ${n0} 06555 + else + expect 0 chmod ${n0} 06555 + fi + expect 06555,65534,65533 lstat ${n0} mode,uid,gid + expect 0 -u 65534 -g 65533,65532 lchown ${n0} 65534 65532 + expect 0555,65534,65532 lstat ${n0} mode,uid,gid + if supported lchmod; then + expect 0 lchmod ${n0} 06555 + else + expect 0 chmod ${n0} 06555 + fi + expect 06555,65534,65532 lstat ${n0} mode,uid,gid + expect 0 -u 65534 -g 65533,65532 -- lchown ${n0} -1 65533 + expect 0555,65534,65533 lstat ${n0} mode,uid,gid + if supported lchmod; then + expect 0 lchmod ${n0} 06555 + else + expect 0 chmod ${n0} 06555 + fi + expect 06555,65534,65533 lstat ${n0} mode,uid,gid + expect 0 -u 65534 -g 65533,65532 -- lchown ${n0} -1 -1 + expect "(06555|0555),65534,65533" lstat ${n0} mode,uid,gid + + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n0} + else + expect 0 unlink ${n0} + fi + fi +done + +# successful chown(2) call (except uid and gid equal to -1) updates ctime. +for type in regular dir fifo block char socket symlink; do + if [ "${type}" != "symlink" ]; then + create_file ${type} ${n0} + + ctime1=`${fstest} stat ${n0} ctime` + sleep 1 + expect 0 chown ${n0} 65534 65533 + expect 65534,65533 stat ${n0} uid,gid + ctime2=`${fstest} stat ${n0} ctime` + test_check $ctime1 -lt $ctime2 + ctime1=`${fstest} stat ${n0} ctime` + sleep 1 + expect 0 -u 65534 -g 65532 chown ${n0} 65534 65532 + expect 65534,65532 stat ${n0} uid,gid + ctime2=`${fstest} stat ${n0} ctime` + test_check $ctime1 -lt $ctime2 + + expect 0 symlink ${n0} ${n1} + ctime1=`${fstest} stat ${n1} ctime` + sleep 1 + expect 0 chown ${n1} 65533 65532 + expect 65533,65532 stat ${n1} uid,gid + ctime2=`${fstest} stat ${n1} ctime` + test_check $ctime1 -lt $ctime2 + ctime1=`${fstest} stat ${n1} ctime` + sleep 1 + expect 0 -u 65533 -g 65531 chown ${n1} 65533 65531 + expect 65533,65531 stat ${n1} uid,gid + ctime2=`${fstest} stat ${n1} ctime` + test_check $ctime1 -lt $ctime2 + expect 0 unlink ${n1} + + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n0} + else + expect 0 unlink ${n0} + fi + fi + + create_file ${type} ${n0} + + ctime1=`${fstest} lstat ${n0} ctime` + sleep 1 + expect 0 lchown ${n0} 65534 65533 + expect 65534,65533 lstat ${n0} uid,gid + ctime2=`${fstest} lstat ${n0} ctime` + test_check $ctime1 -lt $ctime2 + ctime1=`${fstest} lstat ${n0} ctime` + sleep 1 + expect 0 -u 65534 -g 65532 lchown ${n0} 65534 65532 + expect 65534,65532 lstat ${n0} uid,gid + ctime2=`${fstest} lstat ${n0} ctime` + test_check $ctime1 -lt $ctime2 + + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n0} + else + expect 0 unlink ${n0} + fi +done + +for type in regular dir fifo block char socket symlink; do + if [ "${type}" != "symlink" ]; then + create_file ${type} ${n0} + + ctime1=`${fstest} stat ${n0} ctime` + sleep 1 + expect 0 -- chown ${n0} -1 -1 + ctime2=`${fstest} stat ${n0} ctime` + todo Linux "According to POSIX: If both owner and group are -1, the times need not be updated." + test_check $ctime1 -eq $ctime2 + expect 0,0 stat ${n0} uid,gid + + expect 0 symlink ${n0} ${n1} + ctime1=`${fstest} stat ${n1} ctime` + sleep 1 + expect 0 -- chown ${n1} -1 -1 + ctime2=`${fstest} stat ${n1} ctime` + todo Linux "According to POSIX: If both owner and group are -1, the times need not be updated." + test_check $ctime1 -eq $ctime2 + expect 0,0 stat ${n1} uid,gid + expect 0 unlink ${n1} + + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n0} + else + expect 0 unlink ${n0} + fi + fi + + create_file ${type} ${n0} + + ctime1=`${fstest} lstat ${n0} ctime` + sleep 1 + expect 0 -- lchown ${n0} -1 -1 + ctime2=`${fstest} lstat ${n0} ctime` + todo Linux "According to POSIX: If both owner and group are -1, the times need not be updated." + test_check $ctime1 -eq $ctime2 + expect 0,0 lstat ${n0} uid,gid + + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n0} + else + expect 0 unlink ${n0} + fi +done + +# unsuccessful chown(2) does not update ctime. +for type in regular dir fifo block char socket symlink; do + if [ "${type}" != "symlink" ]; then + create_file ${type} ${n0} + + ctime1=`${fstest} stat ${n0} ctime` + sleep 1 + expect EPERM -u 65534 -- chown ${n0} 65534 -1 + expect EPERM -u 65534 -g 65534 -- chown ${n0} -1 65534 + expect EPERM -u 65534 -g 65534 chown ${n0} 65534 65534 + ctime2=`${fstest} stat ${n0} ctime` + test_check $ctime1 -eq $ctime2 + expect 0,0 stat ${n0} uid,gid + + expect 0 symlink ${n0} ${n1} + ctime1=`${fstest} stat ${n1} ctime` + sleep 1 + expect EPERM -u 65534 -- chown ${n1} 65534 -1 + expect EPERM -u 65534 -g 65534 -- chown ${n1} -1 65534 + expect EPERM -u 65534 -g 65534 chown ${n1} 65534 65534 + ctime2=`${fstest} stat ${n1} ctime` + test_check $ctime1 -eq $ctime2 + expect 0,0 stat ${n1} uid,gid + expect 0 unlink ${n1} + + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n0} + else + expect 0 unlink ${n0} + fi + fi + + create_file ${type} ${n0} + + ctime1=`${fstest} lstat ${n0} ctime` + sleep 1 + expect EPERM -u 65534 -- lchown ${n0} 65534 -1 + expect EPERM -u 65534 -g 65534 -- lchown ${n0} -1 65534 + expect EPERM -u 65534 -g 65534 lchown ${n0} 65534 65534 + ctime2=`${fstest} lstat ${n0} ctime` + test_check $ctime1 -eq $ctime2 + expect 0,0 lstat ${n0} uid,gid + + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n0} + else + expect 0 unlink ${n0} + fi +done + +cd ${cdir} +expect 0 rmdir ${n2} diff --git a/tests/chown/01.t b/tests/chown/01.t new file mode 100644 index 000000000000..1813394aee83 --- /dev/null +++ b/tests/chown/01.t @@ -0,0 +1,21 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/chown/01.t 211474 2010-08-18 22:06:43Z pjd $ + +desc="chown returns ENOTDIR if a component of the path prefix is not a directory" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..22" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +for type in regular fifo block char socket; do + create_file ${type} ${n0}/${n1} + expect ENOTDIR chown ${n0}/${n1}/test 65534 65534 + expect ENOTDIR lchown ${n0}/${n1}/test 65534 65534 + expect 0 unlink ${n0}/${n1} +done +expect 0 rmdir ${n0} diff --git a/tests/chown/02.t b/tests/chown/02.t new file mode 100644 index 000000000000..e110db8261ba --- /dev/null +++ b/tests/chown/02.t @@ -0,0 +1,24 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/chown/02.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="chown returns ENAMETOOLONG if a component of a pathname exceeded ${NAME_MAX} characters" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..10" + +nx=`namegen_max` +nxx="${nx}x" + +expect 0 create ${nx} 0644 +expect 0 chown ${nx} 65534 65534 +expect 65534,65534 stat ${nx} uid,gid +expect 0 unlink ${nx} +expect ENAMETOOLONG chown ${nxx} 65534 65534 + +expect 0 create ${nx} 0644 +expect 0 lchown ${nx} 65534 65534 +expect 65534,65534 stat ${nx} uid,gid +expect 0 unlink ${nx} +expect ENAMETOOLONG lchown ${nxx} 65534 65534 diff --git a/tests/chown/03.t b/tests/chown/03.t new file mode 100644 index 000000000000..031a878f3524 --- /dev/null +++ b/tests/chown/03.t @@ -0,0 +1,28 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/chown/03.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="chown returns ENAMETOOLONG if an entire path name exceeded {PATH_MAX} characters" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..10" + +nx=`dirgen_max` +nxx="${nx}x" + +mkdir -p "${nx%/*}" + +expect 0 create ${nx} 0644 +expect 0 chown ${nx} 65534 65534 +expect 65534,65534 stat ${nx} uid,gid +expect 0 unlink ${nx} +expect ENAMETOOLONG chown ${nxx} 65534 65534 + +expect 0 create ${nx} 0644 +expect 0 lchown ${nx} 65534 65534 +expect 65534,65534 stat ${nx} uid,gid +expect 0 unlink ${nx} +expect ENAMETOOLONG lchown ${nxx} 65534 65534 + +rm -rf "${nx%%/*}" diff --git a/tests/chown/04.t b/tests/chown/04.t new file mode 100644 index 000000000000..d6eac198ed1e --- /dev/null +++ b/tests/chown/04.t @@ -0,0 +1,23 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/chown/04.t 211410 2010-08-17 06:08:09Z pjd $ + +desc="chown returns ENOENT if the named file does not exist" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..9" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n0} 0755 +expect ENOENT chown ${n0}/${n1}/test 65534 65534 +expect ENOENT chown ${n0}/${n1} 65534 65534 +expect ENOENT lchown ${n0}/${n1}/test 65534 65534 +expect ENOENT lchown ${n0}/${n1} 65534 65534 +expect 0 symlink ${n2} ${n0}/${n1} +expect ENOENT chown ${n0}/${n1} 65534 65534 +expect 0 unlink ${n0}/${n1} +expect 0 rmdir ${n0} diff --git a/tests/chown/05.t b/tests/chown/05.t new file mode 100644 index 000000000000..5a27a9ca90fc --- /dev/null +++ b/tests/chown/05.t @@ -0,0 +1,35 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/chown/05.t 211410 2010-08-17 06:08:09Z pjd $ + +desc="chown returns EACCES when search permission is denied for a component of the path prefix" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..18" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n0} 0755 +cdir=`pwd` +cd ${n0} +expect 0 mkdir ${n1} 0755 +expect 0 chown ${n1} 65534 65534 +expect 0 -u 65534 -g 65534 create ${n1}/${n2} 0644 +expect 0 -u 65534 -g 65533,65534 -- chown ${n1}/${n2} -1 65533 +expect 65534,65533 -u 65534 -g 65534 stat ${n1}/${n2} uid,gid +expect 0 chmod ${n1} 0644 +expect EACCES -u 65534 -g 65533,65534 -- chown ${n1}/${n2} -1 65534 +expect EACCES -u 65534 -g 65533,65534 -- lchown ${n1}/${n2} -1 65534 +expect 0 chmod ${n1} 0755 +expect 65534,65533 -u 65534 -g 65534 stat ${n1}/${n2} uid,gid +expect 0 -u 65534 -g 65533,65534 -- chown ${n1}/${n2} -1 65534 +expect 65534,65534 -u 65534 -g 65534 stat ${n1}/${n2} uid,gid +expect 0 -u 65534 -g 65533,65534 -- lchown ${n1}/${n2} -1 65533 +expect 65534,65533 -u 65534 -g 65533 stat ${n1}/${n2} uid,gid +expect 0 unlink ${n1}/${n2} +expect 0 rmdir ${n1} +cd ${cdir} +expect 0 rmdir ${n0} diff --git a/tests/chown/06.t b/tests/chown/06.t new file mode 100644 index 000000000000..a7ac349c02f8 --- /dev/null +++ b/tests/chown/06.t @@ -0,0 +1,23 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/chown/06.t 211410 2010-08-17 06:08:09Z pjd $ + +desc="chown returns ELOOP if too many symbolic links were encountered in translating the pathname" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..10" + +n0=`namegen` +n1=`namegen` + +expect 0 symlink ${n0} ${n1} +expect 0 symlink ${n1} ${n0} +expect ELOOP chown ${n0} 65534 65534 +expect ELOOP chown ${n1} 65534 65534 +expect ELOOP chown ${n0}/test 65534 65534 +expect ELOOP chown ${n1}/test 65534 65534 +expect ELOOP lchown ${n0}/test 65534 65534 +expect ELOOP lchown ${n1}/test 65534 65534 +expect 0 unlink ${n0} +expect 0 unlink ${n1} diff --git a/tests/chown/07.t b/tests/chown/07.t new file mode 100644 index 000000000000..f188080d05ec --- /dev/null +++ b/tests/chown/07.t @@ -0,0 +1,53 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/chown/07.t 211410 2010-08-17 06:08:09Z pjd $ + +desc="chown returns EPERM if the operation would change the ownership, but the effective user ID is not the super-user and the process is not an owner of the file" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..132" + +n0=`namegen` +n1=`namegen` +n2=`namegen` +n3=`namegen` + +expect 0 mkdir ${n0} 0755 +cdir=`pwd` +cd ${n0} +expect 0 mkdir ${n1} 0755 +expect 0 chown ${n1} 65534 65534 +for type in regular dir fifo block char socket symlink; do + if [ "${type}" != "symlink" ]; then + create_file ${type} ${n1}/${n2} 65534 65534 + expect EPERM -u 65534 -g 65534 chown ${n1}/${n2} 65533 65533 + expect EPERM -u 65533 -g 65533 chown ${n1}/${n2} 65534 65534 + expect EPERM -u 65533 -g 65533 chown ${n1}/${n2} 65533 65533 + expect EPERM -u 65534 -g 65534 -- chown ${n1}/${n2} -1 65533 + expect 0 -u 65534 -g 65534 symlink ${n2} ${n1}/${n3} + expect EPERM -u 65534 -g 65534 chown ${n1}/${n3} 65533 65533 + expect EPERM -u 65533 -g 65533 chown ${n1}/${n3} 65534 65534 + expect EPERM -u 65533 -g 65533 chown ${n1}/${n3} 65533 65533 + expect EPERM -u 65534 -g 65534 -- chown ${n1}/${n3} -1 65533 + expect 0 unlink ${n1}/${n3} + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n1}/${n2} + else + expect 0 unlink ${n1}/${n2} + fi + fi + create_file ${type} ${n1}/${n2} 65534 65534 + expect EPERM -u 65534 -g 65534 lchown ${n1}/${n2} 65533 65533 + expect EPERM -u 65533 -g 65533 lchown ${n1}/${n2} 65534 65534 + expect EPERM -u 65533 -g 65533 lchown ${n1}/${n2} 65533 65533 + expect EPERM -u 65534 -g 65534 -- lchown ${n1}/${n2} -1 65533 + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n1}/${n2} + else + expect 0 unlink ${n1}/${n2} + fi +done +expect 0 rmdir ${n1} +cd ${cdir} +expect 0 rmdir ${n0} diff --git a/tests/chown/08.t b/tests/chown/08.t new file mode 100644 index 000000000000..a98f873ff91b --- /dev/null +++ b/tests/chown/08.t @@ -0,0 +1,84 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/chown/08.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="chown returns EPERM if the named file has its immutable or append-only flag set" + +dir=`dirname $0` +. ${dir}/../misc.sh + +require chflags + +case "${os}:${fs}" in +FreeBSD:ZFS) + echo "1..20" + ;; +FreeBSD:UFS) + echo "1..44" + ;; +*) + quick_exit +esac + +n0=`namegen` + +expect 0 create ${n0} 0644 +expect 0 chflags ${n0} SF_IMMUTABLE +expect EPERM chown ${n0} 65534 65534 +expect 0,0 stat ${n0} uid,gid +expect 0 chflags ${n0} none +expect 0 chown ${n0} 65534 65534 +expect 65534,65534 stat ${n0} uid,gid +expect 0 unlink ${n0} + +expect 0 create ${n0} 0644 +expect 0 chflags ${n0} SF_NOUNLINK +expect 0 chown ${n0} 65534 65534 +expect 65534,65534 stat ${n0} uid,gid +expect 0 chflags ${n0} none +expect 0 unlink ${n0} + +case "${os}:${fs}" in +FreeBSD:ZFS) + expect 0 create ${n0} 0644 + expect 0 chflags ${n0} SF_APPEND + expect 0 chown ${n0} 65534 65534 + expect 65534,65534 stat ${n0} uid,gid + expect 0 chflags ${n0} none + expect 0 unlink ${n0} + ;; +FreeBSD:UFS) + expect 0 create ${n0} 0644 + expect 0 chflags ${n0} SF_APPEND + expect EPERM chown ${n0} 65534 65534 + expect 0,0 stat ${n0} uid,gid + expect 0 chflags ${n0} none + expect 0 chown ${n0} 65534 65534 + expect 65534,65534 stat ${n0} uid,gid + expect 0 unlink ${n0} + + expect 0 create ${n0} 0644 + expect 0 chflags ${n0} UF_IMMUTABLE + expect EPERM chown ${n0} 65534 65534 + expect 0,0 stat ${n0} uid,gid + expect 0 chflags ${n0} none + expect 0 chown ${n0} 65534 65534 + expect 65534,65534 stat ${n0} uid,gid + expect 0 unlink ${n0} + + expect 0 create ${n0} 0644 + expect 0 chflags ${n0} UF_NOUNLINK + expect 0 chown ${n0} 65534 65534 + expect 65534,65534 stat ${n0} uid,gid + expect 0 chflags ${n0} none + expect 0 unlink ${n0} + + expect 0 create ${n0} 0644 + expect 0 chflags ${n0} UF_APPEND + expect EPERM chown ${n0} 65534 65534 + expect 0,0 stat ${n0} uid,gid + expect 0 chflags ${n0} none + expect 0 chown ${n0} 65534 65534 + expect 65534,65534 stat ${n0} uid,gid + expect 0 unlink ${n0} + ;; +esac diff --git a/tests/chown/09.t b/tests/chown/09.t new file mode 100644 index 000000000000..455f43690706 --- /dev/null +++ b/tests/chown/09.t @@ -0,0 +1,32 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/chown/09.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="chown returns EROFS if the named file resides on a read-only file system" + +dir=`dirname $0` +. ${dir}/../misc.sh + +[ "${os}:${fs}" = "FreeBSD:UFS" ] || quick_exit + +echo "1..10" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +n=`mdconfig -a -n -t malloc -s 1m` +newfs /dev/md${n} >/dev/null +mount /dev/md${n} ${n0} +expect 0 create ${n0}/${n1} 0644 +expect 0 chown ${n0}/${n1} 65534 65534 +expect 65534,65534 stat ${n0}/${n1} uid,gid +mount -ur /dev/md${n} +expect EROFS chown ${n0}/${n1} 65533 65533 +expect 65534,65534 stat ${n0}/${n1} uid,gid +mount -uw /dev/md${n} +expect 0 chown ${n0}/${n1} 65533 65533 +expect 65533,65533 stat ${n0}/${n1} uid,gid +expect 0 unlink ${n0}/${n1} +umount /dev/md${n} +mdconfig -d -u ${n} +expect 0 rmdir ${n0} diff --git a/tests/chown/10.t b/tests/chown/10.t new file mode 100644 index 000000000000..e791008ee54e --- /dev/null +++ b/tests/chown/10.t @@ -0,0 +1,14 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/chown/10.t 211410 2010-08-17 06:08:09Z pjd $ + +desc="chown returns EFAULT if the path argument points outside the process's allocated address space" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..4" + +expect EFAULT chown NULL 65534 65534 +expect EFAULT chown DEADCODE 65534 65534 +expect EFAULT lchown NULL 65534 65534 +expect EFAULT lchown DEADCODE 65534 65534 diff --git a/tests/conf b/tests/conf new file mode 100644 index 000000000000..adb6cd6fb9b5 --- /dev/null +++ b/tests/conf @@ -0,0 +1,36 @@ +# $FreeBSD: head/tools/regression/pjdfstest/tests/conf 211354 2010-08-15 21:29:03Z pjd $ +# pjdfstest configuration file + +# Supported operating systems: FreeBSD, Darwin, SunOS, Linux +os=`uname` + +case "${os}" in +FreeBSD|Darwin) + GREP=grep + #fs=`df -T . | tail -1 | awk '{print $2}'` + pattern="`df . | tail -1 | awk '{printf("%s on %s \n", $1, $6)}'`" + fs=`mount | ${GREP} -E "^${pattern}" | awk -F '[(,]' '{print toupper($2)}'` + ;; +Solaris|SunOS) + GREP=ggrep + pattern=`df -Pk . | tail -1 | awk '{printf("%s on %s \n", $1, $6)}'` + fs=`mount -v | ${GREP} -E "^${pattern}" | awk '{print $5}' | \ + tr -s '[:lower:]' '[:upper:]'` + ;; +Linux) + GREP=grep + fs=`df -PT . | tail -1 | awk '{print toupper($2)}'` + ;; +*) + echo "Unsupported operating system ${os}." >/dev/stderr + exit 1 + ;; +esac + +# If we cannot figure out file system type, define it here. +#fs="UFS" + +if [ -z "${fs}" ]; then + echo "Cannot figure out file system type, define it by hand." >/dev/stderr + exit 1 +fi diff --git a/tests/ftruncate/00.t b/tests/ftruncate/00.t new file mode 100644 index 000000000000..ff6728fe2a53 --- /dev/null +++ b/tests/ftruncate/00.t @@ -0,0 +1,58 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/ftruncate/00.t 219439 2011-03-09 23:11:30Z pjd $ + +desc="ftruncate descrease/increase file size" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..21" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n1} 0755 +cdir=`pwd` +cd ${n1} + +expect 0 create ${n0} 0644 +expect 0 open ${n0} O_RDWR : ftruncate 0 1234567 +expect 1234567 lstat ${n0} size +expect 0 open ${n0} O_WRONLY : ftruncate 0 567 +expect 567 lstat ${n0} size +expect 0 unlink ${n0} + +dd if=/dev/random of=${n0} bs=12345 count=1 >/dev/null 2>&1 +expect 0 open ${n0} O_RDWR : ftruncate 0 23456 +expect 23456 lstat ${n0} size +expect 0 open ${n0} O_WRONLY : ftruncate 0 1 +expect 1 lstat ${n0} size +expect 0 unlink ${n0} + +# successful ftruncate(2) updates ctime. +expect 0 create ${n0} 0644 +ctime1=`${fstest} stat ${n0} ctime` +sleep 1 +expect 0 open ${n0} O_RDWR : ftruncate 0 123 +ctime2=`${fstest} stat ${n0} ctime` +test_check $ctime1 -lt $ctime2 +expect 0 unlink ${n0} + +# unsuccessful ftruncate(2) does not update ctime. +expect 0 create ${n0} 0644 +ctime1=`${fstest} stat ${n0} ctime` +sleep 1 +expect EINVAL -u 65534 open ${n0} O_RDONLY : ftruncate 0 123 +ctime2=`${fstest} stat ${n0} ctime` +test_check $ctime1 -eq $ctime2 +expect 0 unlink ${n0} + +# third argument should not affect permission. +expect 0 open ${n0} O_CREAT,O_RDWR 0 : ftruncate 0 0 +expect 0 unlink ${n0} +expect 0 chmod . 0777 +expect 0 -u 65534 open ${n0} O_CREAT,O_RDWR 0 : ftruncate 0 0 +expect 0 unlink ${n0} + +cd ${cdir} +expect 0 rmdir ${n1} diff --git a/tests/ftruncate/01.t b/tests/ftruncate/01.t new file mode 100644 index 000000000000..a8e95ac60181 --- /dev/null +++ b/tests/ftruncate/01.t @@ -0,0 +1,18 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/truncate/01.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="truncate returns ENOTDIR if a component of the path prefix is not a directory" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..5" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +expect 0 create ${n0}/${n1} 0644 +expect ENOTDIR truncate ${n0}/${n1}/test 123 +expect 0 unlink ${n0}/${n1} +expect 0 rmdir ${n0} diff --git a/tests/ftruncate/02.t b/tests/ftruncate/02.t new file mode 100644 index 000000000000..83de38d3244f --- /dev/null +++ b/tests/ftruncate/02.t @@ -0,0 +1,18 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/truncate/02.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="truncate returns ENAMETOOLONG if a component of a pathname exceeded {NAME_MAX} characters" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..5" + +nx=`namegen_max` +nxx="${nx}x" + +expect 0 create ${nx} 0644 +expect 0 truncate ${nx} 123 +expect 123 stat ${nx} size +expect 0 unlink ${nx} +expect ENAMETOOLONG truncate ${nxx} 123 diff --git a/tests/ftruncate/03.t b/tests/ftruncate/03.t new file mode 100644 index 000000000000..41e98625ba4f --- /dev/null +++ b/tests/ftruncate/03.t @@ -0,0 +1,22 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/truncate/03.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="truncate returns ENAMETOOLONG if an entire path name exceeded {PATH_MAX} characters" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..5" + +nx=`dirgen_max` +nxx="${nx}x" + +mkdir -p "${nx%/*}" + +expect 0 create ${nx} 0644 +expect 0 truncate ${nx} 123 +expect regular,123 stat ${nx} type,size +expect 0 unlink ${nx} +expect ENAMETOOLONG truncate ${nxx} 123 + +rm -rf "${nx%%/*}" diff --git a/tests/ftruncate/04.t b/tests/ftruncate/04.t new file mode 100644 index 000000000000..cd1cfc66b2b0 --- /dev/null +++ b/tests/ftruncate/04.t @@ -0,0 +1,17 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/truncate/04.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="truncate returns ENOENT if the named file does not exist" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..4" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +expect ENOENT truncate ${n0}/${n1}/test 123 +expect ENOENT truncate ${n0}/${n1} 123 +expect 0 rmdir ${n0} diff --git a/tests/ftruncate/05.t b/tests/ftruncate/05.t new file mode 100644 index 000000000000..f12881581bce --- /dev/null +++ b/tests/ftruncate/05.t @@ -0,0 +1,32 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/truncate/05.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="truncate returns EACCES when search permission is denied for a component of the path prefix" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..15" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n0} 0755 +cdir=`pwd` +cd ${n0} +expect 0 mkdir ${n1} 0755 +expect 0 chown ${n1} 65534 65534 +expect 0 -u 65534 -g 65534 create ${n1}/${n2} 0644 +expect 0 -u 65534 -g 65534 truncate ${n1}/${n2} 123 +expect 123 -u 65534 -g 65534 stat ${n1}/${n2} size +expect 0 chmod ${n1} 0644 +expect EACCES -u 65534 -g 65534 truncate ${n1}/${n2} 1234 +expect 0 chmod ${n1} 0755 +expect 123 -u 65534 -g 65534 stat ${n1}/${n2} size +expect 0 -u 65534 -g 65534 truncate ${n1}/${n2} 1234 +expect 1234 -u 65534 -g 65534 stat ${n1}/${n2} size +expect 0 -u 65534 -g 65534 unlink ${n1}/${n2} +expect 0 rmdir ${n1} +cd ${cdir} +expect 0 rmdir ${n0} diff --git a/tests/ftruncate/06.t b/tests/ftruncate/06.t new file mode 100644 index 000000000000..1ce516fa74a6 --- /dev/null +++ b/tests/ftruncate/06.t @@ -0,0 +1,24 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/truncate/06.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="truncate returns EACCES if the named file is not writable by the user" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..8" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +cdir=`pwd` +cd ${n0} +expect 0 create ${n1} 0644 +expect EACCES -u 65534 -g 65534 truncate ${n1} 123 +expect 0 chown ${n1} 65534 65534 +expect 0 chmod ${n1} 0444 +expect EACCES -u 65534 -g 65534 truncate ${n1} 123 +expect 0 unlink ${n1} +cd ${cdir} +expect 0 rmdir ${n0} diff --git a/tests/ftruncate/07.t b/tests/ftruncate/07.t new file mode 100644 index 000000000000..44f87e7ea859 --- /dev/null +++ b/tests/ftruncate/07.t @@ -0,0 +1,19 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/truncate/07.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="truncate returns ELOOP if too many symbolic links were encountered in translating the pathname" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..6" + +n0=`namegen` +n1=`namegen` + +expect 0 symlink ${n0} ${n1} +expect 0 symlink ${n1} ${n0} +expect ELOOP truncate ${n0}/test 123 +expect ELOOP truncate ${n1}/test 123 +expect 0 unlink ${n0} +expect 0 unlink ${n1} diff --git a/tests/ftruncate/08.t b/tests/ftruncate/08.t new file mode 100644 index 000000000000..6f205ef965f2 --- /dev/null +++ b/tests/ftruncate/08.t @@ -0,0 +1,78 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/truncate/08.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="truncate returns EPERM if the named file has its immutable or append-only flag set" + +dir=`dirname $0` +. ${dir}/../misc.sh + +require chflags + +case "${os}:${fs}" in +FreeBSD:ZFS) + echo "1..22" + ;; +FreeBSD:UFS) + echo "1..44" + ;; +*) + quick_exit +esac + +n0=`namegen` + +expect 0 create ${n0} 0644 +expect 0 chflags ${n0} SF_IMMUTABLE +expect EPERM truncate ${n0} 123 +expect 0 stat ${n0} size +expect 0 chflags ${n0} none +expect 0 truncate ${n0} 123 +expect 123 stat ${n0} size +expect 0 unlink ${n0} + +expect 0 create ${n0} 0644 +expect 0 chflags ${n0} SF_NOUNLINK +expect 0 truncate ${n0} 123 +expect 123 stat ${n0} size +expect 0 chflags ${n0} none +expect 0 unlink ${n0} + +expect 0 create ${n0} 0644 +expect 0 chflags ${n0} SF_APPEND +todo FreeBSD:ZFS "Truncating a file protected by SF_APPEND should return EPERM." +expect EPERM truncate ${n0} 123 +todo FreeBSD:ZFS "Truncating a file protected by SF_APPEND should return EPERM." +expect 0 stat ${n0} size +expect 0 chflags ${n0} none +expect 0 truncate ${n0} 123 +expect 123 stat ${n0} size +expect 0 unlink ${n0} + +case "${os}:${fs}" in +FreeBSD:UFS) + expect 0 create ${n0} 0644 + expect 0 chflags ${n0} UF_IMMUTABLE + expect EPERM truncate ${n0} 123 + expect 0 stat ${n0} size + expect 0 chflags ${n0} none + expect 0 truncate ${n0} 123 + expect 123 stat ${n0} size + expect 0 unlink ${n0} + + expect 0 create ${n0} 0644 + expect 0 chflags ${n0} UF_NOUNLINK + expect 0 truncate ${n0} 123 + expect 123 stat ${n0} size + expect 0 chflags ${n0} none + expect 0 unlink ${n0} + + expect 0 create ${n0} 0644 + expect 0 chflags ${n0} UF_APPEND + expect EPERM truncate ${n0} 123 + expect 0 stat ${n0} size + expect 0 chflags ${n0} none + expect 0 truncate ${n0} 123 + expect 123 stat ${n0} size + expect 0 unlink ${n0} + ;; +esac diff --git a/tests/ftruncate/09.t b/tests/ftruncate/09.t new file mode 100644 index 000000000000..d7e082ddbe0e --- /dev/null +++ b/tests/ftruncate/09.t @@ -0,0 +1,15 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/truncate/09.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="truncate returns EISDIR if the named file is a directory" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..3" + +n0=`namegen` + +expect 0 mkdir ${n0} 0755 +expect EISDIR truncate ${n0} 123 +expect 0 rmdir ${n0} diff --git a/tests/ftruncate/10.t b/tests/ftruncate/10.t new file mode 100644 index 000000000000..08893a385439 --- /dev/null +++ b/tests/ftruncate/10.t @@ -0,0 +1,32 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/truncate/10.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="truncate returns EROFS if the named file resides on a read-only file system" + +dir=`dirname $0` +. ${dir}/../misc.sh + +[ "${os}:${fs}" = "FreeBSD:UFS" ] || quick_exit + +echo "1..10" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +n=`mdconfig -a -n -t malloc -s 1m` +newfs /dev/md${n} >/dev/null +mount /dev/md${n} ${n0} +expect 0 create ${n0}/${n1} 0644 +expect 0 truncate ${n0}/${n1} 123 +expect 123 stat ${n0}/${n1} size +mount -ur /dev/md${n} +expect EROFS truncate ${n0}/${n1} 1234 +expect 123 stat ${n0}/${n1} size +mount -uw /dev/md${n} +expect 0 truncate ${n0}/${n1} 1234 +expect 1234 stat ${n0}/${n1} size +expect 0 unlink ${n0}/${n1} +umount /dev/md${n} +mdconfig -d -u ${n} +expect 0 rmdir ${n0} diff --git a/tests/ftruncate/11.t b/tests/ftruncate/11.t new file mode 100644 index 000000000000..b00d7b89c16d --- /dev/null +++ b/tests/ftruncate/11.t @@ -0,0 +1,18 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/truncate/11.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="truncate returns ETXTBSY the file is a pure procedure (shared text) file that is being executed" + +dir=`dirname $0` +. ${dir}/../misc.sh + +[ "${os}" = "FreeBSD" ] || quick_exit + +echo "1..2" + +n0=`namegen` + +cp -pf `which sleep` ${n0} +./${n0} 3 & +expect ETXTBSY truncate ${n0} 123 +expect 0 unlink ${n0} diff --git a/tests/ftruncate/12.t b/tests/ftruncate/12.t new file mode 100644 index 000000000000..1825456a7b13 --- /dev/null +++ b/tests/ftruncate/12.t @@ -0,0 +1,27 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/truncate/12.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="truncate returns EFBIG or EINVAL if the length argument was greater than the maximum file size" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..3" + +n0=`namegen` + +expect 0 create ${n0} 0644 +r=`${fstest} truncate ${n0} 999999999999999 2>/dev/null` +case "${r}" in +EFBIG|EINVAL) + expect 0 stat ${n0} size + ;; +0) + expect 999999999999999 stat ${n0} size + ;; +*) + echo "not ok ${ntest}" + ntest=`expr ${ntest} + 1` + ;; +esac +expect 0 unlink ${n0} diff --git a/tests/ftruncate/13.t b/tests/ftruncate/13.t new file mode 100644 index 000000000000..28307ae40af7 --- /dev/null +++ b/tests/ftruncate/13.t @@ -0,0 +1,16 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/truncate/13.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="ftruncate returns EINVAL if the length argument was less than 0" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..4" + +n0=`namegen` + +expect 0 create ${n0} 0644 +expect EINVAL -- open ${n0} O_RDWR : ftruncate 0 -1 +expect EINVAL -- open ${n0} O_WRONLY : ftruncate 0 -999999 +expect 0 unlink ${n0} diff --git a/tests/ftruncate/14.t b/tests/ftruncate/14.t new file mode 100644 index 000000000000..a238771264f9 --- /dev/null +++ b/tests/ftruncate/14.t @@ -0,0 +1,12 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/truncate/14.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="truncate returns EFAULT if the path argument points outside the process's allocated address space" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..2" + +expect EFAULT truncate NULL 123 +expect EFAULT truncate DEADCODE 123 diff --git a/tests/granular/00.t b/tests/granular/00.t new file mode 100644 index 000000000000..629f66e419ac --- /dev/null +++ b/tests/granular/00.t @@ -0,0 +1,112 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/granular/00.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="NFSv4 granular permissions checking - WRITE_DATA vs APPEND_DATA on directories" + +dir=`dirname $0` +. ${dir}/../misc.sh + +[ "${os}:${fs}" = "FreeBSD:ZFS" ] || quick_exit + +echo "1..49" + +n0=`namegen` +n1=`namegen` +n2=`namegen` +n3=`namegen` + +expect 0 mkdir ${n2} 0755 +expect 0 mkdir ${n3} 0777 +cdir=`pwd` +cd ${n2} + +# Tests 2..7 - check out whether root user can do stuff. +# Can create files? +expect 0 create ${n0} 0644 + +# Can create symlinks? +expect 0 link ${n0} ${n1} +expect 0 unlink ${n1} +expect 0 unlink ${n0} + +# Can create directories? +expect 0 mkdir ${n0} 0755 +expect 0 rmdir ${n0} + +# Check whether user 65534 is permitted to create and remove +# files, but not subdirectories. +expect 0 prependacl . user:65534:write_data::allow,user:65534:append_data::deny + +# Can create files? +expect 0 -u 65534 -g 65534 create ${n0} 0644 + +# Can create symlinks? +expect 0 -u 65534 -g 65534 link ${n0} ${n1} +expect 0 -u 65534 -g 65534 unlink ${n1} +expect 0 -u 65534 -g 65534 unlink ${n0} + +# Can create directories? +expect EACCES -u 65534 -g 65534 mkdir ${n0} 0755 +expect ENOENT -u 65534 -g 65534 rmdir ${n0} +expect 0 mkdir ${n0} 0755 +expect 0 -u 65534 -g 65534 rmdir ${n0} + +# Can move files from other directory? +expect 0 create ../${n3}/${n1} 0644 +expect 0 -u 65534 -g 65534 rename ../${n3}/${n1} ${n0} + +# Can move files from other directory overwriting existing files? +expect 0 create ../${n3}/${n1} 0644 +expect 0 -u 65534 -g 65534 rename ../${n3}/${n1} ${n0} + +expect 0 -u 65534 -g 65534 unlink ${n0} + +# Can move directories from other directory? +expect 0 mkdir ../${n3}/${n1} 0777 +expect EACCES -u 65534 -g 65534 rename ../${n3}/${n1} ${n0} + +# Can move directories from other directory overwriting existing directory? +expect EACCES -u 65534 -g 65534 rename ../${n3}/${n1} ${n0} +expect 0 -u 65534 -g 65534 rmdir ../${n3}/${n1} + +# Check whether user 65534 is permitted to create +# subdirectories, but not files - and to remove neither of them. +expect 0 prependacl . user:65534:write_data::deny,user:65534:append_data::allow + +# Can create files? +expect EACCES -u 65534 -g 65534 create ${n0} 0644 + +# Can create symlinks? +expect 0 create ${n0} 0644 +expect EACCES -u 65534 -g 65534 link ${n0} ${n1} +expect ENOENT -u 65534 -g 65534 unlink ${n1} +expect EACCES -u 65534 -g 65534 unlink ${n0} +expect 0 unlink ${n0} + +# Can create directories? +expect 0 -u 65534 -g 65534 mkdir ${n0} 0755 +expect EACCES -u 65534 -g 65534 rmdir ${n0} +expect 0 rmdir ${n0} + +# Can move files from other directory? +expect 0 create ../${n3}/${n1} 0644 +expect EACCES -u 65534 -g 65534 rename ../${n3}/${n1} ${n0} + +# Can move files from other directory overwriting existing files? +expect EACCES -u 65534 -g 65534 rename ../${n3}/${n1} ${n0} +expect 0 -u 65534 -g 65534 unlink ../${n3}/${n1} + +# Can move directories from other directory? +expect 0 mkdir ../${n3}/${n1} 0777 +expect 0 -u 65534 -g 65534 rename ../${n3}/${n1} ${n0} + +# Can move directories from other directory overwriting existing directory? +expect 0 mkdir ../${n3}/${n1} 0777 +expect EACCES -u 65534 -g 65534 rename ../${n3}/${n1} ${n0} +expect 0 prependacl . user:65534:delete_child::allow +expect 0 -u 65534 -g 65534 rename ../${n3}/${n1} ${n0} +expect 0 -u 65534 -g 65534 rmdir ${n0} + +cd ${cdir} +expect 0 rmdir ${n2} +expect 0 rmdir ${n3} diff --git a/tests/granular/01.t b/tests/granular/01.t new file mode 100644 index 000000000000..f6658cc5f840 --- /dev/null +++ b/tests/granular/01.t @@ -0,0 +1,37 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/granular/01.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="NFSv4 granular permissions checking - ACL_READ_ATTRIBUTES and ACL_WRITE_ATTRIBUTES" + +dir=`dirname $0` +. ${dir}/../misc.sh + +[ "${os}:${fs}" = "FreeBSD:ZFS" ] || quick_exit + +echo "1..12" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n2} 0755 +cdir=`pwd` +cd ${n2} + +# Tests 1..12 - check out whether user 65534 is permitted to read attributes. +expect 0 create ${n0} 0644 +expect 0 lstat ${n0} size +expect 0 -u 65534 -g 65534 stat ${n0} size +expect 0 prependacl ${n0} user:65534:read_attributes::deny +expect 0 lstat ${n0} size +expect EACCES -u 65534 -g 65534 stat ${n0} size +expect 0 prependacl ${n0} user:65534:read_attributes::allow +expect 0 -u 65534 -g 65534 stat ${n0} size +expect 0 lstat ${n0} size +expect 0 unlink ${n0} + +# Tests 12..12 - check out whether user 65534 is permitted to write attributes. +# XXX: Check if ACL_WRITE_ATTRIBUTES allows for modifying access times. + +cd ${cdir} +expect 0 rmdir ${n2} diff --git a/tests/granular/02.t b/tests/granular/02.t new file mode 100644 index 000000000000..32a318cc0d90 --- /dev/null +++ b/tests/granular/02.t @@ -0,0 +1,144 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/granular/02.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="NFSv4 granular permissions checking - ACL_READ_ACL and ACL_WRITE_ACL" + +dir=`dirname $0` +. ${dir}/../misc.sh + +[ "${os}:${fs}" = "FreeBSD:ZFS" ] || quick_exit + +echo "1..83" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n2} 0755 +cdir=`pwd` +cd ${n2} + +# Check whether user 65534 is permitted to read ACL. +expect 0 create ${n0} 0644 +expect 0 readacl ${n0} +expect 0 -u 65534 -g 65534 readacl ${n0} +expect 0 prependacl ${n0} user:65534:read_acl::deny +expect 0 readacl ${n0} +expect EACCES -u 65534 -g 65534 readacl ${n0} +expect 0 prependacl ${n0} user:65534:read_acl::allow +expect 0 -u 65534 -g 65534 readacl ${n0} +expect 0 readacl ${n0} +expect 0 unlink ${n0} + +# Check whether user 65534 is permitted to write ACL. +expect 0 create ${n0} 0644 +expect EPERM -u 65534 -g 65534 prependacl ${n0} user:65534:read_data::allow +expect 0 prependacl ${n0} user:65534:write_acl::allow +expect 0 -u 65534 -g 65534 prependacl ${n0} user:65534:read_data::allow +expect 0 unlink ${n0} + +# Check whether user 65534 is permitted to write mode. +expect 0 create ${n0} 0755 +expect EPERM -u 65534 -g 65534 chmod ${n0} 0777 +expect 0 prependacl ${n0} user:65534:write_acl::allow +expect 0 -u 65534 -g 65534 chmod ${n0} 0777 +expect 0 unlink ${n0} + +# There is an interesting problem with interaction between ACL_WRITE_ACL +# and SUID/SGID bits. In case user does have ACL_WRITE_ACL, but is not +# a file owner, Solaris does the following: +# 1. Setting SUID fails with EPERM. +# 2. Setting SGID succeeds, but mode is not changed. +# 3. Modifying ACL does not clear SUID nor SGID bits. +# 4. Writing the file does clear both SUID and SGID bits. +# +# What we are doing is the following: +# 1. Setting SUID or SGID fails with EPERM. +# 2. Modifying ACL does not clear SUID nor SGID bits. +# 3. Writing the file does clear both SUID and SGID bits. +# +# Check whether user 65534 is denied to write mode with SUID bit. +expect 0 create ${n0} 0755 +expect EPERM -u 65534 -g 65534 chmod ${n0} 04777 +expect 0 prependacl ${n0} user:65534:write_acl::allow +expect EPERM -u 65534 -g 65534 chmod ${n0} 04777 +expect 0 unlink ${n0} + +# Check whether user 65534 is denied to write mode with SGID bit. +expect 0 create ${n0} 0755 +expect EPERM -u 65534 -g 65534 chmod ${n0} 02777 +expect 0 prependacl ${n0} user:65534:write_acl::allow +expect EPERM -u 65534 -g 65534 chmod ${n0} 02777 +expect 0 unlink ${n0} + +# Check whether user 65534 is allowed to write mode with sticky bit. +expect 0 mkdir ${n0} 0755 +expect EPERM -u 65534 -g 65534 chmod ${n0} 01777 +expect 0 prependacl ${n0} user:65534:write_acl::allow +expect 0 -u 65534 -g 65534 chmod ${n0} 01777 +expect 0 rmdir ${n0} + +# Check whether modifying the ACL by not-owner preserves the SUID. +expect 0 create ${n0} 04755 +expect 0 prependacl ${n0} user:65534:write_acl::allow +expect 0 -u 65534 -g 65534 prependacl ${n0} user:65534:write_data::allow +expect 04755 stat ${n0} mode +expect 0 unlink ${n0} + +# Check whether modifying the ACL by not-owner preserves the SGID. +expect 0 create ${n0} 02755 +expect 0 prependacl ${n0} user:65534:write_acl::allow +expect 0 -u 65534 -g 65534 prependacl ${n0} user:65534:write_data::allow +expect 02755 stat ${n0} mode +expect 0 unlink ${n0} + +# Check whether modifying the ACL by not-owner preserves the sticky bit. +expect 0 mkdir ${n0} 0755 +expect 0 chmod ${n0} 01755 +expect 0 prependacl ${n0} user:65534:write_acl::allow +expect 0 -u 65534 -g 65534 prependacl ${n0} user:65534:write_data::allow +expect 01755 stat ${n0} mode +expect 0 rmdir ${n0} + +# Clearing the SUID and SGID bits when being written to by non-owner +# is checked in chmod/12.t. + +# Check whether the file owner is always permitted to get and set +# ACL and file mode, even if ACL_{READ,WRITE}_ACL would deny it. +expect 0 chmod . 0777 +expect 0 -u 65534 -g 65534 create ${n0} 0600 +expect 0 -u 65534 -g 65534 prependacl ${n0} user:65534:write_acl::deny +expect 0 -u 65534 -g 65534 prependacl ${n0} user:65534:read_acl::deny +expect 0 -u 65534 -g 65534 readacl ${n0} +expect 0600 -u 65534 -g 65534 stat ${n0} mode +expect 0 -u 65534 -g 65534 chmod ${n0} 0777 +expect 0 unlink ${n0} + +expect 0 -u 65534 -g 65534 mkdir ${n0} 0600 +expect 0 -u 65534 -g 65534 prependacl ${n0} user:65534:write_acl::deny +expect 0 -u 65534 -g 65534 prependacl ${n0} user:65534:read_acl::deny +expect 0 -u 65534 -g 65534 readacl ${n0} +expect 0600 -u 65534 -g 65534 stat ${n0} mode +expect 0 -u 65534 -g 65534 chmod ${n0} 0777 +expect 0 rmdir ${n0} + +# Check whether the root is allowed for these as well. +expect 0 -u 65534 -g 65534 create ${n0} 0600 +expect 0 prependacl ${n0} everyone@:write_acl::deny +expect 0 prependacl ${n0} everyone@:read_acl::deny +expect 0 readacl ${n0} +expect 0600 stat ${n0} mode +expect 0 chmod ${n0} 0777 +expect 0 unlink ${n0} + +expect 0 -u 65534 -g 65534 mkdir ${n0} 0600 +expect 0 prependacl ${n0} everyone@:write_acl::deny +expect 0 prependacl ${n0} everyone@:read_acl::deny +expect 0600 stat ${n0} mode +expect 0 readacl ${n0} +expect 0600 stat ${n0} mode +expect 0 chmod ${n0} 0777 +expect 0 rmdir ${n0} + +cd ${cdir} +expect 0 rmdir ${n2} diff --git a/tests/granular/03.t b/tests/granular/03.t new file mode 100644 index 000000000000..3b825ccef3a3 --- /dev/null +++ b/tests/granular/03.t @@ -0,0 +1,134 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/granular/03.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="NFSv4 granular permissions checking - DELETE and DELETE_CHILD" + +dir=`dirname $0` +. ${dir}/../misc.sh + +[ "${os}:${fs}" = "FreeBSD:ZFS" ] || quick_exit + +echo "1..65" + +n0=`namegen` +n1=`namegen` +n2=`namegen` +n3=`namegen` + +expect 0 mkdir ${n2} 0755 +expect 0 mkdir ${n3} 0777 +cdir=`pwd` +cd ${n2} + +# Unlink allowed on writable directory. +expect 0 create ${n0} 0644 +expect EACCES -u 65534 -g 65534 unlink ${n0} +expect 0 prependacl . user:65534:write_data::allow +expect 0 -u 65534 -g 65534 unlink ${n0} + +# Moving file elsewhere allowed on writable directory. +expect 0 create ${n0} 0644 +expect 0 prependacl . user:65534:write_data::deny +expect EACCES -u 65534 -g 65534 rename ${n0} ../${n3}/${n0} +expect 0 prependacl . user:65534:write_data::allow +expect 0 -u 65534 -g 65534 rename ${n0} ../${n3}/${n0} + +# Moving file from elsewhere allowed on writable directory. +expect 0 -u 65534 -g 65534 rename ../${n3}/${n0} ${n0} +expect 0 -u 65534 -g 65534 unlink ${n0} + +# Moving file from elsewhere overwriting local file allowed +# on writable directory. +expect 0 create ${n0} 0644 +expect 0 create ../${n3}/${n0} 0644 +expect 0 prependacl . user:65534:write_data::deny +expect EACCES -u 65534 -g 65534 rename ../${n3}/${n0} ${n0} +expect 0 prependacl . user:65534:write_data::allow +expect 0 -u 65534 -g 65534 rename ../${n3}/${n0} ${n0} +expect 0 -u 65534 -g 65534 unlink ${n0} + +# Denied DELETE changes nothing wrt removing. +expect 0 create ${n0} 0644 +expect 0 prependacl ${n0} user:65534:delete::deny +expect 0 -u 65534 -g 65534 unlink ${n0} + +# Denied DELETE changes nothing wrt moving elsewhere or from elsewhere. +expect 0 create ${n0} 0644 +expect 0 -u 65534 -g 65534 rename ${n0} ../${n3}/${n0} +expect 0 -u 65534 -g 65534 rename ../${n3}/${n0} ${n0} +expect 0 -u 65534 -g 65534 unlink ${n0} + +# DELETE_CHILD denies unlink on writable directory. +expect 0 create ${n0} 0644 +expect 0 prependacl . user:65534:delete_child::deny +expect EPERM -u 65534 -g 65534 unlink ${n0} +expect 0 unlink ${n0} + +# DELETE_CHILD denies moving file elsewhere. +expect 0 create ${n0} 0644 +expect EPERM -u 65534 -g 65534 rename ${n0} ../${n3}/${n0} +expect 0 rename ${n0} ../${n3}/${n0} + +# DELETE_CHILD does not deny moving file from elsewhere +# to a writable directory. +expect 0 -u 65534 -g 65534 rename ../${n3}/${n0} ${n0} + +# DELETE_CHILD denies moving file from elsewhere +# to a writable directory overwriting local file. +expect 0 create ../${n3}/${n0} 0644 +expect EPERM -u 65534 -g 65534 rename ../${n3}/${n0} ${n0} + +# DELETE allowed on file allows for unlinking, no matter +# what permissions on containing directory are. +expect 0 prependacl ${n0} user:65534:delete::allow +expect 0 -u 65534 -g 65534 unlink ${n0} + +# Same for moving the file elsewhere. +expect 0 create ${n0} 0644 +expect 0 prependacl ${n0} user:65534:delete::allow +expect 0 -u 65534 -g 65534 rename ${n0} ../${n3}/${n0} + +# Same for moving the file from elsewhere into a writable +# directory with DELETE_CHILD denied. +expect 0 -u 65534 -g 65534 rename ../${n3}/${n0} ${n0} +expect 0 unlink ${n0} + +# DELETE does not allow for overwriting a file in a unwritable +# directory with DELETE_CHILD denied. +expect 0 create ${n0} 0644 +expect 0 create ../${n3}/${n0} 0644 +expect 0 prependacl . user:65534:write_data::deny +expect 0 prependacl . user:65534:delete_child::deny +expect EPERM -u 65534 -g 65534 rename ../${n3}/${n0} ${n0} +expect 0 prependacl ${n0} user:65534:delete::allow +expect EACCES -u 65534 -g 65534 rename ../${n3}/${n0} ${n0} + +# But it allows for plain deletion. +expect 0 -u 65534 -g 65534 unlink ${n0} + +# DELETE_CHILD allowed on unwritable directory. +expect 0 create ${n0} 0644 +expect 0 prependacl . user:65534:delete_child::allow +expect 0 -u 65534 -g 65534 unlink ${n0} + +# Moving things elsewhere is allowed. +expect 0 create ${n0} 0644 +expect 0 -u 65534 -g 65534 rename ${n0} ../${n3}/${n0} + +# Moving things back is not. +expect EACCES -u 65534 -g 65534 rename ../${n3}/${n0} ${n0} + +# Even if we're overwriting. +expect 0 create ${n0} 0644 +expect EACCES -u 65534 -g 65534 rename ../${n3}/${n0} ${n0} + +# Even if we have DELETE on the existing file. +expect 0 prependacl ${n0} user:65534:delete::allow +expect EACCES -u 65534 -g 65534 rename ../${n3}/${n0} ${n0} + +# Denied DELETE changes nothing wrt removing. +expect 0 prependacl ${n0} user:65534:delete::deny +expect 0 -u 65534 -g 65534 unlink ${n0} + +cd ${cdir} +expect 0 rmdir ${n2} diff --git a/tests/granular/04.t b/tests/granular/04.t new file mode 100644 index 000000000000..a06b0d605ebd --- /dev/null +++ b/tests/granular/04.t @@ -0,0 +1,80 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/granular/04.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="NFSv4 granular permissions checking - ACL_WRITE_OWNER" + +dir=`dirname $0` +. ${dir}/../misc.sh + +[ "${os}:${fs}" = "FreeBSD:ZFS" ] || quick_exit + +echo "1..52" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n2} 0755 +cdir=`pwd` +cd ${n2} + +# ACL_WRITE_OWNER permits to set gid to our own only. +expect 0 create ${n0} 0644 +expect 0,0 lstat ${n0} uid,gid +expect EPERM -u 65534 -g 65532,65531 chown ${n0} -1 65532 +expect 0,0 lstat ${n0} uid,gid +expect 0 prependacl ${n0} user:65534:write_owner::allow +expect EPERM -u 65534 -g 65532,65531 chown ${n0} -1 65530 +expect 0,0 lstat ${n0} uid,gid +expect 0 -u 65534 -g 65532,65531 chown ${n0} -1 65532 +expect 0,65532 lstat ${n0} uid,gid +expect 0 unlink ${n0} + +# ACL_WRITE_OWNER permits to set uid to our own only. +expect 0 create ${n0} 0644 +expect 0,0 lstat ${n0} uid,gid +expect EPERM -u 65534 -g 65532,65531 chown ${n0} 65534 65531 +expect 0,0 lstat ${n0} uid,gid +expect 0 prependacl ${n0} user:65534:write_owner::allow +expect EPERM -u 65534 -g 65532,65531 chown ${n0} 65530 65531 +expect 0,0 lstat ${n0} uid,gid +expect 0 -u 65534 -g 65532,65531 chown ${n0} 65534 65531 +expect 65534,65531 lstat ${n0} uid,gid +expect 0 unlink ${n0} + +# When non-owner calls chown(2) successfully, set-uid and set-gid bits are +# removed, except when both uid and gid are equal to -1. +expect 0 create ${n0} 0644 +expect 0 prependacl ${n0} user:65534:write_owner::allow +expect 0 chmod ${n0} 06555 +expect 06555 lstat ${n0} mode +expect 0 -u 65534 -g 65533,65532 chown ${n0} 65534 65532 +expect 0555,65534,65532 lstat ${n0} mode,uid,gid +expect 0 chmod ${n0} 06555 +expect 06555 lstat ${n0} mode +expect 0 -u 65534 -g 65533,65532 chown ${n0} -1 65533 +expect 0555,65534,65533 lstat ${n0} mode,uid,gid +expect 0 chmod ${n0} 06555 +expect 06555 lstat ${n0} mode +expect 0 -u 65534 -g 65533,65532 chown ${n0} -1 -1 +expect 06555,65534,65533 lstat ${n0} mode,uid,gid +expect 0 unlink ${n0} + +expect 0 mkdir ${n0} 0755 +expect 0 prependacl ${n0} user:65534:write_owner::allow +expect 0 chmod ${n0} 06555 +expect 06555 lstat ${n0} mode +expect 0 -u 65534 -g 65533,65532 chown ${n0} 65534 65532 +expect 0555,65534,65532 lstat ${n0} mode,uid,gid +expect 0 chmod ${n0} 06555 +expect 06555 lstat ${n0} mode +expect 0 -u 65534 -g 65533,65532 chown ${n0} -1 65533 +expect 0555,65534,65533 lstat ${n0} mode,uid,gid +expect 0 chmod ${n0} 06555 +expect 06555 lstat ${n0} mode +expect 0 -u 65534 -g 65533,65532 chown ${n0} -1 -1 +expect 06555,65534,65533 lstat ${n0} mode,uid,gid +expect 0 rmdir ${n0} + +cd ${cdir} +expect 0 rmdir ${n2} diff --git a/tests/granular/05.t b/tests/granular/05.t new file mode 100644 index 000000000000..c42f51a90987 --- /dev/null +++ b/tests/granular/05.t @@ -0,0 +1,149 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/granular/05.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="NFSv4 granular permissions checking - DELETE and DELETE_CHILD with directories" + +dir=`dirname $0` +. ${dir}/../misc.sh + +[ "${os}:${fs}" = "FreeBSD:ZFS" ] || quick_exit + +echo "1..68" + +n0=`namegen` +n1=`namegen` +n2=`namegen` +n3=`namegen` + +expect 0 mkdir ${n2} 0755 +expect 0 mkdir ${n3} 0777 +cdir=`pwd` +cd ${n2} + +# Unlink allowed on writable directory. +expect 0 mkdir ${n0} 0755 +expect EACCES -u 65534 -g 65534 rmdir ${n0} +expect 0 prependacl . user:65534:write_data::allow +expect 0 -u 65534 -g 65534 rmdir ${n0} + +# Moving directory elsewhere allowed on writable directory. +expect 0 mkdir ${n0} 0777 +expect 0 prependacl . user:65534:write_data::deny +expect EACCES -u 65534 -g 65534 rename ${n0} ../${n3}/${n0} +expect 0 prependacl . user:65534:write_data::allow +expect 0 -u 65534 -g 65534 rename ${n0} ../${n3}/${n0} + +# 12 +# Moving directory from elsewhere allowed on writable directory. +expect EACCES -u 65534 -g 65534 rename ../${n3}/${n0} ${n0} +expect 0 prependacl . user:65534:append_data::allow +expect 0 -u 65534 -g 65534 rename ../${n3}/${n0} ${n0} +expect 0 -u 65534 -g 65534 rmdir ${n0} + +# Moving directory from elsewhere overwriting local directory allowed +# on writable directory. +expect 0 mkdir ${n0} 0755 +expect 0 mkdir ../${n3}/${n0} 0777 +expect 0 prependacl . user:65534:write_data::deny +expect EACCES -u 65534 -g 65534 rename ../${n3}/${n0} ${n0} +expect 0 prependacl . user:65534:write_data::allow +expect 0 -u 65534 -g 65534 rename ../${n3}/${n0} ${n0} +expect 0 -u 65534 -g 65534 rmdir ${n0} + +# 23 +# Denied DELETE changes nothing wrt removing. +expect 0 mkdir ${n0} 0755 +expect 0 prependacl ${n0} user:65534:delete::deny +expect 0 -u 65534 -g 65534 rmdir ${n0} + +# Denied DELETE changes nothing wrt moving elsewhere or from elsewhere. +expect 0 mkdir ${n0} 0777 +expect 0 -u 65534 -g 65534 rename ${n0} ../${n3}/${n0} +expect 0 -u 65534 -g 65534 rename ../${n3}/${n0} ${n0} +expect 0 -u 65534 -g 65534 rmdir ${n0} + +# DELETE_CHILD denies unlink on writable directory. +expect 0 mkdir ${n0} 0755 +expect 0 prependacl . user:65534:delete_child::deny +expect EPERM -u 65534 -g 65534 rmdir ${n0} +expect 0 rmdir ${n0} + +# 35 +# DELETE_CHILD denies moving directory elsewhere. +expect 0 mkdir ${n0} 0777 +expect EPERM -u 65534 -g 65534 rename ${n0} ../${n3}/${n0} +expect 0 rename ${n0} ../${n3}/${n0} + +# DELETE_CHILD does not deny moving directory from elsewhere +# to a writable directory. +expect 0 -u 65534 -g 65534 rename ../${n3}/${n0} ${n0} + +# DELETE_CHILD denies moving directory from elsewhere +# to a writable directory overwriting local directory. +expect 0 mkdir ../${n3}/${n0} 0755 +expect EACCES -u 65534 -g 65534 rename ../${n3}/${n0} ${n0} + +# DELETE allowed on directory allows for unlinking, no matter +# what permissions on containing directory are. +expect 0 prependacl ${n0} user:65534:delete::allow +expect 0 -u 65534 -g 65534 rmdir ${n0} + +# Same for moving the directory elsewhere. +expect 0 mkdir ${n0} 0777 +expect 0 prependacl ${n0} user:65534:delete::allow +expect 0 -u 65534 -g 65534 rename ${n0} ../${n3}/${n0} + +# 46 +# Same for moving the directory from elsewhere into a writable +# directory with DELETE_CHILD denied. +expect 0 -u 65534 -g 65534 rename ../${n3}/${n0} ${n0} +expect 0 rmdir ${n0} + +# DELETE does not allow for overwriting a directory in a unwritable +# directory with DELETE_CHILD denied. +expect 0 mkdir ${n0} 0755 +expect 0 mkdir ../${n3}/${n0} 0777 +expect 0 prependacl . user:65534:write_data::deny +expect 0 prependacl . user:65534:delete_child::deny +expect EPERM -u 65534 -g 65534 rename ../${n3}/${n0} ${n0} +expect 0 prependacl ${n0} user:65534:delete::allow +# XXX: expect EACCES -u 65534 -g 65534 rename ../${n3}/${n0} ${n0} +expect 0 -u 65534 -g 65534 rename ../${n3}/${n0} ${n0} + +# 54 +# But it allows for plain deletion. +# XXX: expect 0 -u 65534 -g 65534 rmdir ${n0} +expect 0 rmdir ${n0} + +# DELETE_CHILD allowed on unwritable directory. +expect 0 mkdir ${n0} 0755 +expect 0 prependacl . user:65534:delete_child::allow +expect 0 -u 65534 -g 65534 rmdir ${n0} + +# Moving things elsewhere is allowed. +expect 0 mkdir ${n0} 0777 +expect 0 -u 65534 -g 65534 rename ${n0} ../${n3}/${n0} + +# 60 +# Moving things back is not. +# XXX: expect EACCES -u 65534 -g 65534 rename ../${n3}/${n0} ${n0} +expect 0 -u 65534 -g 65534 rename ../${n3}/${n0} ${n0} + +# Even if we're overwriting. +# XXX: expect 0 mkdir ${n0} 0755 +expect 0 mkdir ../${n3}/${n0} 0777 +# XXX: expect EACCES -u 65534 -g 65534 rename ../${n3}/${n0} ${n0} +expect 0 -u 65534 -g 65534 rename ../${n3}/${n0} ${n0} +expect 0 mkdir ../${n3}/${n0} 0777 + +# Even if we have DELETE on the existing directory. +expect 0 prependacl ${n0} user:65534:delete::allow +# XXX: expect EACCES -u 65534 -g 65534 rename ../${n3}/${n0} ${n0} +expect 0 -u 65534 -g 65534 rename ../${n3}/${n0} ${n0} + +# Denied DELETE changes nothing wrt removing. +expect 0 prependacl ${n0} user:65534:delete::deny +expect 0 -u 65534 -g 65534 rmdir ${n0} + +cd ${cdir} +expect 0 rmdir ${n2} diff --git a/tests/link/00.t b/tests/link/00.t new file mode 100644 index 000000000000..1bcb32ad17ac --- /dev/null +++ b/tests/link/00.t @@ -0,0 +1,93 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/link/00.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="link creates hardlinks" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..202" + +n0=`namegen` +n1=`namegen` +n2=`namegen` +n3=`namegen` + +expect 0 mkdir ${n3} 0755 +cdir=`pwd` +cd ${n3} + +for type in regular fifo block char socket; do + create_file ${type} ${n0} + expect ${type},1 lstat ${n0} type,nlink + + expect 0 link ${n0} ${n1} + expect ${type},2 lstat ${n0} type,nlink + expect ${type},2 lstat ${n1} type,nlink + + expect 0 link ${n1} ${n2} + expect ${type},3 lstat ${n0} type,nlink + expect ${type},3 lstat ${n1} type,nlink + expect ${type},3 lstat ${n2} type,nlink + + expect 0 chmod ${n1} 0201 + expect 0 chown ${n1} 65534 65533 + + expect ${type},0201,3,65534,65533 lstat ${n0} type,mode,nlink,uid,gid + expect ${type},0201,3,65534,65533 lstat ${n1} type,mode,nlink,uid,gid + expect ${type},0201,3,65534,65533 lstat ${n2} type,mode,nlink,uid,gid + + expect 0 unlink ${n0} + expect ENOENT lstat ${n0} type,mode,nlink,uid,gid + expect ${type},0201,2,65534,65533 lstat ${n1} type,mode,nlink,uid,gid + expect ${type},0201,2,65534,65533 lstat ${n2} type,mode,nlink,uid,gid + + expect 0 unlink ${n2} + expect ENOENT lstat ${n0} type,mode,nlink,uid,gid + expect ${type},0201,1,65534,65533 lstat ${n1} type,mode,nlink,uid,gid + expect ENOENT lstat ${n2} type,mode,nlink,uid,gid + + expect 0 unlink ${n1} + expect ENOENT lstat ${n0} type,mode,nlink,uid,gid + expect ENOENT lstat ${n1} type,mode,nlink,uid,gid + expect ENOENT lstat ${n2} type,mode,nlink,uid,gid +done + +# successful link(2) updates ctime. +for type in regular fifo block char socket; do + create_file ${type} ${n0} + ctime1=`${fstest} stat ${n0} ctime` + dctime1=`${fstest} stat . ctime` + dmtime1=`${fstest} stat . mtime` + sleep 1 + expect 0 link ${n0} ${n1} + ctime2=`${fstest} stat ${n0} ctime` + test_check $ctime1 -lt $ctime2 + dctime2=`${fstest} stat . ctime` + test_check $dctime1 -lt $dctime2 + dmtime2=`${fstest} stat . mtime` + test_check $dctime1 -lt $dmtime2 + expect 0 unlink ${n0} + expect 0 unlink ${n1} +done + +# unsuccessful link(2) does not update ctime. +for type in regular fifo block char socket; do + create_file ${type} ${n0} + expect 0 -- chown ${n0} 65534 -1 + ctime1=`${fstest} stat ${n0} ctime` + dctime1=`${fstest} stat . ctime` + dmtime1=`${fstest} stat . mtime` + sleep 1 + expect EACCES -u 65534 link ${n0} ${n1} + ctime2=`${fstest} stat ${n0} ctime` + test_check $ctime1 -eq $ctime2 + dctime2=`${fstest} stat . ctime` + test_check $dctime1 -eq $dctime2 + dmtime2=`${fstest} stat . mtime` + test_check $dctime1 -eq $dmtime2 + expect 0 unlink ${n0} +done + +cd ${cdir} +expect 0 rmdir ${n3} diff --git a/tests/link/01.t b/tests/link/01.t new file mode 100644 index 000000000000..fe05aeba7119 --- /dev/null +++ b/tests/link/01.t @@ -0,0 +1,24 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/link/01.t 211474 2010-08-18 22:06:43Z pjd $ + +desc="link returns ENOTDIR if a component of either path prefix is not a directory" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..32" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n0} 0755 +for type in regular fifo block char socket; do + create_file ${type} ${n0}/${n1} + expect ENOTDIR link ${n0}/${n1}/test ${n0}/${n2} + create_file ${type} ${n0}/${n2} + expect ENOTDIR link ${n0}/${n2} ${n0}/${n1}/test + expect 0 unlink ${n0}/${n1} + expect 0 unlink ${n0}/${n2} +done +expect 0 rmdir ${n0} diff --git a/tests/link/02.t b/tests/link/02.t new file mode 100644 index 000000000000..ca3e092edf99 --- /dev/null +++ b/tests/link/02.t @@ -0,0 +1,25 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/link/02.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="link returns ENAMETOOLONG if a component of either pathname exceeded {NAME_MAX} characters" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..10" + +n0=`namegen` +nx=`namegen_max` +nxx="${nx}x" + +expect 0 create ${nx} 0644 +expect 0 link ${nx} ${n0} +expect 0 unlink ${nx} +expect 0 link ${n0} ${nx} +expect 0 unlink ${n0} +expect 0 unlink ${nx} + +expect 0 create ${n0} 0644 +expect ENAMETOOLONG link ${n0} ${nxx} +expect 0 unlink ${n0} +expect ENAMETOOLONG link ${nxx} ${n0} diff --git a/tests/link/03.t b/tests/link/03.t new file mode 100644 index 000000000000..22f8e55e0cb3 --- /dev/null +++ b/tests/link/03.t @@ -0,0 +1,31 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/link/03.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="link returns ENAMETOOLONG if an entire length of either path name exceeded {PATH_MAX} characters" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..13" + +n0=`namegen` +nx=`dirgen_max` +nxx="${nx}x" + +mkdir -p "${nx%/*}" + +expect 0 create ${nx} 0644 +expect 0 link ${nx} ${n0} +expect 2 stat ${n0} nlink +expect 2 stat ${nx} nlink +expect 0 unlink ${nx} +expect 0 link ${n0} ${nx} +expect 2 stat ${n0} nlink +expect 2 stat ${nx} nlink +expect 0 unlink ${nx} +expect ENAMETOOLONG link ${n0} ${nxx} +expect 1 stat ${n0} nlink +expect 0 unlink ${n0} +expect ENAMETOOLONG link ${nxx} ${n0} + +rm -rf "${nx%%/*}" diff --git a/tests/link/04.t b/tests/link/04.t new file mode 100644 index 000000000000..bb095396005e --- /dev/null +++ b/tests/link/04.t @@ -0,0 +1,20 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/link/04.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="link returns ENOENT if a component of either path prefix does not exist" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..6" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n0} 0755 +expect ENOENT link ${n0}/${n1}/test ${n2} +expect 0 create ${n2} 0644 +expect ENOENT link ${n2} ${n0}/${n1}/test +expect 0 unlink ${n2} +expect 0 rmdir ${n0} diff --git a/tests/link/05.t b/tests/link/05.t new file mode 100644 index 000000000000..7db93fd96c67 --- /dev/null +++ b/tests/link/05.t @@ -0,0 +1,36 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/link/05.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="link returns EMLINK if the link count of the file named by name1 would exceed 32767" + +dir=`dirname $0` +. ${dir}/../misc.sh + +[ "${os}:${fs}" = "FreeBSD:UFS" ] || quick_exit + +echo "1..5" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n0} 0755 +n=`mdconfig -a -n -t malloc -s 1m` +newfs -i 1 /dev/md${n} >/dev/null +mount /dev/md${n} ${n0} +expect 0 create ${n0}/${n1} 0644 +i=1 +while :; do + link ${n0}/${n1} ${n0}/${i} >/dev/null 2>&1 + if [ $? -ne 0 ]; then + break + fi + i=`expr $i + 1` +done +test_check $i -eq 32767 + +expect EMLINK link ${n0}/${n1} ${n0}/${n2} + +umount /dev/md${n} +mdconfig -d -u ${n} +expect 0 rmdir ${n0} diff --git a/tests/link/06.t b/tests/link/06.t new file mode 100644 index 000000000000..73ab01e9ae15 --- /dev/null +++ b/tests/link/06.t @@ -0,0 +1,43 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/link/06.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="link returns EACCES when a component of either path prefix denies search permission" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..18" + +n0=`namegen` +n1=`namegen` +n2=`namegen` +n3=`namegen` +n4=`namegen` + +expect 0 mkdir ${n0} 0755 +cdir=`pwd` +cd ${n0} + +expect 0 mkdir ${n1} 0755 +expect 0 chown ${n1} 65534 65534 +expect 0 mkdir ${n2} 0755 +expect 0 chown ${n2} 65534 65534 +expect 0 -u 65534 -g 65534 create ${n1}/${n3} 0644 + +expect 0 -u 65534 -g 65534 link ${n1}/${n3} ${n2}/${n4} +expect 0 -u 65534 -g 65534 unlink ${n2}/${n4} + +expect 0 chmod ${n1} 0644 +expect EACCES -u 65534 -g 65534 link ${n1}/${n3} ${n1}/${n4} +expect EACCES -u 65534 -g 65534 link ${n1}/${n3} ${n2}/${n4} + +expect 0 chmod ${n1} 0755 +expect 0 chmod ${n2} 0644 +expect EACCES -u 65534 -g 65534 link ${n1}/${n3} ${n2}/${n4} + +expect 0 unlink ${n1}/${n3} +expect 0 rmdir ${n1} +expect 0 rmdir ${n2} + +cd ${cdir} +expect 0 rmdir ${n0} diff --git a/tests/link/07.t b/tests/link/07.t new file mode 100644 index 000000000000..68495dd7c0b8 --- /dev/null +++ b/tests/link/07.t @@ -0,0 +1,41 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/link/07.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="link returns EACCES when the requested link requires writing in a directory with a mode that denies write permission" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..17" + +n0=`namegen` +n1=`namegen` +n2=`namegen` +n3=`namegen` +n4=`namegen` + +expect 0 mkdir ${n0} 0755 +cdir=`pwd` +cd ${n0} + +expect 0 mkdir ${n1} 0755 +expect 0 chown ${n1} 65534 65534 +expect 0 mkdir ${n2} 0755 +expect 0 chown ${n2} 65534 65534 +expect 0 -u 65534 -g 65534 create ${n1}/${n3} 0644 + +expect 0 -u 65534 -g 65534 link ${n1}/${n3} ${n2}/${n4} +expect 0 -u 65534 -g 65534 unlink ${n2}/${n4} + +expect 0 chmod ${n2} 0555 +expect EACCES -u 65534 -g 65534 link ${n1}/${n3} ${n2}/${n4} +expect 0 chmod ${n1} 0555 +expect EACCES -u 65534 -g 65534 link ${n1}/${n3} ${n1}/${n4} +expect 0 chmod ${n1} 0755 + +expect 0 unlink ${n1}/${n3} +expect 0 rmdir ${n1} +expect 0 rmdir ${n2} + +cd ${cdir} +expect 0 rmdir ${n0} diff --git a/tests/link/08.t b/tests/link/08.t new file mode 100644 index 000000000000..f4599d50f01b --- /dev/null +++ b/tests/link/08.t @@ -0,0 +1,24 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/link/08.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="link returns ELOOP if too many symbolic links were encountered in translating one of the pathnames" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..10" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 symlink ${n0} ${n1} +expect 0 symlink ${n1} ${n0} +expect ELOOP link ${n0}/test ${n2} +expect ELOOP link ${n1}/test ${n2} +expect 0 create ${n2} 0644 +expect ELOOP link ${n2} ${n0}/test +expect ELOOP link ${n2} ${n1}/test +expect 0 unlink ${n0} +expect 0 unlink ${n1} +expect 0 unlink ${n2} diff --git a/tests/link/09.t b/tests/link/09.t new file mode 100644 index 000000000000..5f89655d3610 --- /dev/null +++ b/tests/link/09.t @@ -0,0 +1,18 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/link/09.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="link returns ENOENT if the source file does not exist" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..5" + +n0=`namegen` +n1=`namegen` + +expect 0 create ${n0} 0644 +expect 0 link ${n0} ${n1} +expect 0 unlink ${n0} +expect 0 unlink ${n1} +expect ENOENT link ${n0} ${n1} diff --git a/tests/link/10.t b/tests/link/10.t new file mode 100644 index 000000000000..03ebbd25ffdb --- /dev/null +++ b/tests/link/10.t @@ -0,0 +1,26 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/link/10.t 211474 2010-08-18 22:06:43Z pjd $ + +desc="link returns EEXIST if the destination file does exist" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..23" + +n0=`namegen` +n1=`namegen` + +expect 0 create ${n0} 0644 + +for type in regular dir fifo block char socket symlink; do + create_file ${type} ${n1} + expect EEXIST link ${n0} ${n1} + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n1} + else + expect 0 unlink ${n1} + fi +done + +expect 0 unlink ${n0} diff --git a/tests/link/11.t b/tests/link/11.t new file mode 100644 index 000000000000..260342cd1d31 --- /dev/null +++ b/tests/link/11.t @@ -0,0 +1,41 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/link/11.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="link returns EPERM if the source file is a directory" + +dir=`dirname $0` +. ${dir}/../misc.sh + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +case "${os}:${fs}" in +SunOS:UFS) + echo "1..10" + + expect 0 mkdir ${n0} 0755 + expect 0 link ${n0} ${n1} + expect 0 unlink ${n1} + expect 0 rmdir ${n0} + ;; +*) + echo "1..9" + + expect 0 mkdir ${n0} 0755 + expect EPERM link ${n0} ${n1} + expect 0 rmdir ${n0} + ;; +esac + +expect 0 mkdir ${n0} 0755 +expect 0 chown ${n0} 65534 65534 +cdir=`pwd` +cd ${n0} + +expect 0 -u 65534 -g 65534 mkdir ${n1} 0755 +expect EPERM -u 65534 -g 65534 link ${n1} ${n2} +expect 0 -u 65534 -g 65534 rmdir ${n1} + +cd ${cdir} +expect 0 rmdir ${n0} diff --git a/tests/link/12.t b/tests/link/12.t new file mode 100644 index 000000000000..a5408b656418 --- /dev/null +++ b/tests/link/12.t @@ -0,0 +1,95 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/link/12.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="link returns EPERM if the source file has its immutable or append-only flag set" + +dir=`dirname $0` +. ${dir}/../misc.sh + +require chflags + +case "${os}:${fs}" in +FreeBSD:ZFS) + echo "1..27" + ;; +FreeBSD:UFS) + echo "1..48" + ;; +*) + quick_exit +esac + +n0=`namegen` +n1=`namegen` + +expect 0 create ${n0} 0644 + +expect 1 stat ${n0} nlink +expect 0 link ${n0} ${n1} +expect 2 stat ${n0} nlink +expect 0 unlink ${n1} +expect 1 stat ${n0} nlink + +expect 0 chflags ${n0} SF_IMMUTABLE +todo FreeBSD:ZFS "Creating a hard link to a file protected by SF_IMMUTABLE should return EPERM." +expect EPERM link ${n0} ${n1} +todo FreeBSD:ZFS "Creating a hard link to a file protected by SF_IMMUTABLE should return EPERM." +expect 1 stat ${n0} nlink +expect 0 chflags ${n0} none +todo FreeBSD:ZFS "Creating a hard link to a file protected by SF_IMMUTABLE should return EPERM." +expect 0 link ${n0} ${n1} +expect 2 stat ${n0} nlink +expect 0 unlink ${n1} +expect 1 stat ${n0} nlink + +expect 0 chflags ${n0} SF_NOUNLINK +expect 0 link ${n0} ${n1} +expect 2 stat ${n0} nlink +expect 0 chflags ${n0} none +expect 0 unlink ${n1} +expect 1 stat ${n0} nlink + +case "${os}:${fs}" in +FreeBSD:ZFS) + expect 0 chflags ${n0} SF_APPEND + expect 0 link ${n0} ${n1} + expect 2 stat ${n0} nlink + expect 0 chflags ${n0} none + expect 0 unlink ${n1} + expect 1 stat ${n0} nlink + ;; +FreeBSD:UFS) + expect 0 chflags ${n0} SF_APPEND + expect EPERM link ${n0} ${n1} + expect 0 chflags ${n0} none + expect 0 link ${n0} ${n1} + expect 2 stat ${n0} nlink + expect 0 unlink ${n1} + expect 1 stat ${n0} nlink + + expect 0 chflags ${n0} UF_IMMUTABLE + expect EPERM link ${n0} ${n1} + expect 0 chflags ${n0} none + expect 0 link ${n0} ${n1} + expect 2 stat ${n0} nlink + expect 0 unlink ${n1} + expect 1 stat ${n0} nlink + + expect 0 chflags ${n0} UF_NOUNLINK + expect 0 link ${n0} ${n1} + expect 2 stat ${n0} nlink + expect 0 chflags ${n0} none + expect 0 unlink ${n1} + expect 1 stat ${n0} nlink + + expect 0 chflags ${n0} UF_APPEND + expect EPERM link ${n0} ${n1} + expect 0 chflags ${n0} none + expect 0 link ${n0} ${n1} + expect 2 stat ${n0} nlink + expect 0 unlink ${n1} + expect 1 stat ${n0} nlink + ;; +esac + +expect 0 unlink ${n0} diff --git a/tests/link/13.t b/tests/link/13.t new file mode 100644 index 000000000000..2da8621f23cc --- /dev/null +++ b/tests/link/13.t @@ -0,0 +1,86 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/link/13.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="link returns EPERM if the parent directory of the destination file has its immutable flag set" + +dir=`dirname $0` +. ${dir}/../misc.sh + +require chflags + +case "${os}:${fs}" in +FreeBSD:ZFS) + echo "1..29" + ;; +FreeBSD:UFS) + echo "1..49" + ;; +*) + quick_exit +esac + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n0} 0755 + +expect 0 create ${n0}/${n1} 0644 +expect 1 stat ${n0}/${n1} nlink +expect 0 link ${n0}/${n1} ${n0}/${n2} +expect 2 stat ${n0}/${n1} nlink +expect 0 unlink ${n0}/${n2} +expect 1 stat ${n0}/${n1} nlink + +expect 0 chflags ${n0} SF_IMMUTABLE +expect EPERM link ${n0}/${n1} ${n0}/${n2} +expect 1 stat ${n0}/${n1} nlink +expect 0 chflags ${n0} none +expect 0 link ${n0}/${n1} ${n0}/${n2} +expect 2 stat ${n0}/${n1} nlink +expect 0 unlink ${n0}/${n2} +expect 1 stat ${n0}/${n1} nlink + +expect 0 chflags ${n0} SF_NOUNLINK +expect 0 link ${n0}/${n1} ${n0}/${n2} +expect 2 stat ${n0}/${n1} nlink +expect 0 chflags ${n0} none +expect 0 unlink ${n0}/${n2} +expect 1 stat ${n0}/${n1} nlink + +expect 0 chflags ${n0} SF_APPEND +expect 0 link ${n0}/${n1} ${n0}/${n2} +expect 2 stat ${n0}/${n1} nlink +expect 0 chflags ${n0} none +expect 0 unlink ${n0}/${n2} +expect 1 stat ${n0}/${n1} nlink + +case "${os}:${fs}" in +FreeBSD:UFS) + expect 0 chflags ${n0} UF_IMMUTABLE + expect EPERM link ${n0}/${n1} ${n0}/${n2} + expect 1 stat ${n0}/${n1} nlink + expect 0 chflags ${n0} none + expect 0 link ${n0}/${n1} ${n0}/${n2} + expect 2 stat ${n0}/${n1} nlink + expect 0 unlink ${n0}/${n2} + expect 1 stat ${n0}/${n1} nlink + + expect 0 chflags ${n0} UF_NOUNLINK + expect 0 link ${n0}/${n1} ${n0}/${n2} + expect 2 stat ${n0}/${n1} nlink + expect 0 chflags ${n0} none + expect 0 unlink ${n0}/${n2} + expect 1 stat ${n0}/${n1} nlink + + expect 0 chflags ${n0} UF_APPEND + expect 0 link ${n0}/${n1} ${n0}/${n2} + expect 2 stat ${n0}/${n1} nlink + expect 0 chflags ${n0} none + expect 0 unlink ${n0}/${n2} + expect 1 stat ${n0}/${n1} nlink + ;; +esac + +expect 0 unlink ${n0}/${n1} +expect 0 rmdir ${n0} diff --git a/tests/link/14.t b/tests/link/14.t new file mode 100644 index 000000000000..3a05dc0d10bc --- /dev/null +++ b/tests/link/14.t @@ -0,0 +1,29 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/link/14.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="link returns EXDEV if the source and the destination files are on different file systems" + +dir=`dirname $0` +. ${dir}/../misc.sh + +[ "${os}" = "FreeBSD" ] || quick_exit + +echo "1..8" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n0} 0755 +n=`mdconfig -a -n -t malloc -s 1m` +newfs /dev/md${n} >/dev/null +mount /dev/md${n} ${n0} +expect 0 create ${n0}/${n1} 0644 +expect EXDEV link ${n0}/${n1} ${n2} +expect 0 unlink ${n0}/${n1} +expect 0 create ${n1} 0644 +expect EXDEV link ${n1} ${n0}/${n2} +expect 0 unlink ${n1} +umount /dev/md${n} +mdconfig -d -u ${n} +expect 0 rmdir ${n0} diff --git a/tests/link/15.t b/tests/link/15.t new file mode 100644 index 000000000000..972176bed08f --- /dev/null +++ b/tests/link/15.t @@ -0,0 +1,33 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/link/15.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="link returns ENOSPC if the directory in which the entry for the new link is being placed cannot be extended because there is no space left on the file system containing the directory" + +dir=`dirname $0` +. ${dir}/../misc.sh + +[ "${os}:${fs}" = "FreeBSD:UFS" ] || quick_exit + +echo "1..4" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n0} 0755 +n=`mdconfig -a -n -t malloc -s 256k` +newfs /dev/md${n} >/dev/null +mount /dev/md${n} ${n0} +expect 0 create ${n0}/${n1} 0644 +i=0 +while :; do + link ${n0}/${n1} ${n0}/${i} >/dev/null 2>&1 + if [ $? -ne 0 ]; then + break + fi + i=`expr $i + 1` +done +expect ENOSPC link ${n0}/${n1} ${n0}/${n2} +umount /dev/md${n} +mdconfig -d -u ${n} +expect 0 rmdir ${n0} diff --git a/tests/link/16.t b/tests/link/16.t new file mode 100644 index 000000000000..56485ec1bee9 --- /dev/null +++ b/tests/link/16.t @@ -0,0 +1,34 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/link/16.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="link returns EROFS if the requested link requires writing in a directory on a read-only file system" + +dir=`dirname $0` +. ${dir}/../misc.sh + +[ "${os}" = "FreeBSD" ] || quick_exit + +echo "1..9" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n0} 0755 +n=`mdconfig -a -n -t malloc -s 1m` +newfs /dev/md${n} >/dev/null +mount /dev/md${n} ${n0} +expect 0 create ${n0}/${n1} 0644 + +expect 0 link ${n0}/${n1} ${n0}/${n2} +expect 0 unlink ${n0}/${n2} +mount -ur /dev/md${n} +expect EROFS link ${n0}/${n1} ${n0}/${n2} +mount -uw /dev/md${n} +expect 0 link ${n0}/${n1} ${n0}/${n2} +expect 0 unlink ${n0}/${n2} + +expect 0 unlink ${n0}/${n1} +umount /dev/md${n} +mdconfig -d -u ${n} +expect 0 rmdir ${n0} diff --git a/tests/link/17.t b/tests/link/17.t new file mode 100644 index 000000000000..9b7e6fc68366 --- /dev/null +++ b/tests/link/17.t @@ -0,0 +1,20 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/link/17.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="link returns EFAULT if one of the pathnames specified is outside the process's allocated address space" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..8" + +n0=`namegen` + +expect 0 create ${n0} 0644 +expect EFAULT link ${n0} NULL +expect EFAULT link ${n0} DEADCODE +expect 0 unlink ${n0} +expect EFAULT link NULL ${n0} +expect EFAULT link DEADCODE ${n0} +expect EFAULT link NULL DEADCODE +expect EFAULT link DEADCODE NULL diff --git a/tests/misc.sh b/tests/misc.sh new file mode 100755 index 000000000000..8978b5fcc6a9 --- /dev/null +++ b/tests/misc.sh @@ -0,0 +1,221 @@ +# $FreeBSD$ + +ntest=1 + +case "${dir}" in +/*) + maindir="${dir}/../.." + ;; +*) + maindir="`pwd`/${dir}/../.." + ;; +esac +fstest="${maindir}/pjdfstest" +. ${maindir}/tests/conf + +expect() +{ + e="${1}" + shift + r=`${fstest} $* 2>/dev/null | tail -1` + echo "${r}" | ${GREP} -Eq '^'${e}'$' + if [ $? -eq 0 ]; then + if [ -z "${todomsg}" ]; then + echo "ok ${ntest}" + else + echo "ok ${ntest} # TODO ${todomsg}" + fi + else + if [ -z "${todomsg}" ]; then + echo "not ok ${ntest} - tried '$*', expected ${e}, got ${r}" + else + echo "not ok ${ntest} # TODO ${todomsg}" + fi + fi + todomsg="" + ntest=$((ntest+1)) +} + +jexpect() +{ + s="${1}" + d="${2}" + e="${3}" + shift 3 + r=`jail -s ${s} / pjdfstest 127.0.0.1 /bin/sh -c "cd ${d} && ${fstest} $* 2>/dev/null" | tail -1` + echo "${r}" | ${GREP} -Eq '^'${e}'$' + if [ $? -eq 0 ]; then + if [ -z "${todomsg}" ]; then + echo "ok ${ntest}" + else + echo "ok ${ntest} # TODO ${todomsg}" + fi + else + if [ -z "${todomsg}" ]; then + echo "not ok ${ntest} - tried '$*', expected ${e}, got ${r}" + else + echo "not ok ${ntest} # TODO ${todomsg}" + fi + fi + todomsg="" + ntest=$((ntest+1)) +} + +test_check() +{ + if [ $* ]; then + if [ -z "${todomsg}" ]; then + echo "ok ${ntest}" + else + echo "ok ${ntest} # TODO ${todomsg}" + fi + else + if [ -z "${todomsg}" ]; then + echo "not ok ${ntest}" + else + echo "not ok ${ntest} # TODO ${todomsg}" + fi + fi + todomsg="" + ntest=$((ntest+1)) +} + +todo() +{ + if [ "${os}" = "${1}" -o "${os}:${fs}" = "${1}" ]; then + todomsg="${2}" + fi +} + +namegen() +{ + echo "pjdfstest_`dd if=/dev/urandom bs=1k count=1 2>/dev/null | openssl md5 | awk '{print $NF}'`" +} + +namegen_len() +{ + len="${1}" + + name="" + while :; do + namepart="`dd if=/dev/urandom bs=64 count=1 2>/dev/null | openssl md5 | awk '{print $NF}'`" + name="${name}${namepart}" + curlen=`printf "%s" "${name}" | wc -c` + [ ${curlen} -lt ${len} ] || break + done + name=`echo "${name}" | cut -b -${len}` + printf "%s" "${name}" +} + +# POSIX: +# {NAME_MAX} +# Maximum number of bytes in a filename (not including terminating null). +namegen_max() +{ + name_max=`${fstest} pathconf . _PC_NAME_MAX` + namegen_len ${name_max} +} + +# POSIX: +# {PATH_MAX} +# Maximum number of bytes in a pathname, including the terminating null character. +dirgen_max() +{ + name_max=`${fstest} pathconf . _PC_NAME_MAX` + complen=$((name_max/2)) + path_max=`${fstest} pathconf . _PC_PATH_MAX` + # "...including the terminating null character." + path_max=$((path_max-1)) + + name="" + while :; do + name="${name}`namegen_len ${complen}`/" + curlen=`printf "%s" "${name}" | wc -c` + [ ${curlen} -lt ${path_max} ] || break + done + name=`echo "${name}" | cut -b -${path_max}` + name=`echo "${name}" | sed -E 's@/$@x@'` + printf "%s" "${name}" +} + +quick_exit() +{ + echo "1..1" + echo "ok 1" + exit 0 +} + +supported() +{ + case "${1}" in + lchmod) + if [ "${os}" != "FreeBSD" ]; then + return 1 + fi + ;; + chflags) + if [ "${os}" != "FreeBSD" ]; then + return 1 + fi + ;; + chflags_SF_SNAPSHOT) + if [ "${os}" != "FreeBSD" -o "${fs}" != "UFS" ]; then + return 1 + fi + ;; + esac + return 0 +} + +require() +{ + if supported ${1}; then + return + fi + quick_exit +} + +# usage: +# create_file +# create_file +# create_file +# create_file +create_file() { + type="${1}" + name="${2}" + + case "${type}" in + none) + return + ;; + regular) + expect 0 create ${name} 0644 + ;; + dir) + expect 0 mkdir ${name} 0755 + ;; + fifo) + expect 0 mkfifo ${name} 0644 + ;; + block) + expect 0 mknod ${name} b 0644 1 2 + ;; + char) + expect 0 mknod ${name} c 0644 1 2 + ;; + socket) + expect 0 bind ${name} + ;; + symlink) + expect 0 symlink test ${name} + ;; + esac + if [ -n "${3}" -a -n "${4}" -a -n "${5}" ]; then + expect 0 lchmod ${name} ${3} + expect 0 lchown ${name} ${4} ${5} + elif [ -n "${3}" -a -n "${4}" ]; then + expect 0 lchown ${name} ${3} ${4} + elif [ -n "${3}" ]; then + expect 0 lchmod ${name} ${3} + fi +} diff --git a/tests/mkdir/00.t b/tests/mkdir/00.t new file mode 100644 index 000000000000..fa1cbc126ebe --- /dev/null +++ b/tests/mkdir/00.t @@ -0,0 +1,73 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/mkdir/00.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="mkdir creates directories" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..36" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n1} 0755 +cdir=`pwd` +cd ${n1} + +# POSIX: The file permission bits of the new directory shall be initialized from +# mode. These file permission bits of the mode argument shall be modified by the +# process' file creation mask. +expect 0 mkdir ${n0} 0755 +expect dir,0755 lstat ${n0} type,mode +expect 0 rmdir ${n0} +expect 0 mkdir ${n0} 0151 +expect dir,0151 lstat ${n0} type,mode +expect 0 rmdir ${n0} +expect 0 -U 077 mkdir ${n0} 0151 +expect dir,0100 lstat ${n0} type,mode +expect 0 rmdir ${n0} +expect 0 -U 070 mkdir ${n0} 0345 +expect dir,0305 lstat ${n0} type,mode +expect 0 rmdir ${n0} +expect 0 -U 0501 mkdir ${n0} 0345 +expect dir,0244 lstat ${n0} type,mode +expect 0 rmdir ${n0} + +# POSIX: The directory's user ID shall be set to the process' effective user ID. +# The directory's group ID shall be set to the group ID of the parent directory +# or to the effective group ID of the process. +expect 0 chown . 65535 65535 +expect 0 -u 65535 -g 65535 mkdir ${n0} 0755 +expect 65535,65535 lstat ${n0} uid,gid +expect 0 rmdir ${n0} +expect 0 -u 65535 -g 65534 mkdir ${n0} 0755 +expect "65535,6553[45]" lstat ${n0} uid,gid +expect 0 rmdir ${n0} +expect 0 chmod . 0777 +expect 0 -u 65534 -g 65533 mkdir ${n0} 0755 +expect "65534,6553[35]" lstat ${n0} uid,gid +expect 0 rmdir ${n0} + +# POSIX: Upon successful completion, mkdir() shall mark for update the st_atime, +# st_ctime, and st_mtime fields of the directory. Also, the st_ctime and +# st_mtime fields of the directory that contains the new entry shall be marked +# for update. +expect 0 chown . 0 0 +time=`${fstest} stat . ctime` +sleep 1 +expect 0 mkdir ${n0} 0755 +atime=`${fstest} stat ${n0} atime` +test_check $time -lt $atime +mtime=`${fstest} stat ${n0} mtime` +test_check $time -lt $mtime +ctime=`${fstest} stat ${n0} ctime` +test_check $time -lt $ctime +mtime=`${fstest} stat . mtime` +test_check $time -lt $mtime +ctime=`${fstest} stat . ctime` +test_check $time -lt $ctime +expect 0 rmdir ${n0} + +cd ${cdir} +expect 0 rmdir ${n1} diff --git a/tests/mkdir/01.t b/tests/mkdir/01.t new file mode 100644 index 000000000000..c33ce1fe9a09 --- /dev/null +++ b/tests/mkdir/01.t @@ -0,0 +1,20 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/mkdir/01.t 211474 2010-08-18 22:06:43Z pjd $ + +desc="mkdir returns ENOTDIR if a component of the path prefix is not a directory" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..17" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +for type in regular fifo block char socket; do + create_file ${type} ${n0}/${n1} + expect ENOTDIR mkdir ${n0}/${n1}/test 0755 + expect 0 unlink ${n0}/${n1} +done +expect 0 rmdir ${n0} diff --git a/tests/mkdir/02.t b/tests/mkdir/02.t new file mode 100644 index 000000000000..e877f20f4c10 --- /dev/null +++ b/tests/mkdir/02.t @@ -0,0 +1,16 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/mkdir/02.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="mkdir returns ENAMETOOLONG if a component of a pathname exceeded {NAME_MAX} characters" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..3" + +nx=`namegen_max` +nxx="${nx}x" + +expect 0 mkdir ${nx} 0755 +expect 0 rmdir ${nx} +expect ENAMETOOLONG mkdir ${nxx} 0755 diff --git a/tests/mkdir/03.t b/tests/mkdir/03.t new file mode 100644 index 000000000000..57ddd20a8627 --- /dev/null +++ b/tests/mkdir/03.t @@ -0,0 +1,20 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/mkdir/03.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="mkdir returns ENAMETOOLONG if an entire path name exceeded {PATH_MAX} characters" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..3" + +nx=`dirgen_max` +nxx="${nx}x" + +mkdir -p "${nx%/*}" + +expect 0 mkdir ${nx} 0755 +expect 0 rmdir ${nx} +expect ENAMETOOLONG mkdir ${nxx} 0755 + +rm -rf "${nx%%/*}" diff --git a/tests/mkdir/04.t b/tests/mkdir/04.t new file mode 100644 index 000000000000..0917ef15516d --- /dev/null +++ b/tests/mkdir/04.t @@ -0,0 +1,16 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/mkdir/04.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="mkdir returns ENOENT if a component of the path prefix does not exist" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..3" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +expect ENOENT mkdir ${n0}/${n1}/test 0755 +expect 0 rmdir ${n0} diff --git a/tests/mkdir/05.t b/tests/mkdir/05.t new file mode 100644 index 000000000000..de351ca37ca7 --- /dev/null +++ b/tests/mkdir/05.t @@ -0,0 +1,29 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/mkdir/05.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="mkdir returns EACCES when search permission is denied for a component of the path prefix" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..12" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n0} 0755 +cdir=`pwd` +cd ${n0} +expect 0 mkdir ${n1} 0755 +expect 0 chown ${n1} 65534 65534 +expect 0 -u 65534 -g 65534 mkdir ${n1}/${n2} 0755 +expect 0 -u 65534 -g 65534 rmdir ${n1}/${n2} +expect 0 chmod ${n1} 0644 +expect EACCES -u 65534 -g 65534 mkdir ${n1}/${n2} 0755 +expect 0 chmod ${n1} 0755 +expect 0 -u 65534 -g 65534 mkdir ${n1}/${n2} 0755 +expect 0 -u 65534 -g 65534 rmdir ${n1}/${n2} +expect 0 rmdir ${n1} +cd ${cdir} +expect 0 rmdir ${n0} diff --git a/tests/mkdir/06.t b/tests/mkdir/06.t new file mode 100644 index 000000000000..2d2b8c22234b --- /dev/null +++ b/tests/mkdir/06.t @@ -0,0 +1,29 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/mkdir/06.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="mkdir returns EACCES when write permission is denied on the parent directory of the directory to be created" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..12" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n0} 0755 +cdir=`pwd` +cd ${n0} +expect 0 mkdir ${n1} 0755 +expect 0 chown ${n1} 65534 65534 +expect 0 -u 65534 -g 65534 mkdir ${n1}/${n2} 0755 +expect 0 -u 65534 -g 65534 rmdir ${n1}/${n2} +expect 0 chmod ${n1} 0555 +expect EACCES -u 65534 -g 65534 mkdir ${n1}/${n2} 0755 +expect 0 chmod ${n1} 0755 +expect 0 -u 65534 -g 65534 mkdir ${n1}/${n2} 0755 +expect 0 -u 65534 -g 65534 rmdir ${n1}/${n2} +expect 0 rmdir ${n1} +cd ${cdir} +expect 0 rmdir ${n0} diff --git a/tests/mkdir/07.t b/tests/mkdir/07.t new file mode 100644 index 000000000000..72ac2b69499f --- /dev/null +++ b/tests/mkdir/07.t @@ -0,0 +1,19 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/mkdir/07.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="mkdir returns ELOOP if too many symbolic links were encountered in translating the pathname" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..6" + +n0=`namegen` +n1=`namegen` + +expect 0 symlink ${n0} ${n1} +expect 0 symlink ${n1} ${n0} +expect ELOOP mkdir ${n0}/test 0755 +expect ELOOP mkdir ${n1}/test 0755 +expect 0 unlink ${n0} +expect 0 unlink ${n1} diff --git a/tests/mkdir/08.t b/tests/mkdir/08.t new file mode 100644 index 000000000000..366f223a8074 --- /dev/null +++ b/tests/mkdir/08.t @@ -0,0 +1,66 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/mkdir/08.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="mkdir returns EPERM if the parent directory of the directory to be created has its immutable flag set" + +dir=`dirname $0` +. ${dir}/../misc.sh + +require chflags + +case "${os}:${fs}" in +FreeBSD:ZFS) + echo "1..17" + ;; +FreeBSD:UFS) + echo "1..30" + ;; +*) + quick_exit +esac + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 + +expect 0 mkdir ${n0}/${n1} 0755 +expect 0 rmdir ${n0}/${n1} + +expect 0 chflags ${n0} SF_IMMUTABLE +expect EPERM mkdir ${n0}/${n1} 0755 +expect 0 chflags ${n0} none +expect 0 mkdir ${n0}/${n1} 0755 +expect 0 rmdir ${n0}/${n1} + +expect 0 chflags ${n0} SF_NOUNLINK +expect 0 mkdir ${n0}/${n1} 0755 +expect 0 rmdir ${n0}/${n1} +expect 0 chflags ${n0} none + +expect 0 chflags ${n0} SF_APPEND +expect 0 mkdir ${n0}/${n1} 0755 +expect 0 chflags ${n0} none +expect 0 rmdir ${n0}/${n1} + +case "${os}:${fs}" in +FreeBSD:UFS) + expect 0 chflags ${n0} UF_IMMUTABLE + expect EPERM mkdir ${n0}/${n1} 0755 + expect 0 chflags ${n0} none + expect 0 mkdir ${n0}/${n1} 0755 + expect 0 rmdir ${n0}/${n1} + + expect 0 chflags ${n0} UF_NOUNLINK + expect 0 mkdir ${n0}/${n1} 0755 + expect 0 rmdir ${n0}/${n1} + expect 0 chflags ${n0} none + + expect 0 chflags ${n0} UF_APPEND + expect 0 mkdir ${n0}/${n1} 0755 + expect 0 chflags ${n0} none + expect 0 rmdir ${n0}/${n1} + ;; +esac + +expect 0 rmdir ${n0} diff --git a/tests/mkdir/09.t b/tests/mkdir/09.t new file mode 100644 index 000000000000..502672e73b70 --- /dev/null +++ b/tests/mkdir/09.t @@ -0,0 +1,29 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/mkdir/09.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="mkdir returns EROFS if the named file resides on a read-only file system" + +dir=`dirname $0` +. ${dir}/../misc.sh + +[ "${os}:${fs}" = "FreeBSD:UFS" ] || quick_exit + +echo "1..7" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +n=`mdconfig -a -n -t malloc -s 1m` +newfs /dev/md${n} >/dev/null +mount /dev/md${n} ${n0} +expect 0 mkdir ${n0}/${n1} 0755 +expect 0 rmdir ${n0}/${n1} +mount -ur /dev/md${n} +expect EROFS mkdir ${n0}/${n1} 0755 +mount -uw /dev/md${n} +expect 0 mkdir ${n0}/${n1} 0755 +expect 0 rmdir ${n0}/${n1} +umount /dev/md${n} +mdconfig -d -u ${n} +expect 0 rmdir ${n0} diff --git a/tests/mkdir/10.t b/tests/mkdir/10.t new file mode 100644 index 000000000000..732dcb882562 --- /dev/null +++ b/tests/mkdir/10.t @@ -0,0 +1,21 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/mkdir/10.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="mkdir returns EEXIST if the named file exists" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..21" + +n0=`namegen` + +for type in regular dir fifo block char socket symlink; do + create_file ${type} ${n0} + expect EEXIST mkdir ${n0} 0755 + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n0} + else + expect 0 unlink ${n0} + fi +done diff --git a/tests/mkdir/11.t b/tests/mkdir/11.t new file mode 100644 index 000000000000..0c400c16db96 --- /dev/null +++ b/tests/mkdir/11.t @@ -0,0 +1,31 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/mkdir/11.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="mkdir returns ENOSPC if there are no free inodes on the file system on which the directory is being created" + +dir=`dirname $0` +. ${dir}/../misc.sh + +[ "${os}:${fs}" = "FreeBSD:UFS" ] || quick_exit + +echo "1..3" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +n=`mdconfig -a -n -t malloc -s 256k` +newfs /dev/md${n} >/dev/null +mount /dev/md${n} ${n0} +i=0 +while :; do + mkdir ${n0}/${i} >/dev/null 2>&1 + if [ $? -ne 0 ]; then + break + fi + i=`expr $i + 1` +done +expect ENOSPC mkdir ${n0}/${n1} 0755 +umount /dev/md${n} +mdconfig -d -u ${n} +expect 0 rmdir ${n0} diff --git a/tests/mkdir/12.t b/tests/mkdir/12.t new file mode 100644 index 000000000000..7c27f74264f6 --- /dev/null +++ b/tests/mkdir/12.t @@ -0,0 +1,12 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/mkdir/12.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="mkdir returns EFAULT if the path argument points outside the process's allocated address space" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..2" + +expect EFAULT mkdir NULL 0755 +expect EFAULT mkdir DEADCODE 0755 diff --git a/tests/mkfifo/00.t b/tests/mkfifo/00.t new file mode 100644 index 000000000000..ad88e2836fbb --- /dev/null +++ b/tests/mkfifo/00.t @@ -0,0 +1,73 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/mkfifo/00.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="mkfifo creates fifo files" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..36" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n1} 0755 +cdir=`pwd` +cd ${n1} + +# POSIX: The file permission bits of the new FIFO shall be initialized from +# mode. The file permission bits of the mode argument shall be modified by the +# process' file creation mask. +expect 0 mkfifo ${n0} 0755 +expect fifo,0755 lstat ${n0} type,mode +expect 0 unlink ${n0} +expect 0 mkfifo ${n0} 0151 +expect fifo,0151 lstat ${n0} type,mode +expect 0 unlink ${n0} +expect 0 -U 077 mkfifo ${n0} 0151 +expect fifo,0100 lstat ${n0} type,mode +expect 0 unlink ${n0} +expect 0 -U 070 mkfifo ${n0} 0345 +expect fifo,0305 lstat ${n0} type,mode +expect 0 unlink ${n0} +expect 0 -U 0501 mkfifo ${n0} 0345 +expect fifo,0244 lstat ${n0} type,mode +expect 0 unlink ${n0} + +# POSIX: The FIFO's user ID shall be set to the process' effective user ID. +# The FIFO's group ID shall be set to the group ID of the parent directory or to +# the effective group ID of the process. +expect 0 chown . 65535 65535 +expect 0 -u 65535 -g 65535 mkfifo ${n0} 0755 +expect 65535,65535 lstat ${n0} uid,gid +expect 0 unlink ${n0} +expect 0 -u 65535 -g 65534 mkfifo ${n0} 0755 +expect "65535,6553[45]" lstat ${n0} uid,gid +expect 0 unlink ${n0} +expect 0 chmod . 0777 +expect 0 -u 65534 -g 65533 mkfifo ${n0} 0755 +expect "65534,6553[35]" lstat ${n0} uid,gid +expect 0 unlink ${n0} + +# POSIX: Upon successful completion, mkfifo() shall mark for update the +# st_atime, st_ctime, and st_mtime fields of the file. Also, the st_ctime and +# st_mtime fields of the directory that contains the new entry shall be marked +# for update. +expect 0 chown . 0 0 +time=`${fstest} stat . ctime` +sleep 1 +expect 0 mkfifo ${n0} 0755 +atime=`${fstest} stat ${n0} atime` +test_check $time -lt $atime +mtime=`${fstest} stat ${n0} mtime` +test_check $time -lt $mtime +ctime=`${fstest} stat ${n0} ctime` +test_check $time -lt $ctime +mtime=`${fstest} stat . mtime` +test_check $time -lt $mtime +ctime=`${fstest} stat . ctime` +test_check $time -lt $ctime +expect 0 unlink ${n0} + +cd ${cdir} +expect 0 rmdir ${n1} diff --git a/tests/mkfifo/01.t b/tests/mkfifo/01.t new file mode 100644 index 000000000000..fae5c23091bc --- /dev/null +++ b/tests/mkfifo/01.t @@ -0,0 +1,20 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/mkfifo/01.t 211474 2010-08-18 22:06:43Z pjd $ + +desc="mkfifo returns ENOTDIR if a component of the path prefix is not a directory" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..17" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +for type in regular fifo block char socket; do + create_file ${type} ${n0}/${n1} + expect ENOTDIR mkfifo ${n0}/${n1}/test 0644 + expect 0 unlink ${n0}/${n1} +done +expect 0 rmdir ${n0} diff --git a/tests/mkfifo/02.t b/tests/mkfifo/02.t new file mode 100644 index 000000000000..e51bcd5fdff2 --- /dev/null +++ b/tests/mkfifo/02.t @@ -0,0 +1,17 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/mkfifo/02.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="mkfifo returns ENAMETOOLONG if a component of a pathname exceeded {NAME_MAX} characters" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..4" + +nx=`namegen_max` +nxx="${nx}x" + +expect 0 mkfifo ${nx} 0644 +expect fifo,0644 stat ${nx} type,mode +expect 0 unlink ${nx} +expect ENAMETOOLONG mkfifo ${nxx} 0644 diff --git a/tests/mkfifo/03.t b/tests/mkfifo/03.t new file mode 100644 index 000000000000..06265293517b --- /dev/null +++ b/tests/mkfifo/03.t @@ -0,0 +1,21 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/mkfifo/03.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="mkfifo returns ENAMETOOLONG if an entire path name exceeded {PATH_MAX} characters" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..4" + +nx=`dirgen_max` +nxx="${nx}x" + +mkdir -p "${nx%/*}" + +expect 0 mkfifo ${nx} 0644 +expect fifo stat ${nx} type +expect 0 unlink ${nx} +expect ENAMETOOLONG mkfifo ${nxx} 0644 + +rm -rf "${nx%%/*}" diff --git a/tests/mkfifo/04.t b/tests/mkfifo/04.t new file mode 100644 index 000000000000..981015808a18 --- /dev/null +++ b/tests/mkfifo/04.t @@ -0,0 +1,16 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/mkfifo/04.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="mkfifo returns ENOENT if a component of the path prefix does not exist" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..3" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +expect ENOENT mkfifo ${n0}/${n1}/test 0644 +expect 0 rmdir ${n0} diff --git a/tests/mkfifo/05.t b/tests/mkfifo/05.t new file mode 100644 index 000000000000..a9510e284841 --- /dev/null +++ b/tests/mkfifo/05.t @@ -0,0 +1,29 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/mkfifo/05.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="mkfifo returns EACCES when search permission is denied for a component of the path prefix" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..12" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n0} 0755 +cdir=`pwd` +cd ${n0} +expect 0 mkdir ${n1} 0755 +expect 0 chown ${n1} 65534 65534 +expect 0 -u 65534 -g 65534 mkfifo ${n1}/${n2} 0644 +expect 0 -u 65534 -g 65534 unlink ${n1}/${n2} +expect 0 chmod ${n1} 0644 +expect EACCES -u 65534 -g 65534 mkfifo ${n1}/${n2} 0644 +expect 0 chmod ${n1} 0755 +expect 0 -u 65534 -g 65534 mkfifo ${n1}/${n2} 0644 +expect 0 -u 65534 -g 65534 unlink ${n1}/${n2} +expect 0 rmdir ${n1} +cd ${cdir} +expect 0 rmdir ${n0} diff --git a/tests/mkfifo/06.t b/tests/mkfifo/06.t new file mode 100644 index 000000000000..a1fa76135152 --- /dev/null +++ b/tests/mkfifo/06.t @@ -0,0 +1,29 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/mkfifo/06.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="mkfifo returns EACCES when write permission is denied on the parent directory of the file to be created" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..12" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n0} 0755 +cdir=`pwd` +cd ${n0} +expect 0 mkdir ${n1} 0755 +expect 0 chown ${n1} 65534 65534 +expect 0 -u 65534 -g 65534 mkfifo ${n1}/${n2} 0644 +expect 0 -u 65534 -g 65534 unlink ${n1}/${n2} +expect 0 chmod ${n1} 0555 +expect EACCES -u 65534 -g 65534 mkfifo ${n1}/${n2} 0644 +expect 0 chmod ${n1} 0755 +expect 0 -u 65534 -g 65534 mkfifo ${n1}/${n2} 0644 +expect 0 -u 65534 -g 65534 unlink ${n1}/${n2} +expect 0 rmdir ${n1} +cd ${cdir} +expect 0 rmdir ${n0} diff --git a/tests/mkfifo/07.t b/tests/mkfifo/07.t new file mode 100644 index 000000000000..0ba1ac4bde30 --- /dev/null +++ b/tests/mkfifo/07.t @@ -0,0 +1,19 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/mkfifo/07.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="mkfifo returns ELOOP if too many symbolic links were encountered in translating the pathname" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..6" + +n0=`namegen` +n1=`namegen` + +expect 0 symlink ${n0} ${n1} +expect 0 symlink ${n1} ${n0} +expect ELOOP mkfifo ${n0}/test 0644 +expect ELOOP mkfifo ${n1}/test 0644 +expect 0 unlink ${n0} +expect 0 unlink ${n1} diff --git a/tests/mkfifo/08.t b/tests/mkfifo/08.t new file mode 100644 index 000000000000..7866c61362e5 --- /dev/null +++ b/tests/mkfifo/08.t @@ -0,0 +1,29 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/mkfifo/08.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="mkfifo returns EROFS if the named file resides on a read-only file system" + +dir=`dirname $0` +. ${dir}/../misc.sh + +[ "${os}:${fs}" = "FreeBSD:UFS" ] || quick_exit + +echo "1..7" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +n=`mdconfig -a -n -t malloc -s 1m` +newfs /dev/md${n} >/dev/null +mount /dev/md${n} ${n0} +expect 0 mkfifo ${n0}/${n1} 0644 +expect 0 unlink ${n0}/${n1} +mount -ur /dev/md${n} +expect EROFS mkfifo ${n0}/${n1} 0644 +mount -uw /dev/md${n} +expect 0 mkfifo ${n0}/${n1} 0644 +expect 0 unlink ${n0}/${n1} +umount /dev/md${n} +mdconfig -d -u ${n} +expect 0 rmdir ${n0} diff --git a/tests/mkfifo/09.t b/tests/mkfifo/09.t new file mode 100644 index 000000000000..15af5d106180 --- /dev/null +++ b/tests/mkfifo/09.t @@ -0,0 +1,21 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/mkfifo/09.t 211474 2010-08-18 22:06:43Z pjd $ + +desc="mkfifo returns EEXIST if the named file exists" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..21" + +n0=`namegen` + +for type in regular dir fifo block char socket symlink; do + create_file ${type} ${n0} + expect EEXIST mkfifo ${n0} 0644 + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n0} + else + expect 0 unlink ${n0} + fi +done diff --git a/tests/mkfifo/10.t b/tests/mkfifo/10.t new file mode 100644 index 000000000000..4c8bcab5ff21 --- /dev/null +++ b/tests/mkfifo/10.t @@ -0,0 +1,66 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/mkfifo/10.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="mkfifo returns EPERM if the parent directory of the file to be created has its immutable flag set" + +dir=`dirname $0` +. ${dir}/../misc.sh + +require chflags + +case "${os}:${fs}" in +FreeBSD:ZFS) + echo "1..17" + ;; +FreeBSD:UFS) + echo "1..30" + ;; +*) + quick_exit +esac + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 + +expect 0 mkfifo ${n0}/${n1} 0644 +expect 0 unlink ${n0}/${n1} + +expect 0 chflags ${n0} SF_IMMUTABLE +expect EPERM mkfifo ${n0}/${n1} 0644 +expect 0 chflags ${n0} none +expect 0 mkfifo ${n0}/${n1} 0644 +expect 0 unlink ${n0}/${n1} + +expect 0 chflags ${n0} SF_NOUNLINK +expect 0 mkfifo ${n0}/${n1} 0644 +expect 0 unlink ${n0}/${n1} +expect 0 chflags ${n0} none + +expect 0 chflags ${n0} SF_APPEND +expect 0 mkfifo ${n0}/${n1} 0644 +expect 0 chflags ${n0} none +expect 0 unlink ${n0}/${n1} + +case "${os}:${fs}" in +FreeBSD:UFS) + expect 0 chflags ${n0} UF_IMMUTABLE + expect EPERM mkfifo ${n0}/${n1} 0644 + expect 0 chflags ${n0} none + expect 0 mkfifo ${n0}/${n1} 0644 + expect 0 unlink ${n0}/${n1} + + expect 0 chflags ${n0} UF_NOUNLINK + expect 0 mkfifo ${n0}/${n1} 0644 + expect 0 unlink ${n0}/${n1} + expect 0 chflags ${n0} none + + expect 0 chflags ${n0} UF_APPEND + expect 0 mkfifo ${n0}/${n1} 0644 + expect 0 chflags ${n0} none + expect 0 unlink ${n0}/${n1} + ;; +esac + +expect 0 rmdir ${n0} diff --git a/tests/mkfifo/11.t b/tests/mkfifo/11.t new file mode 100644 index 000000000000..a82fe0f40cd7 --- /dev/null +++ b/tests/mkfifo/11.t @@ -0,0 +1,31 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/mkfifo/11.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="mkfifo returns ENOSPC if there are no free inodes on the file system on which the file is being created" + +dir=`dirname $0` +. ${dir}/../misc.sh + +[ "${os}:${fs}" = "FreeBSD:UFS" ] || quick_exit + +echo "1..3" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +n=`mdconfig -a -n -t malloc -s 256k` +newfs /dev/md${n} >/dev/null +mount /dev/md${n} ${n0} +i=0 +while :; do + mkfifo ${n0}/${i} >/dev/null 2>&1 + if [ $? -ne 0 ]; then + break + fi + i=`expr $i + 1` +done +expect ENOSPC mkfifo ${n0}/${n1} 0644 +umount /dev/md${n} +mdconfig -d -u ${n} +expect 0 rmdir ${n0} diff --git a/tests/mkfifo/12.t b/tests/mkfifo/12.t new file mode 100644 index 000000000000..ad044b9f702c --- /dev/null +++ b/tests/mkfifo/12.t @@ -0,0 +1,12 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/mkfifo/12.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="mkfifo returns EFAULT if the path argument points outside the process's allocated address space" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..2" + +expect EFAULT mkfifo NULL 0644 +expect EFAULT mkfifo DEADCODE 0644 diff --git a/tests/mknod/00.t b/tests/mknod/00.t new file mode 100644 index 000000000000..67f4046a6ffb --- /dev/null +++ b/tests/mknod/00.t @@ -0,0 +1,73 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/mknod/00.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="mknod creates fifo files" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..36" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n1} 0755 +cdir=`pwd` +cd ${n1} + +# POSIX: The file permission bits of the new FIFO shall be initialized from +# mode. The file permission bits of the mode argument shall be modified by the +# process' file creation mask. +expect 0 mknod ${n0} f 0755 0 0 +expect fifo,0755 lstat ${n0} type,mode +expect 0 unlink ${n0} +expect 0 mknod ${n0} f 0151 0 0 +expect fifo,0151 lstat ${n0} type,mode +expect 0 unlink ${n0} +expect 0 -U 077 mknod ${n0} f 0151 0 0 +expect fifo,0100 lstat ${n0} type,mode +expect 0 unlink ${n0} +expect 0 -U 070 mknod ${n0} f 0345 0 0 +expect fifo,0305 lstat ${n0} type,mode +expect 0 unlink ${n0} +expect 0 -U 0501 mknod ${n0} f 0345 0 0 +expect fifo,0244 lstat ${n0} type,mode +expect 0 unlink ${n0} + +# POSIX: The FIFO's user ID shall be set to the process' effective user ID. +# The FIFO's group ID shall be set to the group ID of the parent directory or to +# the effective group ID of the process. +expect 0 chown . 65535 65535 +expect 0 -u 65535 -g 65535 mknod ${n0} f 0755 0 0 +expect 65535,65535 lstat ${n0} uid,gid +expect 0 unlink ${n0} +expect 0 -u 65535 -g 65534 mknod ${n0} f 0755 0 0 +expect "65535,6553[45]" lstat ${n0} uid,gid +expect 0 unlink ${n0} +expect 0 chmod . 0777 +expect 0 -u 65534 -g 65533 mknod ${n0} f 0755 0 0 +expect "65534,6553[35]" lstat ${n0} uid,gid +expect 0 unlink ${n0} + +# POSIX: Upon successful completion, mkfifo() shall mark for update the +# st_atime, st_ctime, and st_mtime fields of the file. Also, the st_ctime and +# st_mtime fields of the directory that contains the new entry shall be marked +# for update. +expect 0 chown . 0 0 +time=`${fstest} stat . ctime` +sleep 1 +expect 0 mknod ${n0} f 0755 0 0 +atime=`${fstest} stat ${n0} atime` +test_check $time -lt $atime +mtime=`${fstest} stat ${n0} mtime` +test_check $time -lt $mtime +ctime=`${fstest} stat ${n0} ctime` +test_check $time -lt $ctime +mtime=`${fstest} stat . mtime` +test_check $time -lt $mtime +ctime=`${fstest} stat . ctime` +test_check $time -lt $ctime +expect 0 unlink ${n0} + +cd ${cdir} +expect 0 rmdir ${n1} diff --git a/tests/mknod/01.t b/tests/mknod/01.t new file mode 100644 index 000000000000..84a0a9731cd7 --- /dev/null +++ b/tests/mknod/01.t @@ -0,0 +1,22 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/mknod/01.t 211474 2010-08-18 22:06:43Z pjd $ + +desc="mknod returns ENOTDIR if a component of the path prefix is not a directory" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..27" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +for type in regular fifo block char socket; do + create_file ${type} ${n0}/${n1} + expect ENOTDIR mknod ${n0}/${n1}/test b 0644 1 2 + expect ENOTDIR mknod ${n0}/${n1}/test c 0644 1 2 + expect ENOTDIR mknod ${n0}/${n1}/test f 0644 0 0 + expect 0 unlink ${n0}/${n1} +done +expect 0 rmdir ${n0} diff --git a/tests/mknod/02.t b/tests/mknod/02.t new file mode 100644 index 000000000000..4e864fe69f69 --- /dev/null +++ b/tests/mknod/02.t @@ -0,0 +1,27 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/mknod/02.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="mknod returns ENAMETOOLONG if a component of a pathname exceeded {NAME_MAX} characters" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..12" + +nx=`namegen_max` +nxx="${nx}x" + +expect 0 mknod ${nx} f 0644 0 0 +expect fifo,0644 stat ${nx} type,mode +expect 0 unlink ${nx} +expect ENAMETOOLONG mknod ${nxx} f 0644 0 0 + +expect 0 mknod ${nx} b 0644 1 2 +expect block,0644 stat ${nx} type,mode +expect 0 unlink ${nx} +expect ENAMETOOLONG mknod ${nxx} b 0644 0 0 + +expect 0 mknod ${nx} c 0644 1 2 +expect char,0644 stat ${nx} type,mode +expect 0 unlink ${nx} +expect ENAMETOOLONG mknod ${nxx} c 0644 0 0 diff --git a/tests/mknod/03.t b/tests/mknod/03.t new file mode 100644 index 000000000000..d5c572cbf460 --- /dev/null +++ b/tests/mknod/03.t @@ -0,0 +1,31 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/mknod/03.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="mknod returns ENAMETOOLONG if an entire path name exceeded {PATH_MAX} characters" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..12" + +nx=`dirgen_max` +nxx="${nx}x" + +mkdir -p "${nx%/*}" + +expect 0 mknod ${nx} f 0644 0 0 +expect fifo stat ${nx} type +expect 0 unlink ${nx} +expect ENAMETOOLONG mknod ${nxx} f 0644 0 0 + +expect 0 mknod ${nx} b 0644 1 2 +expect block stat ${nx} type +expect 0 unlink ${nx} +expect ENAMETOOLONG mknod ${nxx} b 0644 1 2 + +expect 0 mknod ${nx} c 0644 1 2 +expect char stat ${nx} type +expect 0 unlink ${nx} +expect ENAMETOOLONG mknod ${nxx} c 0644 1 2 + +rm -rf "${nx%%/*}" diff --git a/tests/mknod/04.t b/tests/mknod/04.t new file mode 100644 index 000000000000..4b80208caffe --- /dev/null +++ b/tests/mknod/04.t @@ -0,0 +1,16 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/mknod/04.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="mkfifo returns ENOENT if a component of the path prefix does not exist" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..3" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +expect ENOENT mknod ${n0}/${n1}/test f 0644 0 0 +expect 0 rmdir ${n0} diff --git a/tests/mknod/05.t b/tests/mknod/05.t new file mode 100644 index 000000000000..deafda620750 --- /dev/null +++ b/tests/mknod/05.t @@ -0,0 +1,29 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/mknod/05.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="mknod returns EACCES when search permission is denied for a component of the path prefix" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..12" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n0} 0755 +cdir=`pwd` +cd ${n0} +expect 0 mkdir ${n1} 0755 +expect 0 chown ${n1} 65534 65534 +expect 0 -u 65534 -g 65534 mknod ${n1}/${n2} f 0644 0 0 +expect 0 -u 65534 -g 65534 unlink ${n1}/${n2} +expect 0 chmod ${n1} 0644 +expect EACCES -u 65534 -g 65534 mknod ${n1}/${n2} f 0644 0 0 +expect 0 chmod ${n1} 0755 +expect 0 -u 65534 -g 65534 mknod ${n1}/${n2} f 0644 0 0 +expect 0 -u 65534 -g 65534 unlink ${n1}/${n2} +expect 0 rmdir ${n1} +cd ${cdir} +expect 0 rmdir ${n0} diff --git a/tests/mknod/06.t b/tests/mknod/06.t new file mode 100644 index 000000000000..da7a5497b5a6 --- /dev/null +++ b/tests/mknod/06.t @@ -0,0 +1,29 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/mknod/06.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="mknod returns EACCES when write permission is denied on the parent directory of the file to be created" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..12" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n0} 0755 +cdir=`pwd` +cd ${n0} +expect 0 mkdir ${n1} 0755 +expect 0 chown ${n1} 65534 65534 +expect 0 -u 65534 -g 65534 mknod ${n1}/${n2} f 0644 0 0 +expect 0 -u 65534 -g 65534 unlink ${n1}/${n2} +expect 0 chmod ${n1} 0555 +expect EACCES -u 65534 -g 65534 mknod ${n1}/${n2} f 0644 0 0 +expect 0 chmod ${n1} 0755 +expect 0 -u 65534 -g 65534 mknod ${n1}/${n2} f 0644 0 0 +expect 0 -u 65534 -g 65534 unlink ${n1}/${n2} +expect 0 rmdir ${n1} +cd ${cdir} +expect 0 rmdir ${n0} diff --git a/tests/mknod/07.t b/tests/mknod/07.t new file mode 100644 index 000000000000..1b39cc7c6d94 --- /dev/null +++ b/tests/mknod/07.t @@ -0,0 +1,19 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/mknod/07.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="mknod returns ELOOP if too many symbolic links were encountered in translating the pathname" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..6" + +n0=`namegen` +n1=`namegen` + +expect 0 symlink ${n0} ${n1} +expect 0 symlink ${n1} ${n0} +expect ELOOP mknod ${n0}/test f 0644 0 0 +expect ELOOP mknod ${n1}/test f 0644 0 0 +expect 0 unlink ${n0} +expect 0 unlink ${n1} diff --git a/tests/mknod/08.t b/tests/mknod/08.t new file mode 100644 index 000000000000..a8055629de07 --- /dev/null +++ b/tests/mknod/08.t @@ -0,0 +1,23 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/mknod/08.t 211474 2010-08-18 22:06:43Z pjd $ + +desc="mknod returns EEXIST if the named file exists" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..35" + +n0=`namegen` + +for type in regular dir fifo block char socket symlink; do + create_file ${type} ${n0} + expect EEXIST mknod ${n0} b 0644 0 0 + expect EEXIST mknod ${n0} c 0644 0 0 + expect EEXIST mknod ${n0} f 0644 0 0 + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n0} + else + expect 0 unlink ${n0} + fi +done diff --git a/tests/mknod/09.t b/tests/mknod/09.t new file mode 100644 index 000000000000..00c2a2f6d8b5 --- /dev/null +++ b/tests/mknod/09.t @@ -0,0 +1,64 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/mknod/09.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="mknod returns EPERM if the parent directory of the file to be created has its immutable flag set" + +dir=`dirname $0` +. ${dir}/../misc.sh + +require chflags + +case "${os}:${fs}" in +FreeBSD:UFS) + echo "1..30" + ;; +*) + echo "1..17" + ;; +esac + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 + +expect 0 mknod ${n0}/${n1} f 0644 0 0 +expect 0 unlink ${n0}/${n1} + +expect 0 chflags ${n0} SF_IMMUTABLE +expect EPERM mknod ${n0}/${n1} f 0644 0 0 +expect 0 chflags ${n0} none +expect 0 mknod ${n0}/${n1} f 0644 0 0 +expect 0 unlink ${n0}/${n1} + +expect 0 chflags ${n0} SF_APPEND +expect 0 mknod ${n0}/${n1} f 0644 0 0 +expect 0 chflags ${n0} none +expect 0 unlink ${n0}/${n1} + +expect 0 chflags ${n0} SF_NOUNLINK +expect 0 mknod ${n0}/${n1} f 0644 0 0 +expect 0 unlink ${n0}/${n1} +expect 0 chflags ${n0} none + +case "${os}:${fs}" in +FreeBSD:UFS) + expect 0 chflags ${n0} UF_IMMUTABLE + expect EPERM mknod ${n0}/${n1} f 0644 0 0 + expect 0 chflags ${n0} none + expect 0 mknod ${n0}/${n1} f 0644 0 0 + expect 0 unlink ${n0}/${n1} + + expect 0 chflags ${n0} UF_APPEND + expect 0 mknod ${n0}/${n1} f 0644 0 0 + expect 0 chflags ${n0} none + expect 0 unlink ${n0}/${n1} + + expect 0 chflags ${n0} UF_NOUNLINK + expect 0 mknod ${n0}/${n1} f 0644 0 0 + expect 0 unlink ${n0}/${n1} + expect 0 chflags ${n0} none + ;; +esac + +expect 0 rmdir ${n0} diff --git a/tests/mknod/10.t b/tests/mknod/10.t new file mode 100644 index 000000000000..5bf18d37adc4 --- /dev/null +++ b/tests/mknod/10.t @@ -0,0 +1,12 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/mknod/10.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="mknod returns EFAULT if the path argument points outside the process's allocated address space" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..2" + +expect EFAULT mknod NULL f 0644 0 0 +expect EFAULT mknod DEADCODE f 0644 0 0 diff --git a/tests/mknod/11.t b/tests/mknod/11.t new file mode 100644 index 000000000000..309f71695f31 --- /dev/null +++ b/tests/mknod/11.t @@ -0,0 +1,79 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/mknod/11.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="mknod creates device files" + +dir=`dirname $0` +. ${dir}/../misc.sh + +case "${os}" in +SunOS) + echo "1..40" + ;; +*) + echo "1..28" + ;; +esac + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n1} 0755 +cdir=`pwd` +cd ${n1} + +for type in c b; do + case "${type}" in + c) + stattype="char" + ;; + b) + stattype="block" + ;; + esac + + # Create char special with old-style numbers + expect 0 mknod ${n0} ${type} 0755 1 2 + expect ${stattype},0755 lstat ${n0} type,mode + expect 1,2 lstat ${n0} major,minor + expect EEXIST mknod ${n0} ${type} 0777 3 4 + expect 0 unlink ${n0} + + case "${os}" in + SunOS) + # Create char special with new-style numbers + expect 0 mknod ${n0} ${type} 0755 4095 4095 + expect ${stattype},0755 lstat ${n0} type,mode + expect 4095,4095 lstat ${n0} major,minor + expect EEXIST mknod ${n0} ${type} 0777 4000 4000 + expect 0 unlink ${n0} + + # mknod returns EINVAL if device's numbers are too big + # for 32-bit solaris !! + expect EINVAL mknod ${n0} ${type} 0755 4096 262144 + ;; + esac + + # POSIX: Upon successful completion, mknod(2) shall mark for update the + # st_atime, st_ctime, and st_mtime fields of the file. Also, the st_ctime and + # st_mtime fields of the directory that contains the new entry shall be marked + # for update. + expect 0 chown . 0 0 + time=`${fstest} stat . ctime` + sleep 1 + expect 0 mknod ${n0} ${type} 0755 1 2 + atime=`${fstest} stat ${n0} atime` + test_check $time -lt $atime + mtime=`${fstest} stat ${n0} mtime` + test_check $time -lt $mtime + ctime=`${fstest} stat ${n0} ctime` + test_check $time -lt $ctime + mtime=`${fstest} stat . mtime` + test_check $time -lt $mtime + ctime=`${fstest} stat . ctime` + test_check $time -lt $ctime + expect 0 unlink ${n0} +done + +cd ${cdir} +expect 0 rmdir ${n1} diff --git a/tests/open/00.t b/tests/open/00.t new file mode 100644 index 000000000000..cf11a9290e8e --- /dev/null +++ b/tests/open/00.t @@ -0,0 +1,99 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/open/00.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="open opens (and eventually creates) a file" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..47" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n1} 0755 +cdir=`pwd` +cd ${n1} + +# POSIX: (If O_CREAT is specified and the file doesn't exist) [...] the access +# permission bits of the file mode shall be set to the value of the third +# argument taken as type mode_t modified as follows: a bitwise AND is performed +# on the file-mode bits and the corresponding bits in the complement of the +# process' file mode creation mask. Thus, all bits in the file mode whose +# corresponding bit in the file mode creation mask is set are cleared. +expect 0 open ${n0} O_CREAT,O_WRONLY 0755 +expect regular,0755 lstat ${n0} type,mode +expect 0 unlink ${n0} +expect 0 open ${n0} O_CREAT,O_WRONLY 0151 +expect regular,0151 lstat ${n0} type,mode +expect 0 unlink ${n0} +expect 0 -U 077 open ${n0} O_CREAT,O_WRONLY 0151 +expect regular,0100 lstat ${n0} type,mode +expect 0 unlink ${n0} +expect 0 -U 070 open ${n0} O_CREAT,O_WRONLY 0345 +expect regular,0305 lstat ${n0} type,mode +expect 0 unlink ${n0} +expect 0 -U 0501 open ${n0} O_CREAT,O_WRONLY 0345 +expect regular,0244 lstat ${n0} type,mode +expect 0 unlink ${n0} + +# POSIX: (If O_CREAT is specified and the file doesn't exist) [...] the user ID +# of the file shall be set to the effective user ID of the process; the group ID +# of the file shall be set to the group ID of the file's parent directory or to +# the effective group ID of the process [...] +expect 0 chown . 65535 65535 +expect 0 -u 65535 -g 65535 open ${n0} O_CREAT,O_WRONLY 0644 +expect 65535,65535 lstat ${n0} uid,gid +expect 0 unlink ${n0} +expect 0 -u 65535 -g 65534 open ${n0} O_CREAT,O_WRONLY 0644 +expect "65535,6553[45]" lstat ${n0} uid,gid +expect 0 unlink ${n0} +expect 0 chmod . 0777 +expect 0 -u 65534 -g 65533 open ${n0} O_CREAT,O_WRONLY 0644 +expect "65534,6553[35]" lstat ${n0} uid,gid +expect 0 unlink ${n0} + +# Update parent directory ctime/mtime if file didn't exist. +expect 0 chown . 0 0 +time=`${fstest} stat . ctime` +sleep 1 +expect 0 open ${n0} O_CREAT,O_WRONLY 0644 +atime=`${fstest} stat ${n0} atime` +test_check $time -lt $atime +mtime=`${fstest} stat ${n0} mtime` +test_check $time -lt $mtime +ctime=`${fstest} stat ${n0} ctime` +test_check $time -lt $ctime +mtime=`${fstest} stat . mtime` +test_check $time -lt $mtime +ctime=`${fstest} stat . ctime` +test_check $time -lt $ctime +expect 0 unlink ${n0} + +# Don't update parent directory ctime/mtime if file existed. +expect 0 create ${n0} 0644 +dmtime=`${fstest} stat . mtime` +dctime=`${fstest} stat . ctime` +sleep 1 +expect 0 open ${n0} O_CREAT,O_RDONLY 0644 +mtime=`${fstest} stat . mtime` +test_check $dmtime -eq $mtime +ctime=`${fstest} stat . ctime` +test_check $dctime -eq $ctime +expect 0 unlink ${n0} + +echo test > ${n0} +expect 5 stat ${n0} size +mtime1=`${fstest} stat ${n0} mtime` +ctime1=`${fstest} stat ${n0} ctime` +sleep 1 +expect 0 open ${n0} O_WRONLY,O_TRUNC +mtime2=`${fstest} stat ${n0} mtime` +test_check $mtime1 -lt $mtime2 +ctime2=`${fstest} stat ${n0} ctime` +test_check $ctime1 -lt $ctime2 +expect 0 stat ${n0} size +expect 0 unlink ${n0} + +cd ${cdir} +expect 0 rmdir ${n1} diff --git a/tests/open/01.t b/tests/open/01.t new file mode 100644 index 000000000000..df17590113ab --- /dev/null +++ b/tests/open/01.t @@ -0,0 +1,21 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/open/01.t 211474 2010-08-18 22:06:43Z pjd $ + +desc="open returns ENOTDIR if a component of the path prefix is not a directory" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..22" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +for type in regular fifo block char socket; do + create_file ${type} ${n0}/${n1} + expect ENOTDIR open ${n0}/${n1}/test O_RDONLY + expect ENOTDIR open ${n0}/${n1}/test O_CREAT 0644 + expect 0 unlink ${n0}/${n1} +done +expect 0 rmdir ${n0} diff --git a/tests/open/02.t b/tests/open/02.t new file mode 100644 index 000000000000..adb3bb09d39b --- /dev/null +++ b/tests/open/02.t @@ -0,0 +1,17 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/open/02.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="open returns ENAMETOOLONG if a component of a pathname exceeded {NAME_MAX} characters" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..4" + +nx=`namegen_max` +nxx="${nx}x" + +expect 0 open ${nx} O_CREAT 0620 +expect regular,0620 stat ${nx} type,mode +expect 0 unlink ${nx} +expect ENAMETOOLONG open ${nxx} O_CREAT 0620 diff --git a/tests/open/03.t b/tests/open/03.t new file mode 100644 index 000000000000..89e67bb46eb2 --- /dev/null +++ b/tests/open/03.t @@ -0,0 +1,21 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/open/03.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="open returns ENAMETOOLONG if an entire path name exceeded ${PATH_MAX} characters" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..4" + +nx=`dirgen_max` +nxx="${nx}x" + +mkdir -p "${nx%/*}" + +expect 0 open ${nx} O_CREAT 0642 +expect regular,0642 stat ${nx} type,mode +expect 0 unlink ${nx} +expect ENAMETOOLONG open ${nxx} O_CREAT 0642 + +rm -rf "${nx%%/*}" diff --git a/tests/open/04.t b/tests/open/04.t new file mode 100644 index 000000000000..84b0441f11d8 --- /dev/null +++ b/tests/open/04.t @@ -0,0 +1,17 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/open/04.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="open returns ENOENT if a component of the path name that must exist does not exist or O_CREAT is not set and the named file does not exist" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..4" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +expect ENOENT open ${n0}/${n1}/test O_CREAT 0644 +expect ENOENT open ${n0}/${n1} O_RDONLY +expect 0 rmdir ${n0} diff --git a/tests/open/05.t b/tests/open/05.t new file mode 100644 index 000000000000..1b69c61333c3 --- /dev/null +++ b/tests/open/05.t @@ -0,0 +1,29 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/open/05.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="open returns EACCES when search permission is denied for a component of the path prefix" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..12" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n0} 0755 +cdir=`pwd` +cd ${n0} +expect 0 mkdir ${n1} 0755 +expect 0 chown ${n1} 65534 65534 +expect 0 -u 65534 -g 65534 create ${n1}/${n2} 0644 +expect 0 -u 65534 -g 65534 open ${n1}/${n2} O_RDONLY +expect 0 chmod ${n1} 0644 +expect EACCES -u 65534 -g 65534 open ${n1}/${n2} O_RDONLY +expect 0 chmod ${n1} 0755 +expect 0 -u 65534 -g 65534 open ${n1}/${n2} O_RDONLY +expect 0 -u 65534 -g 65534 unlink ${n1}/${n2} +expect 0 rmdir ${n1} +cd ${cdir} +expect 0 rmdir ${n0} diff --git a/tests/open/06.t b/tests/open/06.t new file mode 100644 index 000000000000..b33e6404e70b --- /dev/null +++ b/tests/open/06.t @@ -0,0 +1,187 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/open/06.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="open returns EACCES when the required permissions (for reading and/or writing) are denied for the given flags" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..144" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +expect 0 chown ${n0} 65534 65534 +cdir=`pwd` +cd ${n0} + +# Regular file. + +expect 0 -u 65534 -g 65534 create ${n1} 0644 + +expect 0 -u 65534 -g 65534 chmod ${n1} 0600 +expect 0 -u 65534 -g 65534 open ${n1} O_RDONLY, +expect 0 -u 65534 -g 65534 open ${n1} O_WRONLY, +expect 0 -u 65534 -g 65534 open ${n1} O_RDWR, +expect 0 -u 65534 -g 65534 chmod ${n1} 0060 +expect 0 -u 65533 -g 65534 open ${n1} O_RDONLY, +expect 0 -u 65533 -g 65534 open ${n1} O_WRONLY, +expect 0 -u 65533 -g 65534 open ${n1} O_RDWR, +expect 0 -u 65534 -g 65534 chmod ${n1} 0006 +expect 0 -u 65533 -g 65533 open ${n1} O_RDONLY, +expect 0 -u 65533 -g 65533 open ${n1} O_WRONLY, +expect 0 -u 65533 -g 65533 open ${n1} O_RDWR, + +expect 0 -u 65534 -g 65534 chmod ${n1} 0477 +expect 0 -u 65534 -g 65534 open ${n1} O_RDONLY, +expect EACCES -u 65534 -g 65534 open ${n1} O_WRONLY, +expect EACCES -u 65534 -g 65534 open ${n1} O_RDWR, +expect 0 -u 65534 -g 65534 chmod ${n1} 0747 +expect 0 -u 65533 -g 65534 open ${n1} O_RDONLY, +expect EACCES -u 65533 -g 65534 open ${n1} O_WRONLY, +expect EACCES -u 65533 -g 65534 open ${n1} O_RDWR, +expect 0 -u 65534 -g 65534 chmod ${n1} 0774 +expect 0 -u 65533 -g 65533 open ${n1} O_RDONLY, +expect EACCES -u 65533 -g 65533 open ${n1} O_WRONLY, +expect EACCES -u 65533 -g 65533 open ${n1} O_RDWR, + +expect 0 -u 65534 -g 65534 chmod ${n1} 0277 +expect EACCES -u 65534 -g 65534 open ${n1} O_RDONLY, +expect 0 -u 65534 -g 65534 open ${n1} O_WRONLY, +expect EACCES -u 65534 -g 65534 open ${n1} O_RDWR, +expect 0 -u 65534 -g 65534 chmod ${n1} 0727 +expect EACCES -u 65533 -g 65534 open ${n1} O_RDONLY, +expect 0 -u 65533 -g 65534 open ${n1} O_WRONLY, +expect EACCES -u 65533 -g 65534 open ${n1} O_RDWR, +expect 0 -u 65534 -g 65534 chmod ${n1} 0772 +expect EACCES -u 65533 -g 65533 open ${n1} O_RDONLY, +expect 0 -u 65533 -g 65533 open ${n1} O_WRONLY, +expect EACCES -u 65533 -g 65533 open ${n1} O_RDWR, + +expect 0 -u 65534 -g 65534 chmod ${n1} 0177 +expect EACCES -u 65534 -g 65534 open ${n1} O_RDONLY, +expect EACCES -u 65534 -g 65534 open ${n1} O_WRONLY, +expect EACCES -u 65534 -g 65534 open ${n1} O_RDWR, +expect 0 -u 65534 -g 65534 chmod ${n1} 0717 +expect EACCES -u 65533 -g 65534 open ${n1} O_RDONLY, +expect EACCES -u 65533 -g 65534 open ${n1} O_WRONLY, +expect EACCES -u 65533 -g 65534 open ${n1} O_RDWR, +expect 0 -u 65534 -g 65534 chmod ${n1} 0771 +expect EACCES -u 65533 -g 65533 open ${n1} O_RDONLY, +expect EACCES -u 65533 -g 65533 open ${n1} O_WRONLY, +expect EACCES -u 65533 -g 65533 open ${n1} O_RDWR, + +expect 0 -u 65534 -g 65534 chmod ${n1} 0077 +expect EACCES -u 65534 -g 65534 open ${n1} O_RDONLY, +expect EACCES -u 65534 -g 65534 open ${n1} O_WRONLY, +expect EACCES -u 65534 -g 65534 open ${n1} O_RDWR, +expect 0 -u 65534 -g 65534 chmod ${n1} 0707 +expect EACCES -u 65533 -g 65534 open ${n1} O_RDONLY, +expect EACCES -u 65533 -g 65534 open ${n1} O_WRONLY, +expect EACCES -u 65533 -g 65534 open ${n1} O_RDWR, +expect 0 -u 65534 -g 65534 chmod ${n1} 0770 +expect EACCES -u 65533 -g 65533 open ${n1} O_RDONLY, +expect EACCES -u 65533 -g 65533 open ${n1} O_WRONLY, +expect EACCES -u 65533 -g 65533 open ${n1} O_RDWR, + +expect 0 -u 65534 -g 65534 unlink ${n1} + +# FIFO. + +expect 0 -u 65534 -g 65534 mkfifo ${n1} 0644 + +expect 0 -u 65534 -g 65534 chmod ${n1} 0600 +expect 0 -u 65534 -g 65534 open ${n1} O_RDONLY,O_NONBLOCK +expect 0 -u 65534 -g 65534 open ${n1} O_RDWR,O_NONBLOCK +expect 0 -u 65534 -g 65534 chmod ${n1} 0060 +expect 0 -u 65533 -g 65534 open ${n1} O_RDONLY,O_NONBLOCK +expect 0 -u 65533 -g 65534 open ${n1} O_RDWR,O_NONBLOCK +expect 0 -u 65534 -g 65534 chmod ${n1} 0006 +expect 0 -u 65533 -g 65533 open ${n1} O_RDONLY,O_NONBLOCK +expect 0 -u 65533 -g 65533 open ${n1} O_RDWR,O_NONBLOCK + +expect 0 -u 65534 -g 65534 chmod ${n1} 0477 +expect 0 -u 65534 -g 65534 open ${n1} O_RDONLY,O_NONBLOCK +expect EACCES -u 65534 -g 65534 open ${n1} O_WRONLY +expect EACCES -u 65534 -g 65534 open ${n1} O_RDWR +expect 0 -u 65534 -g 65534 chmod ${n1} 0747 +expect 0 -u 65533 -g 65534 open ${n1} O_RDONLY,O_NONBLOCK +expect EACCES -u 65533 -g 65534 open ${n1} O_WRONLY +expect EACCES -u 65533 -g 65534 open ${n1} O_RDWR +expect 0 -u 65534 -g 65534 chmod ${n1} 0774 +expect 0 -u 65533 -g 65533 open ${n1} O_RDONLY,O_NONBLOCK +expect EACCES -u 65533 -g 65533 open ${n1} O_WRONLY +expect EACCES -u 65533 -g 65533 open ${n1} O_RDWR + +expect 0 -u 65534 -g 65534 chmod ${n1} 0177 +expect EACCES -u 65534 -g 65534 open ${n1} O_RDONLY +expect EACCES -u 65534 -g 65534 open ${n1} O_WRONLY +expect EACCES -u 65534 -g 65534 open ${n1} O_RDWR +expect 0 -u 65534 -g 65534 chmod ${n1} 0717 +expect EACCES -u 65533 -g 65534 open ${n1} O_RDONLY +expect EACCES -u 65533 -g 65534 open ${n1} O_WRONLY +expect EACCES -u 65533 -g 65534 open ${n1} O_RDWR +expect 0 -u 65534 -g 65534 chmod ${n1} 0771 +expect EACCES -u 65533 -g 65533 open ${n1} O_RDONLY +expect EACCES -u 65533 -g 65533 open ${n1} O_WRONLY +expect EACCES -u 65533 -g 65533 open ${n1} O_RDWR + +expect 0 -u 65534 -g 65534 chmod ${n1} 0077 +expect EACCES -u 65534 -g 65534 open ${n1} O_RDONLY +expect EACCES -u 65534 -g 65534 open ${n1} O_WRONLY +expect EACCES -u 65534 -g 65534 open ${n1} O_RDWR +expect 0 -u 65534 -g 65534 chmod ${n1} 0707 +expect EACCES -u 65533 -g 65534 open ${n1} O_RDONLY +expect EACCES -u 65533 -g 65534 open ${n1} O_WRONLY +expect EACCES -u 65533 -g 65534 open ${n1} O_RDWR +expect 0 -u 65534 -g 65534 chmod ${n1} 0770 +expect EACCES -u 65533 -g 65533 open ${n1} O_RDONLY +expect EACCES -u 65533 -g 65533 open ${n1} O_WRONLY +expect EACCES -u 65533 -g 65533 open ${n1} O_RDWR + +expect 0 -u 65534 -g 65534 unlink ${n1} + +# Directory. + +expect 0 -u 65534 -g 65534 mkdir ${n1} 0755 + +expect 0 -u 65534 -g 65534 chmod ${n1} 0600 +expect 0 -u 65534 -g 65534 open ${n1} O_RDONLY +expect 0 -u 65534 -g 65534 chmod ${n1} 0060 +expect 0 -u 65533 -g 65534 open ${n1} O_RDONLY +expect 0 -u 65534 -g 65534 chmod ${n1} 0006 +expect 0 -u 65533 -g 65533 open ${n1} O_RDONLY + +expect 0 -u 65534 -g 65534 chmod ${n1} 0477 +expect 0 -u 65534 -g 65534 open ${n1} O_RDONLY +expect 0 -u 65534 -g 65534 chmod ${n1} 0747 +expect 0 -u 65533 -g 65534 open ${n1} O_RDONLY +expect 0 -u 65534 -g 65534 chmod ${n1} 0774 +expect 0 -u 65533 -g 65533 open ${n1} O_RDONLY + +expect 0 -u 65534 -g 65534 chmod ${n1} 0277 +expect EACCES -u 65534 -g 65534 open ${n1} O_RDONLY +expect 0 -u 65534 -g 65534 chmod ${n1} 0727 +expect EACCES -u 65533 -g 65534 open ${n1} O_RDONLY +expect 0 -u 65534 -g 65534 chmod ${n1} 0772 +expect EACCES -u 65533 -g 65533 open ${n1} O_RDONLY + +expect 0 -u 65534 -g 65534 chmod ${n1} 0177 +expect EACCES -u 65534 -g 65534 open ${n1} O_RDONLY +expect 0 -u 65534 -g 65534 chmod ${n1} 0717 +expect EACCES -u 65533 -g 65534 open ${n1} O_RDONLY +expect 0 -u 65534 -g 65534 chmod ${n1} 0771 +expect EACCES -u 65533 -g 65533 open ${n1} O_RDONLY + +expect 0 -u 65534 -g 65534 chmod ${n1} 0077 +expect EACCES -u 65534 -g 65534 open ${n1} O_RDONLY +expect 0 -u 65534 -g 65534 chmod ${n1} 0707 +expect EACCES -u 65533 -g 65534 open ${n1} O_RDONLY +expect 0 -u 65534 -g 65534 chmod ${n1} 0770 +expect EACCES -u 65533 -g 65533 open ${n1} O_RDONLY + +expect 0 -u 65534 -g 65534 rmdir ${n1} + +cd ${cdir} +expect 0 rmdir ${n0} diff --git a/tests/open/07.t b/tests/open/07.t new file mode 100644 index 000000000000..edc4be13649b --- /dev/null +++ b/tests/open/07.t @@ -0,0 +1,45 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/open/07.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="open returns EACCES when O_TRUNC is specified and write permission is denied" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..23" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +expect 0 chown ${n0} 65534 65534 +cdir=`pwd` +cd ${n0} + +expect 0 -u 65534 -g 65534 create ${n1} 0644 + +expect 0 -u 65534 -g 65534 chmod ${n1} 0477 +expect EACCES -u 65534 -g 65534 open ${n1} O_RDONLY,O_TRUNC +expect 0 -u 65534 -g 65534 chmod ${n1} 0747 +expect EACCES -u 65533 -g 65534 open ${n1} O_RDONLY,O_TRUNC +expect 0 -u 65534 -g 65534 chmod ${n1} 0774 +expect EACCES -u 65533 -g 65533 open ${n1} O_RDONLY,O_TRUNC + +expect 0 -u 65534 -g 65534 chmod ${n1} 0177 +expect EACCES -u 65534 -g 65534 open ${n1} O_RDONLY,O_TRUNC +expect 0 -u 65534 -g 65534 chmod ${n1} 0717 +expect EACCES -u 65533 -g 65534 open ${n1} O_RDONLY,O_TRUNC +expect 0 -u 65534 -g 65534 chmod ${n1} 0771 +expect EACCES -u 65533 -g 65533 open ${n1} O_RDONLY,O_TRUNC + +expect 0 -u 65534 -g 65534 chmod ${n1} 0077 +expect EACCES -u 65534 -g 65534 open ${n1} O_RDONLY,O_TRUNC +expect 0 -u 65534 -g 65534 chmod ${n1} 0707 +expect EACCES -u 65533 -g 65534 open ${n1} O_RDONLY,O_TRUNC +expect 0 -u 65534 -g 65534 chmod ${n1} 0770 +expect EACCES -u 65533 -g 65533 open ${n1} O_RDONLY,O_TRUNC + +expect 0 -u 65534 -g 65534 unlink ${n1} + +cd ${cdir} +expect 0 rmdir ${n0} diff --git a/tests/open/08.t b/tests/open/08.t new file mode 100644 index 000000000000..f47ff8720419 --- /dev/null +++ b/tests/open/08.t @@ -0,0 +1,19 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/open/08.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="open returns EACCES when O_CREAT is specified, the file does not exist, and the directory in which it is to be created does not permit writing" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..3" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +cdir=`pwd` +cd ${n0} +expect EACCES -u 65534 -g 65534 open ${n1} O_RDONLY,O_CREAT 0644 +cd ${cdir} +expect 0 rmdir ${n0} diff --git a/tests/open/09.t b/tests/open/09.t new file mode 100644 index 000000000000..b76c70da8190 --- /dev/null +++ b/tests/open/09.t @@ -0,0 +1,66 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/open/09.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="O_CREAT is specified, the file does not exist, and the directory in which it is to be created has its immutable flag set" + +dir=`dirname $0` +. ${dir}/../misc.sh + +require chflags + +case "${os}:${fs}" in +FreeBSD:ZFS) + echo "1..17" + ;; +FreeBSD:UFS) + echo "1..30" + ;; +*) + quick_exit +esac + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 + +expect 0 open ${n0}/${n1} O_RDONLY,O_CREAT 0644 +expect 0 unlink ${n0}/${n1} + +expect 0 chflags ${n0} SF_IMMUTABLE +expect EPERM open ${n0}/${n1} O_RDONLY,O_CREAT 0644 +expect 0 chflags ${n0} none +expect 0 open ${n0}/${n1} O_RDONLY,O_CREAT 0644 +expect 0 unlink ${n0}/${n1} + +expect 0 chflags ${n0} SF_NOUNLINK +expect 0 open ${n0}/${n1} O_RDONLY,O_CREAT 0644 +expect 0 chflags ${n0} none +expect 0 unlink ${n0}/${n1} + +expect 0 chflags ${n0} SF_APPEND +expect 0 open ${n0}/${n1} O_RDONLY,O_CREAT 0644 +expect 0 chflags ${n0} none +expect 0 unlink ${n0}/${n1} + +case "${os}:${fs}" in +FreeBSD:UFS) + expect 0 chflags ${n0} UF_IMMUTABLE + expect EPERM open ${n0}/${n1} O_RDONLY,O_CREAT 0644 + expect 0 chflags ${n0} none + expect 0 open ${n0}/${n1} O_RDONLY,O_CREAT 0644 + expect 0 unlink ${n0}/${n1} + + expect 0 chflags ${n0} UF_NOUNLINK + expect 0 symlink test ${n0}/${n1} + expect 0 chflags ${n0} none + expect 0 unlink ${n0}/${n1} + + expect 0 chflags ${n0} UF_APPEND + expect 0 open ${n0}/${n1} O_RDONLY,O_CREAT 0644 + expect 0 chflags ${n0} none + expect 0 unlink ${n0}/${n1} + ;; +esac + +expect 0 rmdir ${n0} diff --git a/tests/open/10.t b/tests/open/10.t new file mode 100644 index 000000000000..bd6fdd25241f --- /dev/null +++ b/tests/open/10.t @@ -0,0 +1,58 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/open/10.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="open returns EPERM when the named file has its immutable flag set and the file is to be modified" + +dir=`dirname $0` +. ${dir}/../misc.sh + +require chflags + +case "${os}:${fs}" in +FreeBSD:ZFS) + echo "1..14" + ;; +FreeBSD:UFS) + echo "1..28" + ;; +*) + quick_exit +esac + +n0=`namegen` + +expect 0 create ${n0} 0644 +expect 0 chflags ${n0} SF_IMMUTABLE +expect EPERM open ${n0} O_WRONLY +expect EPERM open ${n0} O_RDWR +expect EPERM open ${n0} O_RDONLY,O_TRUNC +expect 0 chflags ${n0} none +expect 0 unlink ${n0} + +expect 0 create ${n0} 0644 +expect 0 chflags ${n0} SF_NOUNLINK +expect 0 open ${n0} O_WRONLY +expect 0 open ${n0} O_RDWR +expect 0 open ${n0} O_RDONLY,O_TRUNC +expect 0 chflags ${n0} none +expect 0 unlink ${n0} + +case "${os}:${fs}" in +FreeBSD:UFS) + expect 0 create ${n0} 0644 + expect 0 chflags ${n0} UF_IMMUTABLE + expect EPERM open ${n0} O_WRONLY + expect EPERM open ${n0} O_RDWR + expect EPERM open ${n0} O_RDONLY,O_TRUNC + expect 0 chflags ${n0} none + expect 0 unlink ${n0} + + expect 0 create ${n0} 0644 + expect 0 chflags ${n0} UF_NOUNLINK + expect 0 open ${n0} O_WRONLY + expect 0 open ${n0} O_RDWR + expect 0 open ${n0} O_RDONLY,O_TRUNC + expect 0 chflags ${n0} none + expect 0 unlink ${n0} + ;; +esac diff --git a/tests/open/11.t b/tests/open/11.t new file mode 100644 index 000000000000..e4a3a2d45e8f --- /dev/null +++ b/tests/open/11.t @@ -0,0 +1,56 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/open/11.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="open returns EPERM when the named file has its append-only flag set, the file is to be modified, and O_TRUNC is specified or O_APPEND is not specified" + +dir=`dirname $0` +. ${dir}/../misc.sh + +require chflags + +case "${os}:${fs}" in +FreeBSD:ZFS) + echo "1..12" + ;; +FreeBSD:UFS) + echo "1..24" + ;; +*) + quick_exit +esac + +n0=`namegen` + +expect 0 create ${n0} 0644 +expect 0 chflags ${n0} SF_APPEND +expect 0 open ${n0} O_WRONLY,O_APPEND +expect 0 open ${n0} O_RDWR,O_APPEND +expect EPERM open ${n0} O_WRONLY +expect EPERM open ${n0} O_RDWR +todo FreeBSD:ZFS "When fle is protected by SF_APPEND, open(O_TRUNC) should return EPERM." +expect EPERM open ${n0} O_RDONLY,O_TRUNC +todo FreeBSD:ZFS "When fle is protected by SF_APPEND, open(O_TRUNC) should return EPERM." +expect EPERM open ${n0} O_RDONLY,O_APPEND,O_TRUNC +todo FreeBSD:ZFS "When fle is protected by SF_APPEND, open(O_TRUNC) should return EPERM." +expect EPERM open ${n0} O_WRONLY,O_APPEND,O_TRUNC +todo FreeBSD:ZFS "When fle is protected by SF_APPEND, open(O_TRUNC) should return EPERM." +expect EPERM open ${n0} O_RDWR,O_APPEND,O_TRUNC +expect 0 chflags ${n0} none +expect 0 unlink ${n0} + +case "${os}:${fs}" in +FreeBSD:UFS) + expect 0 create ${n0} 0644 + expect 0 chflags ${n0} UF_APPEND + expect 0 open ${n0} O_WRONLY,O_APPEND + expect 0 open ${n0} O_RDWR,O_APPEND + expect EPERM open ${n0} O_WRONLY + expect EPERM open ${n0} O_RDWR + expect EPERM open ${n0} O_RDONLY,O_TRUNC + expect EPERM open ${n0} O_RDONLY,O_APPEND,O_TRUNC + expect EPERM open ${n0} O_WRONLY,O_APPEND,O_TRUNC + expect EPERM open ${n0} O_RDWR,O_APPEND,O_TRUNC + expect 0 chflags ${n0} none + expect 0 unlink ${n0} + ;; +esac diff --git a/tests/open/12.t b/tests/open/12.t new file mode 100644 index 000000000000..d38309d4a118 --- /dev/null +++ b/tests/open/12.t @@ -0,0 +1,19 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/open/12.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="open returns ELOOP if too many symbolic links were encountered in translating the pathname" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..6" + +n0=`namegen` +n1=`namegen` + +expect 0 symlink ${n0} ${n1} +expect 0 symlink ${n1} ${n0} +expect ELOOP open ${n0}/test O_RDONLY +expect ELOOP open ${n1}/test O_RDONLY +expect 0 unlink ${n0} +expect 0 unlink ${n1} diff --git a/tests/open/13.t b/tests/open/13.t new file mode 100644 index 000000000000..64bb0b8f825f --- /dev/null +++ b/tests/open/13.t @@ -0,0 +1,24 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/open/13.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="open returns EISDIR when trying to open a directory for writing" + +dir=`dirname $0` +. ${dir}/../misc.sh + +require chflags + +echo "1..8" + +n0=`namegen` + +expect 0 mkdir ${n0} 0755 + +expect 0 open ${n0} O_RDONLY +expect EISDIR open ${n0} O_WRONLY +expect EISDIR open ${n0} O_RDWR +expect EISDIR open ${n0} O_RDONLY,O_TRUNC +expect EISDIR open ${n0} O_WRONLY,O_TRUNC +expect EISDIR open ${n0} O_RDWR,O_TRUNC + +expect 0 rmdir ${n0} diff --git a/tests/open/14.t b/tests/open/14.t new file mode 100644 index 000000000000..a9c637f4cc0d --- /dev/null +++ b/tests/open/14.t @@ -0,0 +1,32 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/open/14.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="open returns EROFS if the named file resides on a read-only file system, and the file is to be modified" + +dir=`dirname $0` +. ${dir}/../misc.sh + +[ "${os}:${fs}" = "FreeBSD:UFS" ] || quick_exit + +echo "1..10" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +n=`mdconfig -a -n -t malloc -s 1m` +newfs /dev/md${n} >/dev/null +mount /dev/md${n} ${n0} +expect 0 create ${n0}/${n1} 0644 +expect 0 open ${n0}/${n1} O_WRONLY +expect 0 open ${n0}/${n1} O_RDWR +expect 0 open ${n0}/${n1} O_RDONLY,O_TRUNC +mount -ur /dev/md${n} +expect EROFS open ${n0}/${n1} O_WRONLY +expect EROFS open ${n0}/${n1} O_RDWR +expect EROFS open ${n0}/${n1} O_RDONLY,O_TRUNC +mount -uw /dev/md${n} +expect 0 unlink ${n0}/${n1} +umount /dev/md${n} +mdconfig -d -u ${n} +expect 0 rmdir ${n0} diff --git a/tests/open/15.t b/tests/open/15.t new file mode 100644 index 000000000000..1e00db130fe4 --- /dev/null +++ b/tests/open/15.t @@ -0,0 +1,27 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/open/15.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="open returns EROFS when O_CREAT is specified and the named file would reside on a read-only file system" + +dir=`dirname $0` +. ${dir}/../misc.sh + +[ "${os}:${fs}" = "FreeBSD:UFS" ] || quick_exit + +echo "1..5" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +n=`mdconfig -a -n -t malloc -s 1m` +newfs /dev/md${n} >/dev/null +mount /dev/md${n} ${n0} +expect 0 open ${n0}/${n1} O_RDONLY,O_CREAT 0644 +expect 0 unlink ${n0}/${n1} +mount -ur /dev/md${n} +expect EROFS open ${n0}/${n1} O_RDONLY,O_CREAT 0644 +mount -uw /dev/md${n} +umount /dev/md${n} +mdconfig -d -u ${n} +expect 0 rmdir ${n0} diff --git a/tests/open/16.t b/tests/open/16.t new file mode 100644 index 000000000000..598ed895a68e --- /dev/null +++ b/tests/open/16.t @@ -0,0 +1,19 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/open/16.t 219621 2011-03-13 19:35:13Z pjd $ + +desc="open returns ELOOP when O_NOFOLLOW was specified and the target is a symbolic link" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..6" + +n0=`namegen` +n1=`namegen` + +expect 0 symlink ${n0} ${n1} +expect ELOOP open ${n1} O_RDONLY,O_CREAT,O_NOFOLLOW 0644 +expect ELOOP open ${n1} O_RDONLY,O_NOFOLLOW +expect ELOOP open ${n1} O_WRONLY,O_NOFOLLOW +expect ELOOP open ${n1} O_RDWR,O_NOFOLLOW +expect 0 unlink ${n1} diff --git a/tests/open/17.t b/tests/open/17.t new file mode 100644 index 000000000000..e5888fc176f2 --- /dev/null +++ b/tests/open/17.t @@ -0,0 +1,15 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/open/17.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="open returns ENXIO when O_NONBLOCK is set, the named file is a fifo, O_WRONLY is set, and no process has the file open for reading" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..3" + +n0=`namegen` + +expect 0 mkfifo ${n0} 0644 +expect ENXIO open ${n0} O_WRONLY,O_NONBLOCK +expect 0 unlink ${n0} diff --git a/tests/open/18.t b/tests/open/18.t new file mode 100644 index 000000000000..6d0713b43a89 --- /dev/null +++ b/tests/open/18.t @@ -0,0 +1,20 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/open/18.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="open returns EWOULDBLOCK when O_NONBLOCK and one of O_SHLOCK or O_EXLOCK is specified and the file is locked" + +dir=`dirname $0` +. ${dir}/../misc.sh + +[ "${os}" = "FreeBSD" ] || quick_exit + +echo "1..6" + +n0=`namegen` + +expect 0 create ${n0} 0644 +expect 0 open ${n0} O_RDONLY,O_SHLOCK : open ${n0} O_RDONLY,O_SHLOCK,O_NONBLOCK +expect "EWOULDBLOCK|EAGAIN" open ${n0} O_RDONLY,O_EXLOCK : open ${n0} O_RDONLY,O_EXLOCK,O_NONBLOCK +expect "EWOULDBLOCK|EAGAIN" open ${n0} O_RDONLY,O_SHLOCK : open ${n0} O_RDONLY,O_EXLOCK,O_NONBLOCK +expect "EWOULDBLOCK|EAGAIN" open ${n0} O_RDONLY,O_EXLOCK : open ${n0} O_RDONLY,O_SHLOCK,O_NONBLOCK +expect 0 unlink ${n0} diff --git a/tests/open/19.t b/tests/open/19.t new file mode 100644 index 000000000000..29f2a3689f02 --- /dev/null +++ b/tests/open/19.t @@ -0,0 +1,31 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/open/19.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="open returns ENOSPC when O_CREAT is specified, the file does not exist, and there are no free inodes on the file system on which the file is being created" + +dir=`dirname $0` +. ${dir}/../misc.sh + +[ "${os}:${fs}" = "FreeBSD:UFS" ] || quick_exit + +echo "1..3" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +n=`mdconfig -a -n -t malloc -s 256k` +newfs /dev/md${n} >/dev/null +mount /dev/md${n} ${n0} +i=0 +while :; do + touch ${n0}/${i} >/dev/null 2>&1 + if [ $? -ne 0 ]; then + break + fi + i=`expr $i + 1` +done +expect ENOSPC open ${n0}/${i} O_RDONLY,O_CREAT 0644 +umount /dev/md${n} +mdconfig -d -u ${n} +expect 0 rmdir ${n0} diff --git a/tests/open/20.t b/tests/open/20.t new file mode 100644 index 000000000000..de80b6122b7d --- /dev/null +++ b/tests/open/20.t @@ -0,0 +1,20 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/open/20.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="open returns ETXTBSY when the file is a pure procedure (shared text) file that is being executed and the open() system call requests write access" + +dir=`dirname $0` +. ${dir}/../misc.sh + +[ "${os}:${fs}" = "FreeBSD:UFS" ] || quick_exit + +echo "1..4" + +n0=`namegen` + +cp -pf `which sleep` ${n0} +./${n0} 3 & +expect ETXTBSY open ${n0} O_WRONLY +expect ETXTBSY open ${n0} O_RDWR +expect ETXTBSY open ${n0} O_RDONLY,O_TRUNC +expect 0 unlink ${n0} diff --git a/tests/open/21.t b/tests/open/21.t new file mode 100644 index 000000000000..4a2422cfa6aa --- /dev/null +++ b/tests/open/21.t @@ -0,0 +1,12 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/open/21.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="open returns EFAULT if the path argument points outside the process's allocated address space" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..2" + +expect EFAULT open NULL O_RDONLY +expect EFAULT open DEADCODE O_RDONLY diff --git a/tests/open/22.t b/tests/open/22.t new file mode 100644 index 000000000000..55d4b9b3f8a3 --- /dev/null +++ b/tests/open/22.t @@ -0,0 +1,21 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/open/22.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="open returns EEXIST when O_CREAT and O_EXCL were specified and the file exists" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..21" + +n0=`namegen` + +for type in regular dir fifo block char socket symlink; do + create_file ${type} ${n0} + expect EEXIST open ${n0} O_CREAT,O_EXCL 0644 + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n0} + else + expect 0 unlink ${n0} + fi +done diff --git a/tests/open/23.t b/tests/open/23.t new file mode 100644 index 000000000000..4728c18896cd --- /dev/null +++ b/tests/open/23.t @@ -0,0 +1,17 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/open/23.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="open may return EINVAL when an attempt was made to open a descriptor with an illegal combination of O_RDONLY, O_WRONLY, and O_RDWR" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..5" + +n0=`namegen` + +expect 0 create ${n0} 0644 +expect "0|EINVAL" open ${n0} O_RDONLY,O_RDWR +expect "0|EINVAL" open ${n0} O_WRONLY,O_RDWR +expect "0|EINVAL" open ${n0} O_RDONLY,O_WRONLY,O_RDWR +expect 0 unlink ${n0} diff --git a/tests/open/24.t b/tests/open/24.t new file mode 100644 index 000000000000..ca709f221214 --- /dev/null +++ b/tests/open/24.t @@ -0,0 +1,17 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/open/24.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="open returns EOPNOTSUPP when trying to open UNIX domain socket" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..5" + +n0=`namegen` + +expect 0 bind ${n0} +expect "EOPNOTSUPP" open ${n0} O_RDONLY +expect "EOPNOTSUPP" open ${n0} O_WRONLY +expect "EOPNOTSUPP" open ${n0} O_RDWR +expect 0 unlink ${n0} diff --git a/tests/rename/00.t b/tests/rename/00.t new file mode 100644 index 000000000000..2126a86a5488 --- /dev/null +++ b/tests/rename/00.t @@ -0,0 +1,91 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/rename/00.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="rename changes file name" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..150" + +n0=`namegen` +n1=`namegen` +n2=`namegen` +n3=`namegen` + +expect 0 mkdir ${n3} 0755 +cdir=`pwd` +cd ${n3} + +for type in regular fifo block char socket; do + create_file ${type} ${n0} 0644 + expect ${type},0644,1 lstat ${n0} type,mode,nlink + inode=`${fstest} lstat ${n0} inode` + expect 0 rename ${n0} ${n1} + expect ENOENT lstat ${n0} type,mode,nlink + expect ${type},${inode},0644,1 lstat ${n1} type,inode,mode,nlink + expect 0 link ${n1} ${n0} + expect ${type},${inode},0644,2 lstat ${n0} type,inode,mode,nlink + expect ${type},${inode},0644,2 lstat ${n1} type,inode,mode,nlink + expect 0 rename ${n1} ${n2} + expect ${type},${inode},0644,2 lstat ${n0} type,inode,mode,nlink + expect ENOENT lstat ${n1} type,mode,nlink + expect ${type},${inode},0644,2 lstat ${n2} type,inode,mode,nlink + expect 0 unlink ${n0} + expect 0 unlink ${n2} +done + +expect 0 mkdir ${n0} 0755 +expect dir,0755 lstat ${n0} type,mode +inode=`${fstest} lstat ${n0} inode` +expect 0 rename ${n0} ${n1} +expect ENOENT lstat ${n0} type,mode +expect dir,${inode},0755 lstat ${n1} type,inode,mode +expect 0 rmdir ${n1} + +expect 0 create ${n0} 0644 +rinode=`${fstest} lstat ${n0} inode` +expect regular,0644 lstat ${n0} type,mode +expect 0 symlink ${n0} ${n1} +sinode=`${fstest} lstat ${n1} inode` +expect regular,${rinode},0644 stat ${n1} type,inode,mode +expect symlink,${sinode} lstat ${n1} type,inode +expect 0 rename ${n1} ${n2} +expect regular,${rinode},0644 stat ${n0} type,inode,mode +expect ENOENT lstat ${n1} type,mode +expect symlink,${sinode} lstat ${n2} type,inode +expect 0 unlink ${n0} +expect 0 unlink ${n2} + +# successful rename(2) updates ctime. +for type in regular dir fifo block char socket symlink; do + create_file ${type} ${n0} + ctime1=`${fstest} lstat ${n0} ctime` + sleep 1 + expect 0 rename ${n0} ${n1} + ctime2=`${fstest} lstat ${n1} ctime` + test_check $ctime1 -lt $ctime2 + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n1} + else + expect 0 unlink ${n1} + fi +done + +# unsuccessful link(2) does not update ctime. +for type in regular dir fifo block char socket symlink; do + create_file ${type} ${n0} + ctime1=`${fstest} lstat ${n0} ctime` + sleep 1 + expect EACCES -u 65534 rename ${n0} ${n1} + ctime2=`${fstest} lstat ${n0} ctime` + test_check $ctime1 -eq $ctime2 + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n0} + else + expect 0 unlink ${n0} + fi +done + +cd ${cdir} +expect 0 rmdir ${n3} diff --git a/tests/rename/01.t b/tests/rename/01.t new file mode 100644 index 000000000000..dbb9c0660d41 --- /dev/null +++ b/tests/rename/01.t @@ -0,0 +1,23 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/rename/01.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="rename returns ENAMETOOLONG if a component of either pathname exceeded {NAME_MAX} characters" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..8" + +n0=`namegen` +nx=`namegen_max` +nxx="${nx}x" + +expect 0 create ${nx} 0644 +expect 0 rename ${nx} ${n0} +expect 0 rename ${n0} ${nx} +expect 0 unlink ${nx} + +expect 0 create ${n0} 0644 +expect ENAMETOOLONG rename ${n0} ${nxx} +expect 0 unlink ${n0} +expect ENAMETOOLONG rename ${nxx} ${n0} diff --git a/tests/rename/02.t b/tests/rename/02.t new file mode 100644 index 000000000000..23425bada559 --- /dev/null +++ b/tests/rename/02.t @@ -0,0 +1,24 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/rename/02.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="rename returns ENAMETOOLONG if an entire length of either path name exceeded {PATH_MAX} characters" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..6" + +n0=`namegen` +nx=`dirgen_max` +nxx="${nx}x" + +mkdir -p "${nx%/*}" + +expect 0 create ${n0} 0644 +expect 0 rename ${n0} ${nx} +expect 0 rename ${nx} ${n0} +expect ENAMETOOLONG rename ${n0} ${nxx} +expect 0 unlink ${n0} +expect ENAMETOOLONG rename ${nxx} ${n0} + +rm -rf "${nx%%/*}" diff --git a/tests/rename/03.t b/tests/rename/03.t new file mode 100644 index 000000000000..fb1d16f10d10 --- /dev/null +++ b/tests/rename/03.t @@ -0,0 +1,20 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/rename/03.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="rename returns ENOENT if a component of the 'from' path does not exist, or a path prefix of 'to' does not exist" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..6" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n0} 0755 +expect ENOENT rename ${n0}/${n1}/test ${n2} +expect 0 create ${n2} 0644 +expect ENOENT rename ${n2} ${n0}/${n1}/test +expect 0 unlink ${n2} +expect 0 rmdir ${n0} diff --git a/tests/rename/04.t b/tests/rename/04.t new file mode 100644 index 000000000000..19d1791a71a8 --- /dev/null +++ b/tests/rename/04.t @@ -0,0 +1,43 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/rename/04.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="rename returns EACCES when a component of either path prefix denies search permission" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..18" + +n0=`namegen` +n1=`namegen` +n2=`namegen` +n3=`namegen` +n4=`namegen` + +expect 0 mkdir ${n0} 0755 +cdir=`pwd` +cd ${n0} + +expect 0 mkdir ${n1} 0755 +expect 0 chown ${n1} 65534 65534 +expect 0 mkdir ${n2} 0755 +expect 0 chown ${n2} 65534 65534 +expect 0 -u 65534 -g 65534 create ${n1}/${n3} 0644 + +expect 0 -u 65534 -g 65534 rename ${n1}/${n3} ${n2}/${n4} +expect 0 -u 65534 -g 65534 rename ${n2}/${n4} ${n1}/${n3} + +expect 0 chmod ${n1} 0644 +expect EACCES -u 65534 -g 65534 rename ${n1}/${n3} ${n1}/${n4} +expect EACCES -u 65534 -g 65534 rename ${n1}/${n3} ${n2}/${n4} + +expect 0 chmod ${n1} 0755 +expect 0 chmod ${n2} 0644 +expect EACCES -u 65534 -g 65534 rename ${n1}/${n3} ${n2}/${n4} + +expect 0 unlink ${n1}/${n3} +expect 0 rmdir ${n1} +expect 0 rmdir ${n2} + +cd ${cdir} +expect 0 rmdir ${n0} diff --git a/tests/rename/05.t b/tests/rename/05.t new file mode 100644 index 000000000000..52deac153b8c --- /dev/null +++ b/tests/rename/05.t @@ -0,0 +1,41 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/rename/05.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="rename returns EACCES when the requested link requires writing in a directory with a mode that denies write permission" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..17" + +n0=`namegen` +n1=`namegen` +n2=`namegen` +n3=`namegen` +n4=`namegen` + +expect 0 mkdir ${n0} 0755 +cdir=`pwd` +cd ${n0} + +expect 0 mkdir ${n1} 0755 +expect 0 chown ${n1} 65534 65534 +expect 0 mkdir ${n2} 0755 +expect 0 chown ${n2} 65534 65534 +expect 0 -u 65534 -g 65534 create ${n1}/${n3} 0644 + +expect 0 -u 65534 -g 65534 rename ${n1}/${n3} ${n2}/${n4} +expect 0 -u 65534 -g 65534 rename ${n2}/${n4} ${n1}/${n3} + +expect 0 chmod ${n2} 0555 +expect EACCES -u 65534 -g 65534 rename ${n1}/${n3} ${n2}/${n4} +expect 0 chmod ${n1} 0555 +expect EACCES -u 65534 -g 65534 rename ${n1}/${n3} ${n1}/${n4} +expect 0 chmod ${n1} 0755 + +expect 0 unlink ${n1}/${n3} +expect 0 rmdir ${n1} +expect 0 rmdir ${n2} + +cd ${cdir} +expect 0 rmdir ${n0} diff --git a/tests/rename/06.t b/tests/rename/06.t new file mode 100644 index 000000000000..ffcf61e83a5c --- /dev/null +++ b/tests/rename/06.t @@ -0,0 +1,61 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/rename/06.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="rename returns EPERM if the file pointed at by the 'from' argument has its immutable, undeletable or append-only flag set" + +dir=`dirname $0` +. ${dir}/../misc.sh + +require chflags + +case "${os}:${fs}" in +FreeBSD:ZFS) + flags="SF_IMMUTABLE SF_NOUNLINK SF_APPEND" + echo "1..195" + ;; +FreeBSD:UFS) + flags="SF_IMMUTABLE SF_NOUNLINK SF_APPEND UF_IMMUTABLE UF_NOUNLINK UF_APPEND" + echo "1..351" + ;; +*) + quick_exit +esac + +n0=`namegen` +n1=`namegen` + +for type in regular dir fifo block char socket symlink; do + if [ "${type}" != "symlink" ]; then + create_file ${type} ${n0} + for flag in ${flags}; do + expect 0 chflags ${n0} ${flag} + expect ${flag} stat ${n0} flags + [ "${flag}" = "SF_APPEND" ] && todo FreeBSD:ZFS "Renaming a file protected by SF_APPEND should return EPERM." + expect EPERM rename ${n0} ${n1} + [ "${flag}" = "SF_APPEND" ] && todo FreeBSD:ZFS "Renaming a file protected by SF_APPEND should return EPERM." + expect ENOENT rename ${n1} ${n0} + done + expect 0 chflags ${n0} none + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n0} + else + expect 0 unlink ${n0} + fi + fi + + create_file ${type} ${n0} + for flag in ${flags}; do + expect 0 lchflags ${n0} ${flag} + expect ${flag} lstat ${n0} flags + [ "${flag}" = "SF_APPEND" ] && todo FreeBSD:ZFS "Renaming a file protected by SF_APPEND should return EPERM." + expect EPERM rename ${n0} ${n1} + [ "${flag}" = "SF_APPEND" ] && todo FreeBSD:ZFS "Renaming a file protected by SF_APPEND should return EPERM." + expect ENOENT rename ${n1} ${n0} + done + expect 0 lchflags ${n0} none + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n0} + else + expect 0 unlink ${n0} + fi +done diff --git a/tests/rename/07.t b/tests/rename/07.t new file mode 100644 index 000000000000..522e67df9181 --- /dev/null +++ b/tests/rename/07.t @@ -0,0 +1,66 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/rename/07.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="rename returns EPERM if the parent directory of the file pointed at by the 'from' argument has its immutable or append-only flag set" + +dir=`dirname $0` +. ${dir}/../misc.sh + +require chflags + +case "${os}:${fs}" in +FreeBSD:ZFS) + flags1="SF_IMMUTABLE SF_APPEND" + flags2="SF_NOUNLINK" + echo "1..128" + ;; +FreeBSD:UFS) + flags1="SF_IMMUTABLE SF_APPEND UF_IMMUTABLE UF_APPEND" + flags2="SF_NOUNLINK UF_NOUNLINK" + echo "1..212" + ;; +*) + quick_exit +esac + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n0} 0755 + +for type in regular dir fifo block char socket symlink; do + create_file ${type} ${n0}/${n1} + for flag in ${flags1}; do + expect 0 chflags ${n0} ${flag} + expect ${flag} stat ${n0} flags + [ "${flag}" = "SF_APPEND" ] && todo FreeBSD:ZFS "Renaming a file protected by SF_APPEND should return EPERM." + expect EPERM rename ${n0}/${n1} ${n2} + [ "${flag}" = "SF_APPEND" ] && todo FreeBSD:ZFS "Renaming a file protected by SF_APPEND should return EPERM." + expect ENOENT rename ${n2} ${n0}/${n1} + done + expect 0 chflags ${n0} none + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n0}/${n1} + else + expect 0 unlink ${n0}/${n1} + fi +done + +for type in regular dir fifo block char socket symlink; do + create_file ${type} ${n0}/${n1} + for flag in ${flags2}; do + expect 0 chflags ${n0} ${flag} + expect ${flag} stat ${n0} flags + expect 0 rename ${n0}/${n1} ${n2} + expect 0 rename ${n2} ${n0}/${n1} + done + expect 0 chflags ${n0} none + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n0}/${n1} + else + expect 0 unlink ${n0}/${n1} + fi +done + +expect 0 rmdir ${n0} diff --git a/tests/rename/08.t b/tests/rename/08.t new file mode 100644 index 000000000000..beffb41f8785 --- /dev/null +++ b/tests/rename/08.t @@ -0,0 +1,63 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/rename/08.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="rename returns EPERM if the parent directory of the file pointed at by the 'to' argument has its immutable flag set" + +dir=`dirname $0` +. ${dir}/../misc.sh + +require chflags + +case "${os}:${fs}" in +FreeBSD:ZFS) + flags1="SF_IMMUTABLE" + flags2="SF_NOUNLINK SF_APPEND" + echo "1..128" + ;; +FreeBSD:UFS) + flags1="SF_IMMUTABLE UF_IMMUTABLE" + flags2="SF_NOUNLINK SF_APPEND UF_NOUNLINK UF_APPEND" + echo "1..219" + ;; +*) + quick_exit +esac + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n0} 0755 + +for type in regular dir fifo block char socket symlink; do + create_file ${type} ${n1} + for flag in ${flags1}; do + expect 0 chflags ${n0} ${flag} + expect ${flag} stat ${n0} flags + expect EPERM rename ${n1} ${n0}/${n2} + done + expect 0 chflags ${n0} none + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n1} + else + expect 0 unlink ${n1} + fi +done + +for type in regular dir fifo block char socket symlink; do + create_file ${type} ${n1} + for flag in ${flags2}; do + expect 0 chflags ${n0} ${flag} + expect ${flag} stat ${n0} flags + expect 0 rename ${n1} ${n0}/${n2} + expect 0 chflags ${n0} none + expect 0 rename ${n0}/${n2} ${n1} + done + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n1} + else + expect 0 unlink ${n1} + fi +done + +expect 0 rmdir ${n0} diff --git a/tests/rename/09.t b/tests/rename/09.t new file mode 100644 index 000000000000..299ff64c57e0 --- /dev/null +++ b/tests/rename/09.t @@ -0,0 +1,191 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/rename/09.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="rename returns EACCES or EPERM if the directory containing 'from' is marked sticky, and neither the containing directory nor 'from' are owned by the effective user ID" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..2353" + +n0=`namegen` +n1=`namegen` +n2=`namegen` +n3=`namegen` +n4=`namegen` + +expect 0 mkdir ${n4} 0755 +cdir=`pwd` +cd ${n4} + +expect 0 mkdir ${n0} 0755 +expect 0 chmod ${n0} 01777 +expect 0 chown ${n0} 65534 65534 + +expect 0 mkdir ${n1} 0755 +expect 0 chown ${n1} 65534 65534 + +for type in regular fifo block char socket symlink; do + # User owns both: the source sticky directory and the source file. + expect 0 chown ${n0} 65534 65534 + create_file ${type} ${n0}/${n2} 65534 65534 + inode=`${fstest} lstat ${n0}/${n2} inode` + + for type in none regular fifo block char socket symlink; do + create_file ${type} ${n1}/${n3} 65534 65534 + expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3} + expect ENOENT lstat ${n0}/${n2} inode + expect ${inode},65534,65534 lstat ${n1}/${n3} inode,uid,gid + expect 0 -u 65534 -g 65534 rename ${n1}/${n3} ${n0}/${n2} + expect ${inode} lstat ${n0}/${n2} inode + expect ENOENT lstat ${n1}/${n3} inode + done + + expect 0 unlink ${n0}/${n2} + + # User owns the source sticky directory, but doesn't own the source file. + for id in 0 65533; do + expect 0 chown ${n0} 65534 65534 + create_file ${type} ${n0}/${n2} ${id} ${id} + inode=`${fstest} lstat ${n0}/${n2} inode` + + for type in none regular fifo block char socket symlink; do + create_file ${type} ${n1}/${n3} 65534 65534 + expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3} + expect ENOENT lstat ${n0}/${n2} inode + expect ${inode},${id},${id} lstat ${n1}/${n3} inode,uid,gid + expect 0 -u 65534 -g 65534 rename ${n1}/${n3} ${n0}/${n2} + expect ${inode} lstat ${n0}/${n2} inode + expect ENOENT lstat ${n1}/${n3} inode + done + + expect 0 unlink ${n0}/${n2} + done + + # User owns the source file, but doesn't own the source sticky directory. + for id in 0 65533; do + expect 0 chown ${n0} ${id} ${id} + create_file ${type} ${n0}/${n2} 65534 65534 + inode=`${fstest} lstat ${n0}/${n2} inode` + + for type in none regular fifo block char socket symlink; do + create_file ${type} ${n1}/${n3} 65534 65534 + expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3} + expect ENOENT lstat ${n0}/${n2} inode + expect ${inode},65534,65534 lstat ${n1}/${n3} inode,uid,gid + expect 0 -u 65534 -g 65534 rename ${n1}/${n3} ${n0}/${n2} + expect ${inode} lstat ${n0}/${n2} inode + expect ENOENT lstat ${n1}/${n3} inode + done + + expect 0 unlink ${n0}/${n2} + done + + # User doesn't own the source sticky directory nor the source file. + for id in 0 65533; do + expect 0 chown ${n0} ${id} ${id} + create_file ${type} ${n0}/${n2} ${id} ${id} + inode=`${fstest} lstat ${n0}/${n2} inode` + + for type in none regular fifo block char socket symlink; do + create_file ${type} ${n1}/${n3} 65534 65534 + expect "EACCES|EPERM" -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3} + expect ${inode},${id},${id} lstat ${n0}/${n2} inode,uid,gid + if [ "${type}" != "none" ]; then + expect 65534,65534 lstat ${n1}/${n3} uid,gid + expect 0 unlink ${n1}/${n3} + fi + done + + expect 0 unlink ${n0}/${n2} + done +done + +# User owns both: the source sticky directory and the source directory. +expect 0 chown ${n0} 65534 65534 +create_file dir ${n0}/${n2} 65534 65534 +inode=`${fstest} lstat ${n0}/${n2} inode` + +expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3} +expect ENOENT lstat ${n0}/${n2} type +expect ${inode},65534,65534 lstat ${n1}/${n3} inode,uid,gid +expect 0 rename ${n1}/${n3} ${n0}/${n2} + +expect 0 -u 65534 -g 65534 mkdir ${n1}/${n3} 0755 +expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3} +expect ENOENT lstat ${n0}/${n2} type +expect ${inode},65534,65534 lstat ${n1}/${n3} inode,uid,gid +expect 0 rmdir ${n1}/${n3} + +# User owns the source sticky directory, but doesn't own the source directory. +# This fails when changing parent directory, because this will modify +# source directory inode (the .. link in it), but we can still rename it +# without changing its parent directory. +for id in 0 65533; do + expect 0 chown ${n0} 65534 65534 + create_file dir ${n0}/${n2} ${id} ${id} + inode=`${fstest} lstat ${n0}/${n2} inode` + + expect "EACCES|EPERM" -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3} + expect ${inode},${id},${id} lstat ${n0}/${n2} inode,uid,gid + expect ENOENT lstat ${n1}/${n3} type + + expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n0}/${n3} + expect ENOENT lstat ${n0}/${n2} type + expect ${inode},${id},${id} lstat ${n0}/${n3} inode,uid,gid + expect 0 rename ${n0}/${n3} ${n0}/${n2} + + expect 0 -u 65534 -g 65534 mkdir ${n1}/${n3} 0755 + expect "EACCES|EPERM" -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3} + expect ${inode},${id},${id} lstat ${n0}/${n2} inode,uid,gid + expect dir,${id},${id} lstat ${n0}/${n2} type,uid,gid + expect 0 rmdir ${n1}/${n3} + + expect 0 -u 65534 -g 65534 mkdir ${n0}/${n3} 0755 + expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n0}/${n3} + expect ENOENT lstat ${n0}/${n2} type + expect ${inode},${id},${id} lstat ${n0}/${n3} inode,uid,gid + expect 0 rmdir ${n0}/${n3} +done + +# User owns the source directory, but doesn't own the source sticky directory. +for id in 0 65533; do + expect 0 chown ${n0} ${id} ${id} + create_file dir ${n0}/${n2} 65534 65534 + inode=`${fstest} lstat ${n0}/${n2} inode` + + expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3} + expect ENOENT lstat ${n0}/${n2} type + expect ${inode},65534,65534 lstat ${n1}/${n3} inode,uid,gid + expect 0 rename ${n1}/${n3} ${n0}/${n2} + + expect 0 -u 65534 -g 65534 mkdir ${n1}/${n3} 0755 + expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3} + expect ENOENT lstat ${n0}/${n2} type + expect ${inode},65534,65534 lstat ${n1}/${n3} inode,uid,gid + expect 0 rmdir ${n1}/${n3} +done + +# User doesn't own the source sticky directory nor the source directory. +for id in 0 65533; do + expect 0 chown ${n0} ${id} ${id} + create_file dir ${n0}/${n2} ${id} ${id} + inode=`${fstest} lstat ${n0}/${n2} inode` + + expect "EACCES|EPERM" -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3} + expect ${inode},${id},${id} lstat ${n0}/${n2} inode,uid,gid + expect ENOENT lstat ${n1}/${n3} type + + expect 0 -u 65534 -g 65534 mkdir ${n1}/${n3} 0755 + expect "EACCES|EPERM" -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3} + expect ${inode},${id},${id} lstat ${n0}/${n2} inode,uid,gid + expect dir,65534,65534 lstat ${n1}/${n3} type,uid,gid + expect 0 rmdir ${n0}/${n2} + expect 0 rmdir ${n1}/${n3} +done + +expect 0 rmdir ${n1} +expect 0 rmdir ${n0} + +cd ${cdir} +expect 0 rmdir ${n4} diff --git a/tests/rename/10.t b/tests/rename/10.t new file mode 100644 index 000000000000..268c3b647de1 --- /dev/null +++ b/tests/rename/10.t @@ -0,0 +1,156 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/rename/10.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="rename returns EACCES or EPERM if the file pointed at by the 'to' argument exists, the directory containing 'to' is marked sticky, and neither the containing directory nor 'to' are owned by the effective user ID" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..2099" + +n0=`namegen` +n1=`namegen` +n2=`namegen` +n3=`namegen` +n4=`namegen` + +expect 0 mkdir ${n4} 0755 +cdir=`pwd` +cd ${n4} + +expect 0 mkdir ${n0} 0755 +expect 0 chown ${n0} 65534 65534 + +expect 0 mkdir ${n1} 0755 +expect 0 chmod ${n1} 01777 + +for type in regular fifo block char socket symlink; do + # User owns both: the sticky directory and the destination file. + expect 0 chown ${n1} 65534 65534 + create_file ${type} ${n0}/${n2} 65534 65534 + inode=`${fstest} lstat ${n0}/${n2} inode` + + for type in regular fifo block char socket symlink; do + create_file ${type} ${n1}/${n3} 65534 65534 + expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3} + expect ENOENT lstat ${n0}/${n2} inode + expect ${inode} lstat ${n1}/${n3} inode + expect 0 -u 65534 -g 65534 rename ${n1}/${n3} ${n0}/${n2} + expect ${inode} lstat ${n0}/${n2} inode + expect ENOENT lstat ${n1}/${n3} inode + done + + expect 0 unlink ${n0}/${n2} + + # User owns the sticky directory, but doesn't own the destination file. + for id in 0 65533; do + expect 0 chown ${n1} 65534 65534 + create_file ${type} ${n0}/${n2} 65534 65534 + inode=`${fstest} lstat ${n0}/${n2} inode` + + for type in regular fifo block char socket symlink; do + create_file ${type} ${n1}/${n3} ${id} ${id} + expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3} + expect ENOENT lstat ${n0}/${n2} inode + expect ${inode} lstat ${n1}/${n3} inode + expect 0 -u 65534 -g 65534 rename ${n1}/${n3} ${n0}/${n2} + expect ${inode} lstat ${n0}/${n2} inode + expect ENOENT lstat ${n1}/${n3} inode + done + + expect 0 unlink ${n0}/${n2} + done + + # User owns the destination file, but doesn't own the sticky directory. + for id in 0 65533; do + expect 0 chown ${n1} ${id} ${id} + create_file ${type} ${n0}/${n2} 65534 65534 + inode=`${fstest} lstat ${n0}/${n2} inode` + + for type in regular fifo block char socket symlink; do + create_file ${type} ${n1}/${n3} 65534 65534 + expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3} + expect ENOENT lstat ${n0}/${n2} inode + expect ${inode} lstat ${n1}/${n3} inode + expect 0 -u 65534 -g 65534 rename ${n1}/${n3} ${n0}/${n2} + expect ${inode} lstat ${n0}/${n2} inode + expect ENOENT lstat ${n1}/${n3} inode + done + + expect 0 unlink ${n0}/${n2} + done + + # User doesn't own the sticky directory nor the destination file. + for id in 0 65533; do + expect 0 chown ${n1} ${id} ${id} + create_file ${type} ${n0}/${n2} 65534 65534 + inode=`${fstest} lstat ${n0}/${n2} inode` + + for type in regular fifo block char socket symlink; do + create_file ${type} ${n1}/${n3} ${id} ${id} + expect "EACCES|EPERM" -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3} + expect ${inode} lstat ${n0}/${n2} inode + expect ${id},${id} lstat ${n1}/${n3} uid,gid + expect 0 unlink ${n1}/${n3} + done + + expect 0 unlink ${n0}/${n2} + done +done + +# User owns both: the sticky directory and the destination directory. +expect 0 chown ${n1} 65534 65534 +expect 0 -u 65534 -g 65534 mkdir ${n0}/${n2} 0755 +inode=`${fstest} lstat ${n0}/${n2} inode` + +expect 0 -u 65534 -g 65534 mkdir ${n1}/${n3} 0755 +expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3} +expect ENOENT lstat ${n0}/${n2} type +expect ${inode} lstat ${n1}/${n3} inode +expect 0 rmdir ${n1}/${n3} + +# User owns the sticky directory, but doesn't own the destination directory. +for id in 0 65533; do + expect 0 chown ${n1} 65534 65534 + expect 0 -u 65534 -g 65534 mkdir ${n0}/${n2} 0755 + inode=`${fstest} lstat ${n0}/${n2} inode` + + expect 0 -u ${id} -g ${id} mkdir ${n1}/${n3} 0755 + expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3} + expect ENOENT lstat ${n0}/${n2} type + expect ${inode} lstat ${n1}/${n3} inode + expect 0 rmdir ${n1}/${n3} +done + +# User owns the destination directory, but doesn't own the sticky directory. +for id in 0 65533; do + expect 0 chown ${n1} ${id} ${id} + expect 0 -u 65534 -g 65534 mkdir ${n0}/${n2} 0755 + inode=`${fstest} lstat ${n0}/${n2} inode` + + expect 0 -u 65534 -g 65534 mkdir ${n1}/${n3} 0755 + expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3} + expect ENOENT lstat ${n0}/${n2} type + expect ${inode} lstat ${n1}/${n3} inode + expect 0 rmdir ${n1}/${n3} +done + +# User doesn't own the sticky directory nor the destination directory. +for id in 0 65533; do + expect 0 chown ${n1} ${id} ${id} + expect 0 -u 65534 -g 65534 mkdir ${n0}/${n2} 0755 + inode=`${fstest} lstat ${n0}/${n2} inode` + + expect 0 -u ${id} -g ${id} mkdir ${n1}/${n3} 0755 + expect "EACCES|EPERM" -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3} + expect ${inode} lstat ${n0}/${n2} inode + expect ${id},${id} lstat ${n1}/${n3} uid,gid + expect 0 rmdir ${n0}/${n2} + expect 0 rmdir ${n1}/${n3} +done + +expect 0 rmdir ${n1} +expect 0 rmdir ${n0} + +cd ${cdir} +expect 0 rmdir ${n4} diff --git a/tests/rename/11.t b/tests/rename/11.t new file mode 100644 index 000000000000..3bcd97ed18f3 --- /dev/null +++ b/tests/rename/11.t @@ -0,0 +1,24 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/rename/11.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="rename returns ELOOP if too many symbolic links were encountered in translating one of the pathnames" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..10" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 symlink ${n0} ${n1} +expect 0 symlink ${n1} ${n0} +expect ELOOP rename ${n0}/test ${n2} +expect ELOOP rename ${n1}/test ${n2} +expect 0 create ${n2} 0644 +expect ELOOP rename ${n2} ${n0}/test +expect ELOOP rename ${n2} ${n1}/test +expect 0 unlink ${n0} +expect 0 unlink ${n1} +expect 0 unlink ${n2} diff --git a/tests/rename/12.t b/tests/rename/12.t new file mode 100644 index 000000000000..c8939fe85ebf --- /dev/null +++ b/tests/rename/12.t @@ -0,0 +1,24 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/rename/12.t 211474 2010-08-18 22:06:43Z pjd $ + +desc="rename returns ENOTDIR if a component of either path prefix is not a directory" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..32" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n0} 0755 +for type in regular fifo block char socket; do + create_file ${type} ${n0}/${n1} + expect ENOTDIR rename ${n0}/${n1}/test ${n0}/${n2} + create_file ${type} ${n0}/${n2} + expect ENOTDIR link ${n0}/${n2} ${n0}/${n1}/test + expect 0 unlink ${n0}/${n1} + expect 0 unlink ${n0}/${n2} +done +expect 0 rmdir ${n0} diff --git a/tests/rename/13.t b/tests/rename/13.t new file mode 100644 index 000000000000..00b0bfb6f577 --- /dev/null +++ b/tests/rename/13.t @@ -0,0 +1,24 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/rename/13.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="rename returns ENOTDIR when the 'from' argument is a directory, but 'to' is not a directory" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..32" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 + +for type in regular fifo block char socket symlink; do + create_file ${type} ${n1} + expect ENOTDIR rename ${n0} ${n1} + expect dir lstat ${n0} type + expect ${type} lstat ${n1} type + expect 0 unlink ${n1} +done + +expect 0 rmdir ${n0} diff --git a/tests/rename/14.t b/tests/rename/14.t new file mode 100644 index 000000000000..251a1bd66393 --- /dev/null +++ b/tests/rename/14.t @@ -0,0 +1,24 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/rename/14.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="rename returns EISDIR when the 'to' argument is a directory, but 'from' is not a directory" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..32" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 + +for type in regular fifo block char socket symlink; do + create_file ${type} ${n1} + expect EISDIR rename ${n1} ${n0} + expect dir lstat ${n0} type + expect ${type} lstat ${n1} type + expect 0 unlink ${n1} +done + +expect 0 rmdir ${n0} diff --git a/tests/rename/15.t b/tests/rename/15.t new file mode 100644 index 000000000000..4fc9afbf49bc --- /dev/null +++ b/tests/rename/15.t @@ -0,0 +1,34 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/rename/15.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="rename returns EXDEV if the link named by 'to' and the file named by 'from' are on different file systems" + +dir=`dirname $0` +. ${dir}/../misc.sh + +[ "${os}" = "FreeBSD" ] || quick_exit + +echo "1..23" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n0} 0755 +n=`mdconfig -a -n -t malloc -s 1m` +newfs /dev/md${n} >/dev/null +mount /dev/md${n} ${n0} + +for type in regular dir fifo block char socket symlink; do + create_file ${type} ${n0}/${n1} + expect EXDEV rename ${n0}/${n1} ${n2} + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n0}/${n1} + else + expect 0 unlink ${n0}/${n1} + fi +done + +umount /dev/md${n} +mdconfig -d -u ${n} +expect 0 rmdir ${n0} diff --git a/tests/rename/16.t b/tests/rename/16.t new file mode 100644 index 000000000000..898c95a70a78 --- /dev/null +++ b/tests/rename/16.t @@ -0,0 +1,32 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/rename/16.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="rename returns EROFS if the requested link requires writing in a directory on a read-only file system" + +dir=`dirname $0` +. ${dir}/../misc.sh + +[ "${os}" = "FreeBSD" ] || quick_exit + +echo "1..8" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n0} 0755 +n=`mdconfig -a -n -t malloc -s 1m` +newfs /dev/md${n} >/dev/null +mount /dev/md${n} ${n0} +expect 0 create ${n0}/${n1} 0644 +mount -ur /dev/md${n} + +expect EROFS rename ${n0}/${n1} ${n0}/${n2} +expect EROFS rename ${n0}/${n1} ${n2} +expect 0 create ${n2} 0644 +expect EROFS rename ${n2} ${n0}/${n2} +expect 0 unlink ${n2} + +umount /dev/md${n} +mdconfig -d -u ${n} +expect 0 rmdir ${n0} diff --git a/tests/rename/17.t b/tests/rename/17.t new file mode 100644 index 000000000000..6deb7b704f06 --- /dev/null +++ b/tests/rename/17.t @@ -0,0 +1,20 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/rename/17.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="rename returns EFAULT if one of the pathnames specified is outside the process's allocated address space" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..8" + +n0=`namegen` + +expect 0 create ${n0} 0644 +expect EFAULT rename ${n0} NULL +expect EFAULT rename ${n0} DEADCODE +expect 0 unlink ${n0} +expect EFAULT rename NULL ${n0} +expect EFAULT rename DEADCODE ${n0} +expect EFAULT rename NULL DEADCODE +expect EFAULT rename DEADCODE NULL diff --git a/tests/rename/18.t b/tests/rename/18.t new file mode 100644 index 000000000000..8a9594ec4127 --- /dev/null +++ b/tests/rename/18.t @@ -0,0 +1,22 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/rename/18.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="rename returns EINVAL when the 'from' argument is a parent directory of 'to'" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..6" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n0} 0755 +expect 0 mkdir ${n0}/${n1} 0755 + +expect EINVAL rename ${n0} ${n0}/${n1} +expect EINVAL rename ${n0} ${n0}/${n1}/${n2} + +expect 0 rmdir ${n0}/${n1} +expect 0 rmdir ${n0} diff --git a/tests/rename/19.t b/tests/rename/19.t new file mode 100644 index 000000000000..2cd95615e42b --- /dev/null +++ b/tests/rename/19.t @@ -0,0 +1,22 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/rename/19.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="rename returns EINVAL/EBUSY when an attempt is made to rename '.' or '..'" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..6" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n0} 0755 +expect 0 mkdir ${n0}/${n1} 0755 + +expect "EINVAL|EBUSY" rename ${n0}/${n1}/. ${n2} +expect "EINVAL|EBUSY" rename ${n0}/${n1}/.. ${n2} + +expect 0 rmdir ${n0}/${n1} +expect 0 rmdir ${n0} diff --git a/tests/rename/20.t b/tests/rename/20.t new file mode 100644 index 000000000000..8ec37cf7d4cc --- /dev/null +++ b/tests/rename/20.t @@ -0,0 +1,29 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/rename/20.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="rename returns EEXIST or ENOTEMPTY if the 'to' argument is a directory and is not empty" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..25" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n0} 0755 +expect 0 mkdir ${n1} 0755 + +for type in regular dir fifo block char socket symlink; do + create_file ${type} ${n1}/${n2} + expect "EEXIST|ENOTEMPTY" rename ${n0} ${n1} + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n1}/${n2} + else + expect 0 unlink ${n1}/${n2} + fi +done + +expect 0 rmdir ${n1} +expect 0 rmdir ${n0} diff --git a/tests/rename/21.t b/tests/rename/21.t new file mode 100644 index 000000000000..bba1467069da --- /dev/null +++ b/tests/rename/21.t @@ -0,0 +1,47 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/rename/21.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="write access to subdirectory is required to move it to another directory" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..16" + +n0=`namegen` +n1=`namegen` +n2=`namegen` +n3=`namegen` + +expect 0 mkdir ${n2} 0777 +expect 0 mkdir ${n3} 0777 +cdir=`pwd` + +# Check that write permission on containing directory (${n2}) is enough +# to rename subdirectory (${n0}). If we rename directory write access +# to this directory may also be required. +expect 0 mkdir ${n2}/${n0} 0700 +expect "0|EACCES" -u 65534 -g 65534 rename ${n2}/${n0} ${n2}/${n1} +expect "0|EACCES" -u 65534 -g 65534 rename ${n2}/${n1} ${n2}/${n0} + +# Check that write permission on containing directory (${n2}) is not enough +# to move subdirectory (${n0}) from that directory. +# Actually POSIX says that write access to ${n2} and ${n3} may be enough +# to move ${n0} from ${n2} to ${n3}. +expect "0|EACCES" -u 65534 -g 65534 rename ${n2}/${n0} ${n3}/${n1} + +expect "0|ENOENT" rmdir ${n2}/${n0} +expect ENOENT rmdir ${n2}/${n0} +expect "0|ENOENT" rmdir ${n3}/${n1} +expect ENOENT rmdir ${n3}/${n1} + +# Check that write permission on containing directory (${n2}) is enough +# to move file (${n0}) from that directory. +expect 0 create ${n2}/${n0} 0644 +expect 0 -u 65534 -g 65534 rename ${n2}/${n0} ${n3}/${n1} + +expect 0 unlink ${n3}/${n1} +expect ENOENT unlink ${n2}/${n0} + +expect 0 rmdir ${n3} +expect 0 rmdir ${n2} diff --git a/tests/rmdir/00.t b/tests/rmdir/00.t new file mode 100644 index 000000000000..9e75be6b9884 --- /dev/null +++ b/tests/rmdir/00.t @@ -0,0 +1,28 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/rmdir/00.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="rmdir removes directories" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..10" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +expect dir lstat ${n0} type +expect 0 rmdir ${n0} +expect ENOENT lstat ${n0} type + +expect 0 mkdir ${n0} 0755 +expect 0 mkdir ${n0}/${n1} 0755 +time=`${fstest} stat ${n0} ctime` +sleep 1 +expect 0 rmdir ${n0}/${n1} +mtime=`${fstest} stat ${n0} mtime` +test_check $time -lt $mtime +ctime=`${fstest} stat ${n0} ctime` +test_check $time -lt $ctime +expect 0 rmdir ${n0} diff --git a/tests/rmdir/01.t b/tests/rmdir/01.t new file mode 100644 index 000000000000..b89ffefbe763 --- /dev/null +++ b/tests/rmdir/01.t @@ -0,0 +1,30 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/rmdir/01.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="rmdir returns ENOTDIR if a component of the path is not a directory" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..14" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +expect 0 create ${n0}/${n1} 0644 +expect ENOTDIR rmdir ${n0}/${n1}/test +expect 0 unlink ${n0}/${n1} +expect 0 rmdir ${n0} + +expect 0 create ${n0} 0644 +expect ENOTDIR rmdir ${n0} +expect 0 unlink ${n0} + +expect 0 symlink ${n1} ${n0} +expect ENOTDIR rmdir ${n0} +expect 0 unlink ${n0} + +expect 0 mkfifo ${n0} 0644 +expect ENOTDIR rmdir ${n0} +expect 0 unlink ${n0} diff --git a/tests/rmdir/02.t b/tests/rmdir/02.t new file mode 100644 index 000000000000..eb8a774bf240 --- /dev/null +++ b/tests/rmdir/02.t @@ -0,0 +1,17 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/rmdir/02.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="rmdir returns ENAMETOOLONG if a component of a pathname exceeded {NAME_MAX} characters" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..4" + +nx=`namegen_max` +nxx="${nx}x" + +expect 0 mkdir ${nx} 0755 +expect 0 rmdir ${nx} +expect ENOENT rmdir ${nx} +expect ENAMETOOLONG rmdir ${nxx} diff --git a/tests/rmdir/03.t b/tests/rmdir/03.t new file mode 100644 index 000000000000..3d5a11a3611d --- /dev/null +++ b/tests/rmdir/03.t @@ -0,0 +1,22 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/rmdir/03.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="rmdir returns ENAMETOOLONG if an entire path name exceeded ${PATH_MAX} characters" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..5" + +nx=`dirgen_max` +nxx="${nx}x" + +mkdir -p "${nx%/*}" + +expect 0 mkdir ${nx} 0755 +expect dir,0755 stat ${nx} type,mode +expect 0 rmdir ${nx} +expect ENOENT rmdir ${nx} +expect ENAMETOOLONG rmdir ${nxx} + +rm -rf "${nx%%/*}" diff --git a/tests/rmdir/04.t b/tests/rmdir/04.t new file mode 100644 index 000000000000..d5abc31cfd18 --- /dev/null +++ b/tests/rmdir/04.t @@ -0,0 +1,17 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/rmdir/04.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="rmdir returns ENOENT if the named directory does not exist" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..4" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +expect 0 rmdir ${n0} +expect ENOENT rmdir ${n0} +expect ENOENT rmdir ${n1} diff --git a/tests/rmdir/05.t b/tests/rmdir/05.t new file mode 100644 index 000000000000..eb984533d057 --- /dev/null +++ b/tests/rmdir/05.t @@ -0,0 +1,19 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/rmdir/05.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="rmdir returns ELOOP if too many symbolic links were encountered in translating the pathname" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..6" + +n0=`namegen` +n1=`namegen` + +expect 0 symlink ${n0} ${n1} +expect 0 symlink ${n1} ${n0} +expect ELOOP rmdir ${n0}/test +expect ELOOP rmdir ${n1}/test +expect 0 unlink ${n0} +expect 0 unlink ${n1} diff --git a/tests/rmdir/06.t b/tests/rmdir/06.t new file mode 100644 index 000000000000..64a6ac85fe49 --- /dev/null +++ b/tests/rmdir/06.t @@ -0,0 +1,24 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/rmdir/06.t 211474 2010-08-18 22:06:43Z pjd $ + +desc="rmdir returns EEXIST or ENOTEMPTY the named directory contains files other than '.' and '..' in it" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..23" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +for type in regular dir fifo block char socket symlink; do + create_file ${type} ${n0}/${n1} + expect "EEXIST|ENOTEMPTY" rmdir ${n0} + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n0}/${n1} + else + expect 0 unlink ${n0}/${n1} + fi +done +expect 0 rmdir ${n0} diff --git a/tests/rmdir/07.t b/tests/rmdir/07.t new file mode 100644 index 000000000000..10a78a71e9d5 --- /dev/null +++ b/tests/rmdir/07.t @@ -0,0 +1,27 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/rmdir/07.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="rmdir returns EACCES when search permission is denied for a component of the path prefix" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..10" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n0} 0755 +cdir=`pwd` +cd ${n0} +expect 0 mkdir ${n1} 0755 +expect 0 chown ${n1} 65534 65534 +expect 0 -u 65534 -g 65534 mkdir ${n1}/${n2} 0755 +expect 0 chmod ${n1} 0644 +expect EACCES -u 65534 -g 65534 rmdir ${n1}/${n2} +expect 0 chmod ${n1} 0755 +expect 0 -u 65534 -g 65534 rmdir ${n1}/${n2} +expect 0 rmdir ${n1} +cd ${cdir} +expect 0 rmdir ${n0} diff --git a/tests/rmdir/08.t b/tests/rmdir/08.t new file mode 100644 index 000000000000..fe70c8683d0b --- /dev/null +++ b/tests/rmdir/08.t @@ -0,0 +1,27 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/rmdir/08.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="rmdir returns EACCES when write permission is denied on the directory containing the link to be removed" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..10" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n0} 0755 +cdir=`pwd` +cd ${n0} +expect 0 mkdir ${n1} 0755 +expect 0 chown ${n1} 65534 65534 +expect 0 -u 65534 -g 65534 mkdir ${n1}/${n2} 0755 +expect 0 chmod ${n1} 0555 +expect EACCES -u 65534 -g 65534 rmdir ${n1}/${n2} +expect 0 chmod ${n1} 0755 +expect 0 -u 65534 -g 65534 rmdir ${n1}/${n2} +expect 0 rmdir ${n1} +cd ${cdir} +expect 0 rmdir ${n0} diff --git a/tests/rmdir/09.t b/tests/rmdir/09.t new file mode 100644 index 000000000000..8b0276c980ed --- /dev/null +++ b/tests/rmdir/09.t @@ -0,0 +1,65 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/rmdir/09.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="rmdir returns EPERM if the named directory has its immutable, undeletable or append-only flag set" + +dir=`dirname $0` +. ${dir}/../misc.sh + +require chflags + +case "${os}:${fs}" in +FreeBSD:ZFS) + echo "1..15" + ;; +FreeBSD:UFS) + echo "1..30" + ;; +*) + quick_exit +esac + +n0=`namegen` + +expect 0 mkdir ${n0} 0755 +expect 0 chflags ${n0} SF_IMMUTABLE +expect EPERM rmdir ${n0} +expect 0 chflags ${n0} none +expect 0 rmdir ${n0} + +expect 0 mkdir ${n0} 0755 +expect 0 chflags ${n0} SF_NOUNLINK +expect EPERM rmdir ${n0} +expect 0 chflags ${n0} none +expect 0 rmdir ${n0} + +expect 0 mkdir ${n0} 0755 +expect 0 chflags ${n0} SF_APPEND +todo FreeBSD:ZFS "Removing a directory protected by SF_APPEND should return EPERM." +expect EPERM rmdir ${n0} +todo FreeBSD:ZFS "Removing a directory protected by SF_APPEND should return EPERM." +expect 0 chflags ${n0} none +todo FreeBSD:ZFS "Removing a directory protected by SF_APPEND should return EPERM." +expect 0 rmdir ${n0} + +case "${os}:${fs}" in +FreeBSD:UFS) + expect 0 mkdir ${n0} 0755 + expect 0 chflags ${n0} UF_IMMUTABLE + expect EPERM rmdir ${n0} + expect 0 chflags ${n0} none + expect 0 rmdir ${n0} + + expect 0 mkdir ${n0} 0755 + expect 0 chflags ${n0} UF_NOUNLINK + expect EPERM rmdir ${n0} + expect 0 chflags ${n0} none + expect 0 rmdir ${n0} + + expect 0 mkdir ${n0} 0755 + expect 0 chflags ${n0} UF_APPEND + expect EPERM rmdir ${n0} + expect 0 chflags ${n0} none + expect 0 rmdir ${n0} + ;; +esac diff --git a/tests/rmdir/10.t b/tests/rmdir/10.t new file mode 100644 index 000000000000..5d2e37ef4557 --- /dev/null +++ b/tests/rmdir/10.t @@ -0,0 +1,67 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/rmdir/10.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="rmdir returns EPERM if the parent directory of the named file has its immutable or append-only flag set" + +dir=`dirname $0` +. ${dir}/../misc.sh + +require chflags + +case "${os}:${fs}" in +FreeBSD:ZFS) + echo "1..16" + ;; +FreeBSD:UFS) + echo "1..30" + ;; +*) + quick_exit +esac + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 + +expect 0 mkdir ${n0}/${n1} 0755 +expect 0 chflags ${n0} SF_IMMUTABLE +expect EPERM rmdir ${n0}/${n1} +expect 0 chflags ${n0} none +expect 0 rmdir ${n0}/${n1} + +expect 0 mkdir ${n0}/${n1} 0755 +expect 0 chflags ${n0} SF_NOUNLINK +expect 0 rmdir ${n0}/${n1} +expect 0 chflags ${n0} none + +expect 0 mkdir ${n0}/${n1} 0755 +expect 0 chflags ${n0} SF_APPEND +todo FreeBSD:ZFS "Removing an entry from directory protected by SF_APPEND should return EPERM." +expect EPERM rmdir ${n0}/${n1} +expect 0 chflags ${n0} none +todo FreeBSD:ZFS "Removing an entry from directory protected by SF_APPEND should return EPERM." +expect 0 rmdir ${n0}/${n1} + +case "${os}:${fs}" in +FreeBSD:UFS) + expect 0 mkdir ${n0}/${n1} 0755 + expect 0 chflags ${n0} UF_IMMUTABLE + expect EPERM rmdir ${n0}/${n1} + expect 0 chflags ${n0} none + expect 0 rmdir ${n0}/${n1} + + expect 0 mkdir ${n0}/${n1} 0755 + expect 0 chflags ${n0} UF_NOUNLINK + expect 0 rmdir ${n0}/${n1} + expect 0 chflags ${n0} none + + expect 0 mkdir ${n0}/${n1} 0755 + expect 0 chflags ${n0} UF_APPEND + expect EPERM rmdir ${n0}/${n1} + expect 0 chflags ${n0} none + expect 0 rmdir ${n0}/${n1} + ;; +esac + +expect 0 rmdir ${n0} diff --git a/tests/rmdir/11.t b/tests/rmdir/11.t new file mode 100644 index 000000000000..b8e059135400 --- /dev/null +++ b/tests/rmdir/11.t @@ -0,0 +1,57 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/rmdir/11.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="rmdir returns EACCES or EPERM if the directory containing the directory to be removed is marked sticky, and neither the containing directory nor the directory to be removed are owned by the effective user ID" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..47" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n2} 0755 +cdir=`pwd` +cd ${n2} + +expect 0 mkdir ${n0} 0755 +expect 0 chown ${n0} 65534 65534 +expect 0 chmod ${n0} 01777 + +# User owns both: the sticky directory and the directory to be removed. +expect 0 -u 65534 -g 65534 mkdir ${n0}/${n1} 0755 +expect dir,65534,65534 lstat ${n0}/${n1} type,uid,gid +expect 0 -u 65534 -g 65534 rmdir ${n0}/${n1} +expect ENOENT lstat ${n0}/${n1} type +# User owns the directory to be removed, but doesn't own the sticky directory. +for id in 0 65533; do + expect 0 chown ${n0} ${id} ${id} + create_file dir ${n0}/${n1} 65534 65534 + expect dir,65534,65534 lstat ${n0}/${n1} type,uid,gid + expect 0 -u 65534 -g 65534 rmdir ${n0}/${n1} + expect ENOENT lstat ${n0}/${n1} type +done +# User owns the sticky directory, but doesn't own the directory to be removed. +expect 0 chown ${n0} 65534 65534 +for id in 0 65533; do + create_file dir ${n0}/${n1} ${id} ${id} + expect dir,${id},${id} lstat ${n0}/${n1} type,uid,gid + expect 0 -u 65534 -g 65534 rmdir ${n0}/${n1} + expect ENOENT lstat ${n0}/${n1} type +done +# User doesn't own the sticky directory nor the directory to be removed. +for id in 0 65533; do + expect 0 chown ${n0} ${id} ${id} + create_file dir ${n0}/${n1} ${id} ${id} + expect dir,${id},${id} lstat ${n0}/${n1} type,uid,gid + expect "EACCES|EPERM" -u 65534 -g 65534 rmdir ${n0}/${n1} + expect dir,${id},${id} lstat ${n0}/${n1} type,uid,gid + expect 0 rmdir ${n0}/${n1} +done + +expect 0 rmdir ${n0} + +cd ${cdir} +expect 0 rmdir ${n2} diff --git a/tests/rmdir/12.t b/tests/rmdir/12.t new file mode 100644 index 000000000000..57d144da58f2 --- /dev/null +++ b/tests/rmdir/12.t @@ -0,0 +1,20 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/rmdir/12.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="rmdir returns EINVAL if the last component of the path is '.' and EEXIST or ENOTEMPTY if the last component of the path is '..'" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..6" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +expect 0 mkdir ${n0}/${n1} 0755 +expect EINVAL rmdir ${n0}/${n1}/. +todo FreeBSD "According to POSIX: EEXIST or ENOTEMPTY - The path argument names a directory that is not an empty directory, or there are hard links to the directory other than dot or a single entry in dot-dot." +expect "ENOTEMPTY|EEXIST" rmdir ${n0}/${n1}/.. +expect 0 rmdir ${n0}/${n1} +expect 0 rmdir ${n0} diff --git a/tests/rmdir/13.t b/tests/rmdir/13.t new file mode 100644 index 000000000000..3b12fc5872d1 --- /dev/null +++ b/tests/rmdir/13.t @@ -0,0 +1,22 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/rmdir/13.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="rmdir returns EBUSY if the directory to be removed is the mount point for a mounted file system" + +dir=`dirname $0` +. ${dir}/../misc.sh + +[ "${os}" = "FreeBSD" ] || quick_exit + +echo "1..3" + +n0=`namegen` + +expect 0 mkdir ${n0} 0755 +n=`mdconfig -a -n -t malloc -s 1m` +newfs /dev/md${n} >/dev/null +mount /dev/md${n} ${n0} +expect EBUSY rmdir ${n0} +umount /dev/md${n} +mdconfig -d -u ${n} +expect 0 rmdir ${n0} diff --git a/tests/rmdir/14.t b/tests/rmdir/14.t new file mode 100644 index 000000000000..bc72920e2e54 --- /dev/null +++ b/tests/rmdir/14.t @@ -0,0 +1,27 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/rmdir/14.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="rmdir returns EROFS if the named file resides on a read-only file system" + +dir=`dirname $0` +. ${dir}/../misc.sh + +[ "${os}:${fs}" = "FreeBSD:UFS" ] || quick_exit + +echo "1..5" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +n=`mdconfig -a -n -t malloc -s 1m` +newfs /dev/md${n} >/dev/null +mount /dev/md${n} ${n0} +expect 0 mkdir ${n0}/${n1} 0755 +mount -ur /dev/md${n} +expect EROFS rmdir ${n0}/${n1} +mount -uw /dev/md${n} +expect 0 rmdir ${n0}/${n1} +umount /dev/md${n} +mdconfig -d -u ${n} +expect 0 rmdir ${n0} diff --git a/tests/rmdir/15.t b/tests/rmdir/15.t new file mode 100644 index 000000000000..5390403bcb3e --- /dev/null +++ b/tests/rmdir/15.t @@ -0,0 +1,12 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/rmdir/15.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="rmdir returns EFAULT if the path argument points outside the process's allocated address space" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..2" + +expect EFAULT rmdir NULL +expect EFAULT rmdir DEADCODE diff --git a/tests/symlink/00.t b/tests/symlink/00.t new file mode 100644 index 000000000000..1f2693938a35 --- /dev/null +++ b/tests/symlink/00.t @@ -0,0 +1,32 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/symlink/00.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="symlink creates symbolic links" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..14" + +n0=`namegen` +n1=`namegen` + +expect 0 create ${n0} 0644 +expect regular,0644 lstat ${n0} type,mode +expect 0 symlink ${n0} ${n1} +expect symlink lstat ${n1} type +expect regular,0644 stat ${n1} type,mode +expect 0 unlink ${n0} +expect ENOENT stat ${n1} type,mode +expect 0 unlink ${n1} + +expect 0 mkdir ${n0} 0755 +time=`${fstest} stat ${n0} ctime` +sleep 1 +expect 0 symlink test ${n0}/${n1} +mtime=`${fstest} stat ${n0} mtime` +test_check $time -lt $mtime +ctime=`${fstest} stat ${n0} ctime` +test_check $time -lt $ctime +expect 0 unlink ${n0}/${n1} +expect 0 rmdir ${n0} diff --git a/tests/symlink/01.t b/tests/symlink/01.t new file mode 100644 index 000000000000..3a40b54a45c2 --- /dev/null +++ b/tests/symlink/01.t @@ -0,0 +1,18 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/symlink/01.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="symlink returns ENOTDIR if a component of the name2 path prefix is not a directory" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..5" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +expect 0 create ${n0}/${n1} 0644 +expect ENOTDIR symlink test ${n0}/${n1}/test +expect 0 unlink ${n0}/${n1} +expect 0 rmdir ${n0} diff --git a/tests/symlink/02.t b/tests/symlink/02.t new file mode 100644 index 000000000000..4b81f169f7a6 --- /dev/null +++ b/tests/symlink/02.t @@ -0,0 +1,22 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/symlink/02.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="symlink returns ENAMETOOLONG if a component of the name2 pathname exceeded {NAME_MAX} characters" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..7" + +n0=`namegen` +nx=`namegen_max` +nxx="${nx}x" + +expect 0 symlink ${nx} ${n0} +expect 0 unlink ${n0} +expect 0 symlink ${n0} ${nx} +expect 0 unlink ${nx} + +expect ENAMETOOLONG symlink ${n0} ${nxx} +expect 0 symlink ${nxx} ${n0} +expect 0 unlink ${n0} diff --git a/tests/symlink/03.t b/tests/symlink/03.t new file mode 100644 index 000000000000..68ecfbdfecbc --- /dev/null +++ b/tests/symlink/03.t @@ -0,0 +1,22 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/symlink/03.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="symlink returns ENAMETOOLONG if an entire length of either path name exceeded {PATH_MAX} characters" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..6" + +n0=`namegen` +nx=`dirgen_max` +nxx="${nx}x" + +mkdir -p "${nx%/*}" +expect 0 symlink ${nx} ${n0} +expect 0 unlink ${n0} +expect 0 symlink ${n0} ${nx} +expect 0 unlink ${nx} +expect ENAMETOOLONG symlink ${n0} ${nxx} +expect ENAMETOOLONG symlink ${nxx} ${n0} +rm -rf "${nx%%/*}" diff --git a/tests/symlink/04.t b/tests/symlink/04.t new file mode 100644 index 000000000000..ca1c8eedf48b --- /dev/null +++ b/tests/symlink/04.t @@ -0,0 +1,16 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/symlink/04.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="symlink returns ENOENT if a component of the name2 path prefix does not exist" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..3" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +expect ENOENT symlink test ${n0}/${n1}/test +expect 0 rmdir ${n0} diff --git a/tests/symlink/05.t b/tests/symlink/05.t new file mode 100644 index 000000000000..801e46714a96 --- /dev/null +++ b/tests/symlink/05.t @@ -0,0 +1,34 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/symlink/05.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="symlink returns EACCES when a component of the name2 path prefix denies search permission" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..12" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n0} 0755 +cdir=`pwd` +cd ${n0} + +expect 0 mkdir ${n1} 0755 +expect 0 chown ${n1} 65534 65534 + +expect 0 -u 65534 -g 65534 symlink test ${n1}/${n2} +expect 0 -u 65534 -g 65534 unlink ${n1}/${n2} + +expect 0 chmod ${n1} 0644 +expect EACCES -u 65534 -g 65534 symlink test ${n1}/${n2} +expect 0 chmod ${n1} 0755 +expect 0 -u 65534 -g 65534 symlink test ${n1}/${n2} +expect 0 -u 65534 -g 65534 unlink ${n1}/${n2} + +expect 0 rmdir ${n1} + +cd ${cdir} +expect 0 rmdir ${n0} diff --git a/tests/symlink/06.t b/tests/symlink/06.t new file mode 100644 index 000000000000..db61ad01c392 --- /dev/null +++ b/tests/symlink/06.t @@ -0,0 +1,34 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/symlink/06.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="symlink returns EACCES if the parent directory of the file to be created denies write permission" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..12" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n0} 0755 +cdir=`pwd` +cd ${n0} + +expect 0 mkdir ${n1} 0755 +expect 0 chown ${n1} 65534 65534 + +expect 0 -u 65534 -g 65534 symlink test ${n1}/${n2} +expect 0 -u 65534 -g 65534 unlink ${n1}/${n2} + +expect 0 chmod ${n1} 0555 +expect EACCES -u 65534 -g 65534 symlink test ${n1}/${n2} +expect 0 chmod ${n1} 0755 +expect 0 -u 65534 -g 65534 symlink test ${n1}/${n2} +expect 0 unlink ${n1}/${n2} + +expect 0 rmdir ${n1} + +cd ${cdir} +expect 0 rmdir ${n0} diff --git a/tests/symlink/07.t b/tests/symlink/07.t new file mode 100644 index 000000000000..c6aedc0570e0 --- /dev/null +++ b/tests/symlink/07.t @@ -0,0 +1,19 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/symlink/07.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="symlink returns ELOOP if too many symbolic links were encountered in translating the name2 path name" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..6" + +n0=`namegen` +n1=`namegen` + +expect 0 symlink ${n0} ${n1} +expect 0 symlink ${n1} ${n0} +expect ELOOP symlink test ${n0}/test +expect ELOOP symlink test ${n1}/test +expect 0 unlink ${n0} +expect 0 unlink ${n1} diff --git a/tests/symlink/08.t b/tests/symlink/08.t new file mode 100644 index 000000000000..ef7915dbe72b --- /dev/null +++ b/tests/symlink/08.t @@ -0,0 +1,21 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/symlink/08.t 211474 2010-08-18 22:06:43Z pjd $ + +desc="symlink returns EEXIST if the name2 argument already exists" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..21" + +n0=`namegen` + +for type in regular dir fifo block char socket symlink; do + create_file ${type} ${n0} + expect EEXIST symlink test ${n0} + if [ "${type}" = "dir" ]; then + expect 0 rmdir ${n0} + else + expect 0 unlink ${n0} + fi +done diff --git a/tests/symlink/09.t b/tests/symlink/09.t new file mode 100644 index 000000000000..6292aaf7649f --- /dev/null +++ b/tests/symlink/09.t @@ -0,0 +1,66 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/symlink/09.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="symlink returns EPERM if the parent directory of the file named by name2 has its immutable flag set" + +dir=`dirname $0` +. ${dir}/../misc.sh + +require chflags + +case "${os}:${fs}" in +FreeBSD:ZFS) + echo "1..17" + ;; +FreeBSD:UFS) + echo "1..30" + ;; +*) + quick_exit +esac + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 + +expect 0 symlink test ${n0}/${n1} +expect 0 unlink ${n0}/${n1} + +expect 0 chflags ${n0} SF_IMMUTABLE +expect EPERM symlink test ${n0}/${n1} +expect 0 chflags ${n0} none +expect 0 symlink test ${n0}/${n1} +expect 0 unlink ${n0}/${n1} + +expect 0 chflags ${n0} SF_NOUNLINK +expect 0 symlink test ${n0}/${n1} +expect 0 chflags ${n0} none +expect 0 unlink ${n0}/${n1} + +expect 0 chflags ${n0} SF_APPEND +expect 0 symlink test ${n0}/${n1} +expect 0 chflags ${n0} none +expect 0 unlink ${n0}/${n1} + +case "${os}:${fs}" in +FreeBSD:UFS) + expect 0 chflags ${n0} UF_IMMUTABLE + expect EPERM symlink test ${n0}/${n1} + expect 0 chflags ${n0} none + expect 0 symlink test ${n0}/${n1} + expect 0 unlink ${n0}/${n1} + + expect 0 chflags ${n0} UF_NOUNLINK + expect 0 symlink test ${n0}/${n1} + expect 0 chflags ${n0} none + expect 0 unlink ${n0}/${n1} + + expect 0 chflags ${n0} UF_APPEND + expect 0 symlink test ${n0}/${n1} + expect 0 chflags ${n0} none + expect 0 unlink ${n0}/${n1} + ;; +esac + +expect 0 rmdir ${n0} diff --git a/tests/symlink/10.t b/tests/symlink/10.t new file mode 100644 index 000000000000..34dfa2a337e4 --- /dev/null +++ b/tests/symlink/10.t @@ -0,0 +1,32 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/symlink/10.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="symlink returns EROFS if the file name2 would reside on a read-only file system" + +dir=`dirname $0` +. ${dir}/../misc.sh + +[ "${os}:${fs}" = "FreeBSD:UFS" ] || quick_exit + +echo "1..7" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n0} 0755 +n=`mdconfig -a -n -t malloc -s 1m` +newfs /dev/md${n} >/dev/null +mount /dev/md${n} ${n0} + +expect 0 symlink test ${n0}/${n1} +expect 0 unlink ${n0}/${n1} +mount -ur /dev/md${n} +expect EROFS symlink test ${n0}/${n1} +mount -uw /dev/md${n} +expect 0 symlink test ${n0}/${n1} +expect 0 unlink ${n0}/${n1} + +umount /dev/md${n} +mdconfig -d -u ${n} +expect 0 rmdir ${n0} diff --git a/tests/symlink/11.t b/tests/symlink/11.t new file mode 100644 index 000000000000..956a2d4124c1 --- /dev/null +++ b/tests/symlink/11.t @@ -0,0 +1,31 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/symlink/11.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="symlink returns ENOSPC if there are no free inodes on the file system on which the symbolic link is being created" + +dir=`dirname $0` +. ${dir}/../misc.sh + +[ "${os}:${fs}" = "FreeBSD:UFS" ] || quick_exit + +echo "1..3" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +n=`mdconfig -a -n -t malloc -s 256k` +newfs /dev/md${n} >/dev/null +mount /dev/md${n} ${n0} +i=0 +while :; do + ln -s test ${n0}/${i} >/dev/null 2>&1 + if [ $? -ne 0 ]; then + break + fi + i=`expr $i + 1` +done +expect ENOSPC symlink test ${n0}/${n1} +umount /dev/md${n} +mdconfig -d -u ${n} +expect 0 rmdir ${n0} diff --git a/tests/symlink/12.t b/tests/symlink/12.t new file mode 100644 index 000000000000..2c699050e673 --- /dev/null +++ b/tests/symlink/12.t @@ -0,0 +1,18 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/symlink/12.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="symlink returns EFAULT if one of the pathnames specified is outside the process's allocated address space" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..6" + +n0=`namegen` + +expect EFAULT symlink NULL ${n0} +expect EFAULT symlink DEADCODE ${n0} +expect EFAULT symlink test NULL +expect EFAULT symlink test DEADCODE +expect EFAULT symlink NULL DEADCODE +expect EFAULT symlink DEADCODE NULL diff --git a/tests/truncate/00.t b/tests/truncate/00.t new file mode 100644 index 000000000000..6a77a8f796b0 --- /dev/null +++ b/tests/truncate/00.t @@ -0,0 +1,51 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/truncate/00.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="truncate descrease/increase file size" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..21" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n1} 0755 +cdir=`pwd` +cd ${n1} + +expect 0 create ${n0} 0644 +expect 0 truncate ${n0} 1234567 +expect 1234567 lstat ${n0} size +expect 0 truncate ${n0} 567 +expect 567 lstat ${n0} size +expect 0 unlink ${n0} + +dd if=/dev/random of=${n0} bs=12345 count=1 >/dev/null 2>&1 +expect 0 truncate ${n0} 23456 +expect 23456 lstat ${n0} size +expect 0 truncate ${n0} 1 +expect 1 lstat ${n0} size +expect 0 unlink ${n0} + +# successful truncate(2) updates ctime. +expect 0 create ${n0} 0644 +ctime1=`${fstest} stat ${n0} ctime` +sleep 1 +expect 0 truncate ${n0} 123 +ctime2=`${fstest} stat ${n0} ctime` +test_check $ctime1 -lt $ctime2 +expect 0 unlink ${n0} + +# unsuccessful truncate(2) does not update ctime. +expect 0 create ${n0} 0644 +ctime1=`${fstest} stat ${n0} ctime` +sleep 1 +expect EACCES -u 65534 truncate ${n0} 123 +ctime2=`${fstest} stat ${n0} ctime` +test_check $ctime1 -eq $ctime2 +expect 0 unlink ${n0} + +cd ${cdir} +expect 0 rmdir ${n1} diff --git a/tests/truncate/01.t b/tests/truncate/01.t new file mode 100644 index 000000000000..a8e95ac60181 --- /dev/null +++ b/tests/truncate/01.t @@ -0,0 +1,18 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/truncate/01.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="truncate returns ENOTDIR if a component of the path prefix is not a directory" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..5" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +expect 0 create ${n0}/${n1} 0644 +expect ENOTDIR truncate ${n0}/${n1}/test 123 +expect 0 unlink ${n0}/${n1} +expect 0 rmdir ${n0} diff --git a/tests/truncate/02.t b/tests/truncate/02.t new file mode 100644 index 000000000000..83de38d3244f --- /dev/null +++ b/tests/truncate/02.t @@ -0,0 +1,18 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/truncate/02.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="truncate returns ENAMETOOLONG if a component of a pathname exceeded {NAME_MAX} characters" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..5" + +nx=`namegen_max` +nxx="${nx}x" + +expect 0 create ${nx} 0644 +expect 0 truncate ${nx} 123 +expect 123 stat ${nx} size +expect 0 unlink ${nx} +expect ENAMETOOLONG truncate ${nxx} 123 diff --git a/tests/truncate/03.t b/tests/truncate/03.t new file mode 100644 index 000000000000..41e98625ba4f --- /dev/null +++ b/tests/truncate/03.t @@ -0,0 +1,22 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/truncate/03.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="truncate returns ENAMETOOLONG if an entire path name exceeded {PATH_MAX} characters" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..5" + +nx=`dirgen_max` +nxx="${nx}x" + +mkdir -p "${nx%/*}" + +expect 0 create ${nx} 0644 +expect 0 truncate ${nx} 123 +expect regular,123 stat ${nx} type,size +expect 0 unlink ${nx} +expect ENAMETOOLONG truncate ${nxx} 123 + +rm -rf "${nx%%/*}" diff --git a/tests/truncate/04.t b/tests/truncate/04.t new file mode 100644 index 000000000000..cd1cfc66b2b0 --- /dev/null +++ b/tests/truncate/04.t @@ -0,0 +1,17 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/truncate/04.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="truncate returns ENOENT if the named file does not exist" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..4" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +expect ENOENT truncate ${n0}/${n1}/test 123 +expect ENOENT truncate ${n0}/${n1} 123 +expect 0 rmdir ${n0} diff --git a/tests/truncate/05.t b/tests/truncate/05.t new file mode 100644 index 000000000000..f12881581bce --- /dev/null +++ b/tests/truncate/05.t @@ -0,0 +1,32 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/truncate/05.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="truncate returns EACCES when search permission is denied for a component of the path prefix" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..15" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n0} 0755 +cdir=`pwd` +cd ${n0} +expect 0 mkdir ${n1} 0755 +expect 0 chown ${n1} 65534 65534 +expect 0 -u 65534 -g 65534 create ${n1}/${n2} 0644 +expect 0 -u 65534 -g 65534 truncate ${n1}/${n2} 123 +expect 123 -u 65534 -g 65534 stat ${n1}/${n2} size +expect 0 chmod ${n1} 0644 +expect EACCES -u 65534 -g 65534 truncate ${n1}/${n2} 1234 +expect 0 chmod ${n1} 0755 +expect 123 -u 65534 -g 65534 stat ${n1}/${n2} size +expect 0 -u 65534 -g 65534 truncate ${n1}/${n2} 1234 +expect 1234 -u 65534 -g 65534 stat ${n1}/${n2} size +expect 0 -u 65534 -g 65534 unlink ${n1}/${n2} +expect 0 rmdir ${n1} +cd ${cdir} +expect 0 rmdir ${n0} diff --git a/tests/truncate/06.t b/tests/truncate/06.t new file mode 100644 index 000000000000..1ce516fa74a6 --- /dev/null +++ b/tests/truncate/06.t @@ -0,0 +1,24 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/truncate/06.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="truncate returns EACCES if the named file is not writable by the user" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..8" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +cdir=`pwd` +cd ${n0} +expect 0 create ${n1} 0644 +expect EACCES -u 65534 -g 65534 truncate ${n1} 123 +expect 0 chown ${n1} 65534 65534 +expect 0 chmod ${n1} 0444 +expect EACCES -u 65534 -g 65534 truncate ${n1} 123 +expect 0 unlink ${n1} +cd ${cdir} +expect 0 rmdir ${n0} diff --git a/tests/truncate/07.t b/tests/truncate/07.t new file mode 100644 index 000000000000..44f87e7ea859 --- /dev/null +++ b/tests/truncate/07.t @@ -0,0 +1,19 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/truncate/07.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="truncate returns ELOOP if too many symbolic links were encountered in translating the pathname" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..6" + +n0=`namegen` +n1=`namegen` + +expect 0 symlink ${n0} ${n1} +expect 0 symlink ${n1} ${n0} +expect ELOOP truncate ${n0}/test 123 +expect ELOOP truncate ${n1}/test 123 +expect 0 unlink ${n0} +expect 0 unlink ${n1} diff --git a/tests/truncate/08.t b/tests/truncate/08.t new file mode 100644 index 000000000000..6f205ef965f2 --- /dev/null +++ b/tests/truncate/08.t @@ -0,0 +1,78 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/truncate/08.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="truncate returns EPERM if the named file has its immutable or append-only flag set" + +dir=`dirname $0` +. ${dir}/../misc.sh + +require chflags + +case "${os}:${fs}" in +FreeBSD:ZFS) + echo "1..22" + ;; +FreeBSD:UFS) + echo "1..44" + ;; +*) + quick_exit +esac + +n0=`namegen` + +expect 0 create ${n0} 0644 +expect 0 chflags ${n0} SF_IMMUTABLE +expect EPERM truncate ${n0} 123 +expect 0 stat ${n0} size +expect 0 chflags ${n0} none +expect 0 truncate ${n0} 123 +expect 123 stat ${n0} size +expect 0 unlink ${n0} + +expect 0 create ${n0} 0644 +expect 0 chflags ${n0} SF_NOUNLINK +expect 0 truncate ${n0} 123 +expect 123 stat ${n0} size +expect 0 chflags ${n0} none +expect 0 unlink ${n0} + +expect 0 create ${n0} 0644 +expect 0 chflags ${n0} SF_APPEND +todo FreeBSD:ZFS "Truncating a file protected by SF_APPEND should return EPERM." +expect EPERM truncate ${n0} 123 +todo FreeBSD:ZFS "Truncating a file protected by SF_APPEND should return EPERM." +expect 0 stat ${n0} size +expect 0 chflags ${n0} none +expect 0 truncate ${n0} 123 +expect 123 stat ${n0} size +expect 0 unlink ${n0} + +case "${os}:${fs}" in +FreeBSD:UFS) + expect 0 create ${n0} 0644 + expect 0 chflags ${n0} UF_IMMUTABLE + expect EPERM truncate ${n0} 123 + expect 0 stat ${n0} size + expect 0 chflags ${n0} none + expect 0 truncate ${n0} 123 + expect 123 stat ${n0} size + expect 0 unlink ${n0} + + expect 0 create ${n0} 0644 + expect 0 chflags ${n0} UF_NOUNLINK + expect 0 truncate ${n0} 123 + expect 123 stat ${n0} size + expect 0 chflags ${n0} none + expect 0 unlink ${n0} + + expect 0 create ${n0} 0644 + expect 0 chflags ${n0} UF_APPEND + expect EPERM truncate ${n0} 123 + expect 0 stat ${n0} size + expect 0 chflags ${n0} none + expect 0 truncate ${n0} 123 + expect 123 stat ${n0} size + expect 0 unlink ${n0} + ;; +esac diff --git a/tests/truncate/09.t b/tests/truncate/09.t new file mode 100644 index 000000000000..d7e082ddbe0e --- /dev/null +++ b/tests/truncate/09.t @@ -0,0 +1,15 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/truncate/09.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="truncate returns EISDIR if the named file is a directory" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..3" + +n0=`namegen` + +expect 0 mkdir ${n0} 0755 +expect EISDIR truncate ${n0} 123 +expect 0 rmdir ${n0} diff --git a/tests/truncate/10.t b/tests/truncate/10.t new file mode 100644 index 000000000000..08893a385439 --- /dev/null +++ b/tests/truncate/10.t @@ -0,0 +1,32 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/truncate/10.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="truncate returns EROFS if the named file resides on a read-only file system" + +dir=`dirname $0` +. ${dir}/../misc.sh + +[ "${os}:${fs}" = "FreeBSD:UFS" ] || quick_exit + +echo "1..10" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +n=`mdconfig -a -n -t malloc -s 1m` +newfs /dev/md${n} >/dev/null +mount /dev/md${n} ${n0} +expect 0 create ${n0}/${n1} 0644 +expect 0 truncate ${n0}/${n1} 123 +expect 123 stat ${n0}/${n1} size +mount -ur /dev/md${n} +expect EROFS truncate ${n0}/${n1} 1234 +expect 123 stat ${n0}/${n1} size +mount -uw /dev/md${n} +expect 0 truncate ${n0}/${n1} 1234 +expect 1234 stat ${n0}/${n1} size +expect 0 unlink ${n0}/${n1} +umount /dev/md${n} +mdconfig -d -u ${n} +expect 0 rmdir ${n0} diff --git a/tests/truncate/11.t b/tests/truncate/11.t new file mode 100644 index 000000000000..b00d7b89c16d --- /dev/null +++ b/tests/truncate/11.t @@ -0,0 +1,18 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/truncate/11.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="truncate returns ETXTBSY the file is a pure procedure (shared text) file that is being executed" + +dir=`dirname $0` +. ${dir}/../misc.sh + +[ "${os}" = "FreeBSD" ] || quick_exit + +echo "1..2" + +n0=`namegen` + +cp -pf `which sleep` ${n0} +./${n0} 3 & +expect ETXTBSY truncate ${n0} 123 +expect 0 unlink ${n0} diff --git a/tests/truncate/12.t b/tests/truncate/12.t new file mode 100644 index 000000000000..1825456a7b13 --- /dev/null +++ b/tests/truncate/12.t @@ -0,0 +1,27 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/truncate/12.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="truncate returns EFBIG or EINVAL if the length argument was greater than the maximum file size" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..3" + +n0=`namegen` + +expect 0 create ${n0} 0644 +r=`${fstest} truncate ${n0} 999999999999999 2>/dev/null` +case "${r}" in +EFBIG|EINVAL) + expect 0 stat ${n0} size + ;; +0) + expect 999999999999999 stat ${n0} size + ;; +*) + echo "not ok ${ntest}" + ntest=`expr ${ntest} + 1` + ;; +esac +expect 0 unlink ${n0} diff --git a/tests/truncate/13.t b/tests/truncate/13.t new file mode 100644 index 000000000000..7c9f0d4e14ec --- /dev/null +++ b/tests/truncate/13.t @@ -0,0 +1,16 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/truncate/13.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="truncate returns EINVAL if the length argument was less than 0" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..4" + +n0=`namegen` + +expect 0 create ${n0} 0644 +expect EINVAL -- truncate ${n0} -1 +expect EINVAL -- truncate ${n0} -999999 +expect 0 unlink ${n0} diff --git a/tests/truncate/14.t b/tests/truncate/14.t new file mode 100644 index 000000000000..a238771264f9 --- /dev/null +++ b/tests/truncate/14.t @@ -0,0 +1,12 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/truncate/14.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="truncate returns EFAULT if the path argument points outside the process's allocated address space" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..2" + +expect EFAULT truncate NULL 123 +expect EFAULT truncate DEADCODE 123 diff --git a/tests/unlink/00.t b/tests/unlink/00.t new file mode 100644 index 000000000000..0b9b1f1b59cf --- /dev/null +++ b/tests/unlink/00.t @@ -0,0 +1,212 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/unlink/00.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="unlink removes regular files, symbolic links, fifos and sockets" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..112" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n2} 0755 +cdir=`pwd` +cd ${n2} + +expect 0 create ${n0} 0644 +expect regular lstat ${n0} type +expect 0 unlink ${n0} +expect ENOENT lstat ${n0} type + +expect 0 symlink ${n1} ${n0} +expect symlink lstat ${n0} type +expect 0 unlink ${n0} +expect ENOENT lstat ${n0} type + +expect 0 mkfifo ${n0} 0644 +expect fifo lstat ${n0} type +expect 0 unlink ${n0} +expect ENOENT lstat ${n0} type + +expect 0 mknod ${n0} b 0644 1 2 +expect block lstat ${n0} type +expect 0 unlink ${n0} +expect ENOENT lstat ${n0} type + +expect 0 mknod ${n0} c 0644 1 2 +expect char lstat ${n0} type +expect 0 unlink ${n0} +expect ENOENT lstat ${n0} type + +expect 0 bind ${n0} +expect socket lstat ${n0} type +expect 0 unlink ${n0} +expect ENOENT lstat ${n0} type + +# successful unlink(2) updates ctime. +expect 0 create ${n0} 0644 +expect 0 link ${n0} ${n1} +ctime1=`${fstest} stat ${n0} ctime` +sleep 1 +expect 0 unlink ${n1} +ctime2=`${fstest} stat ${n0} ctime` +test_check $ctime1 -lt $ctime2 +expect 0 unlink ${n0} + +expect 0 mkfifo ${n0} 0644 +expect 0 link ${n0} ${n1} +ctime1=`${fstest} stat ${n0} ctime` +sleep 1 +expect 0 unlink ${n1} +ctime2=`${fstest} stat ${n0} ctime` +test_check $ctime1 -lt $ctime2 +expect 0 unlink ${n0} + +expect 0 mknod ${n0} b 0644 1 2 +expect 0 link ${n0} ${n1} +ctime1=`${fstest} stat ${n0} ctime` +sleep 1 +expect 0 unlink ${n1} +ctime2=`${fstest} stat ${n0} ctime` +test_check $ctime1 -lt $ctime2 +expect 0 unlink ${n0} + +expect 0 mknod ${n0} c 0644 1 2 +expect 0 link ${n0} ${n1} +ctime1=`${fstest} stat ${n0} ctime` +sleep 1 +expect 0 unlink ${n1} +ctime2=`${fstest} stat ${n0} ctime` +test_check $ctime1 -lt $ctime2 +expect 0 unlink ${n0} + +expect 0 bind ${n0} +expect 0 link ${n0} ${n1} +ctime1=`${fstest} stat ${n0} ctime` +sleep 1 +expect 0 unlink ${n1} +ctime2=`${fstest} stat ${n0} ctime` +test_check $ctime1 -lt $ctime2 +expect 0 unlink ${n0} + +# unsuccessful unlink(2) does not update ctime. +expect 0 create ${n0} 0644 +ctime1=`${fstest} stat ${n0} ctime` +sleep 1 +expect EACCES -u 65534 unlink ${n0} +ctime2=`${fstest} stat ${n0} ctime` +test_check $ctime1 -eq $ctime2 +expect 0 unlink ${n0} + +expect 0 mkfifo ${n0} 0644 +ctime1=`${fstest} stat ${n0} ctime` +sleep 1 +expect EACCES -u 65534 unlink ${n0} +ctime2=`${fstest} stat ${n0} ctime` +test_check $ctime1 -eq $ctime2 +expect 0 unlink ${n0} + +expect 0 mknod ${n0} b 0644 1 2 +ctime1=`${fstest} stat ${n0} ctime` +sleep 1 +expect EACCES -u 65534 unlink ${n0} +ctime2=`${fstest} stat ${n0} ctime` +test_check $ctime1 -eq $ctime2 +expect 0 unlink ${n0} + +expect 0 mknod ${n0} c 0644 1 2 +ctime1=`${fstest} stat ${n0} ctime` +sleep 1 +expect EACCES -u 65534 unlink ${n0} +ctime2=`${fstest} stat ${n0} ctime` +test_check $ctime1 -eq $ctime2 +expect 0 unlink ${n0} + +expect 0 bind ${n0} +ctime1=`${fstest} stat ${n0} ctime` +sleep 1 +expect EACCES -u 65534 unlink ${n0} +ctime2=`${fstest} stat ${n0} ctime` +test_check $ctime1 -eq $ctime2 +expect 0 unlink ${n0} + +expect 0 mkdir ${n0} 0755 +expect 0 create ${n0}/${n1} 0644 +time=`${fstest} stat ${n0} ctime` +sleep 1 +expect 0 unlink ${n0}/${n1} +mtime=`${fstest} stat ${n0} mtime` +test_check $time -lt $mtime +ctime=`${fstest} stat ${n0} ctime` +test_check $time -lt $ctime +expect 0 rmdir ${n0} + +expect 0 mkdir ${n0} 0755 +expect 0 mkfifo ${n0}/${n1} 0644 +time=`${fstest} stat ${n0} ctime` +sleep 1 +expect 0 unlink ${n0}/${n1} +mtime=`${fstest} stat ${n0} mtime` +test_check $time -lt $mtime +ctime=`${fstest} stat ${n0} ctime` +test_check $time -lt $ctime +expect 0 rmdir ${n0} + +expect 0 mkdir ${n0} 0755 +expect 0 mknod ${n0}/${n1} b 0644 1 2 +time=`${fstest} stat ${n0} ctime` +sleep 1 +expect 0 unlink ${n0}/${n1} +mtime=`${fstest} stat ${n0} mtime` +test_check $time -lt $mtime +ctime=`${fstest} stat ${n0} ctime` +test_check $time -lt $ctime +expect 0 rmdir ${n0} + +expect 0 mkdir ${n0} 0755 +expect 0 mknod ${n0}/${n1} c 0644 1 2 +time=`${fstest} stat ${n0} ctime` +sleep 1 +expect 0 unlink ${n0}/${n1} +mtime=`${fstest} stat ${n0} mtime` +test_check $time -lt $mtime +ctime=`${fstest} stat ${n0} ctime` +test_check $time -lt $ctime +expect 0 rmdir ${n0} + +expect 0 mkdir ${n0} 0755 +expect 0 bind ${n0}/${n1} +time=`${fstest} stat ${n0} ctime` +sleep 1 +expect 0 unlink ${n0}/${n1} +mtime=`${fstest} stat ${n0} mtime` +test_check $time -lt $mtime +ctime=`${fstest} stat ${n0} ctime` +test_check $time -lt $ctime +expect 0 rmdir ${n0} + +expect 0 mkdir ${n0} 0755 +expect 0 symlink test ${n0}/${n1} +time=`${fstest} stat ${n0} ctime` +sleep 1 +expect 0 unlink ${n0}/${n1} +mtime=`${fstest} stat ${n0} mtime` +test_check $time -lt $mtime +ctime=`${fstest} stat ${n0} ctime` +test_check $time -lt $ctime +expect 0 rmdir ${n0} + +expect 0 create ${n0} 0644 +expect 0 link ${n0} ${n1} +time=`${fstest} stat ${n0} ctime` +sleep 1 +expect 0 unlink ${n1} +ctime=`${fstest} stat ${n0} ctime` +test_check $time -lt $ctime +expect 0 unlink ${n0} + +cd ${cdir} +expect 0 rmdir ${n2} diff --git a/tests/unlink/01.t b/tests/unlink/01.t new file mode 100644 index 000000000000..7e29671ecb70 --- /dev/null +++ b/tests/unlink/01.t @@ -0,0 +1,18 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/unlink/01.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="unlink returns ENOTDIR if a component of the path prefix is not a directory" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..5" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +expect 0 create ${n0}/${n1} 0644 +expect ENOTDIR unlink ${n0}/${n1}/test +expect 0 unlink ${n0}/${n1} +expect 0 rmdir ${n0} diff --git a/tests/unlink/02.t b/tests/unlink/02.t new file mode 100644 index 000000000000..e624d987e813 --- /dev/null +++ b/tests/unlink/02.t @@ -0,0 +1,17 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/unlink/02.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="unlink returns ENAMETOOLONG if a component of a pathname exceeded {NAME_MAX} characters" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..4" + +nx=`namegen_max` +nxx="${nx}x" + +expect 0 create ${nx} 0644 +expect 0 unlink ${nx} +expect ENOENT unlink ${nx} +expect ENAMETOOLONG unlink ${nxx} diff --git a/tests/unlink/03.t b/tests/unlink/03.t new file mode 100644 index 000000000000..f4c939e721e6 --- /dev/null +++ b/tests/unlink/03.t @@ -0,0 +1,21 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/unlink/03.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="unlink returns ENAMETOOLONG if an entire path name exceeded {PATH_MAX} characters" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..4" + +nx=`dirgen_max` +nxx="${nx}x" + +mkdir -p "${nx%/*}" + +expect 0 create ${nx} 0644 +expect 0 unlink ${nx} +expect ENOENT unlink ${nx} +expect ENAMETOOLONG unlink ${nxx} + +rm -rf "${nx%%/*}" diff --git a/tests/unlink/04.t b/tests/unlink/04.t new file mode 100644 index 000000000000..0717eaad01b9 --- /dev/null +++ b/tests/unlink/04.t @@ -0,0 +1,17 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/unlink/04.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="unlink returns ENOENT if the named file does not exist" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..4" + +n0=`namegen` +n1=`namegen` + +expect 0 create ${n0} 0644 +expect 0 unlink ${n0} +expect ENOENT unlink ${n0} +expect ENOENT unlink ${n1} diff --git a/tests/unlink/05.t b/tests/unlink/05.t new file mode 100644 index 000000000000..91dccf90afea --- /dev/null +++ b/tests/unlink/05.t @@ -0,0 +1,27 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/unlink/05.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="unlink returns EACCES when search permission is denied for a component of the path prefix" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..10" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n0} 0755 +cdir=`pwd` +cd ${n0} +expect 0 mkdir ${n1} 0755 +expect 0 chown ${n1} 65534 65534 +expect 0 -u 65534 -g 65534 create ${n1}/${n2} 0644 +expect 0 chmod ${n1} 0644 +expect EACCES -u 65534 -g 65534 unlink ${n1}/${n2} +expect 0 chmod ${n1} 0755 +expect 0 -u 65534 -g 65534 unlink ${n1}/${n2} +expect 0 rmdir ${n1} +cd ${cdir} +expect 0 rmdir ${n0} diff --git a/tests/unlink/06.t b/tests/unlink/06.t new file mode 100644 index 000000000000..293742966c0e --- /dev/null +++ b/tests/unlink/06.t @@ -0,0 +1,27 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/unlink/06.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="unlink returns EACCES when write permission is denied on the directory containing the link to be removed" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..10" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n0} 0755 +cdir=`pwd` +cd ${n0} +expect 0 mkdir ${n1} 0755 +expect 0 chown ${n1} 65534 65534 +expect 0 -u 65534 -g 65534 create ${n1}/${n2} 0644 +expect 0 chmod ${n1} 0555 +expect EACCES -u 65534 -g 65534 unlink ${n1}/${n2} +expect 0 chmod ${n1} 0755 +expect 0 -u 65534 -g 65534 unlink ${n1}/${n2} +expect 0 rmdir ${n1} +cd ${cdir} +expect 0 rmdir ${n0} diff --git a/tests/unlink/07.t b/tests/unlink/07.t new file mode 100644 index 000000000000..e63eafa6e7a4 --- /dev/null +++ b/tests/unlink/07.t @@ -0,0 +1,19 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/unlink/07.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="unlink returns ELOOP if too many symbolic links were encountered in translating the pathname" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..6" + +n0=`namegen` +n1=`namegen` + +expect 0 symlink ${n0} ${n1} +expect 0 symlink ${n1} ${n0} +expect ELOOP unlink ${n0}/test +expect ELOOP unlink ${n1}/test +expect 0 unlink ${n0} +expect 0 unlink ${n1} diff --git a/tests/unlink/08.t b/tests/unlink/08.t new file mode 100644 index 000000000000..666400cd2a2e --- /dev/null +++ b/tests/unlink/08.t @@ -0,0 +1,16 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/unlink/08.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="unlink may return EPERM if the named file is a directory" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..3" + +n0=`namegen` + +expect 0 mkdir ${n0} 0755 +todo Linux "According to POSIX: EPERM - The file named by path is a directory, and either the calling process does not have appropriate privileges, or the implementation prohibits using unlink() on directories." +expect "0|EPERM" unlink ${n0} +expect "0|ENOENT" rmdir ${n0} diff --git a/tests/unlink/09.t b/tests/unlink/09.t new file mode 100644 index 000000000000..dbc202a6954d --- /dev/null +++ b/tests/unlink/09.t @@ -0,0 +1,65 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/unlink/09.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="unlink returns EPERM if the named file has its immutable, undeletable or append-only flag set" + +dir=`dirname $0` +. ${dir}/../misc.sh + +require chflags + +case "${os}:${fs}" in +FreeBSD:ZFS) + echo "1..15" + ;; +FreeBSD:UFS) + echo "1..30" + ;; +*) + quick_exit +esac + +n0=`namegen` + +expect 0 create ${n0} 0644 +expect 0 chflags ${n0} SF_IMMUTABLE +expect EPERM unlink ${n0} +expect 0 chflags ${n0} none +expect 0 unlink ${n0} + +expect 0 create ${n0} 0644 +expect 0 chflags ${n0} SF_NOUNLINK +expect EPERM unlink ${n0} +expect 0 chflags ${n0} none +expect 0 unlink ${n0} + +expect 0 create ${n0} 0644 +expect 0 chflags ${n0} SF_APPEND +todo FreeBSD:ZFS "Removing a file protected by SF_APPEND should return EPERM." +expect EPERM unlink ${n0} +todo FreeBSD:ZFS "Removing a file protected by SF_APPEND should return EPERM." +expect 0 chflags ${n0} none +todo FreeBSD:ZFS "Removing a file protected by SF_APPEND should return EPERM." +expect 0 unlink ${n0} + +case "${os}:${fs}" in +FreeBSD:UFS) + expect 0 create ${n0} 0644 + expect 0 chflags ${n0} UF_IMMUTABLE + expect EPERM unlink ${n0} + expect 0 chflags ${n0} none + expect 0 unlink ${n0} + + expect 0 create ${n0} 0644 + expect 0 chflags ${n0} UF_NOUNLINK + expect EPERM unlink ${n0} + expect 0 chflags ${n0} none + expect 0 unlink ${n0} + + expect 0 create ${n0} 0644 + expect 0 chflags ${n0} UF_APPEND + expect EPERM unlink ${n0} + expect 0 chflags ${n0} none + expect 0 unlink ${n0} + ;; +esac diff --git a/tests/unlink/10.t b/tests/unlink/10.t new file mode 100644 index 000000000000..9ca1d5bc3fb1 --- /dev/null +++ b/tests/unlink/10.t @@ -0,0 +1,67 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/unlink/10.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="unlink returns EPERM if the parent directory of the named file has its immutable or append-only flag set" + +dir=`dirname $0` +. ${dir}/../misc.sh + +require chflags + +case "${os}:${fs}" in +FreeBSD:ZFS) + echo "1..16" + ;; +FreeBSD:UFS) + echo "1..30" + ;; +*) + quick_exit +esac + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 + +expect 0 create ${n0}/${n1} 0644 +expect 0 chflags ${n0} SF_IMMUTABLE +expect EPERM unlink ${n0}/${n1} +expect 0 chflags ${n0} none +expect 0 unlink ${n0}/${n1} + +expect 0 create ${n0}/${n1} 0644 +expect 0 chflags ${n0} SF_NOUNLINK +expect 0 unlink ${n0}/${n1} +expect 0 chflags ${n0} none + +expect 0 create ${n0}/${n1} 0644 +expect 0 chflags ${n0} SF_APPEND +todo FreeBSD:ZFS "Removing a file from a directory protected by SF_APPEND should return EPERM." +expect EPERM unlink ${n0}/${n1} +expect 0 chflags ${n0} none +todo FreeBSD:ZFS "Removing a file from a directory protected by SF_APPEND should return EPERM." +expect 0 unlink ${n0}/${n1} + +case "${os}:${fs}" in +FreeBSD:UFS) + expect 0 create ${n0}/${n1} 0644 + expect 0 chflags ${n0} UF_IMMUTABLE + expect EPERM unlink ${n0}/${n1} + expect 0 chflags ${n0} none + expect 0 unlink ${n0}/${n1} + + expect 0 create ${n0}/${n1} 0644 + expect 0 chflags ${n0} UF_NOUNLINK + expect 0 unlink ${n0}/${n1} + expect 0 chflags ${n0} none + + expect 0 create ${n0}/${n1} 0644 + expect 0 chflags ${n0} UF_APPEND + expect EPERM unlink ${n0}/${n1} + expect 0 chflags ${n0} none + expect 0 unlink ${n0}/${n1} + ;; +esac + +expect 0 rmdir ${n0} diff --git a/tests/unlink/11.t b/tests/unlink/11.t new file mode 100644 index 000000000000..d7d71d842d0d --- /dev/null +++ b/tests/unlink/11.t @@ -0,0 +1,63 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/unlink/11.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="unlink returns EACCES or EPERM if the directory containing the file is marked sticky, and neither the containing directory nor the file to be removed are owned by the effective user ID" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..270" + +n0=`namegen` +n1=`namegen` +n2=`namegen` + +expect 0 mkdir ${n2} 0755 +cdir=`pwd` +cd ${n2} + +expect 0 mkdir ${n0} 0755 +expect 0 chmod ${n0} 01777 +expect 0 chown ${n0} 65534 65534 + +for type in regular fifo block char socket symlink; do + # User owns both: the sticky directory and the file. + expect 0 chown ${n0} 65534 65534 + create_file ${type} ${n0}/${n1} 65534 65534 + expect ${type},65534,65534 lstat ${n0}/${n1} type,uid,gid + expect 0 -u 65534 -g 65534 unlink ${n0}/${n1} + expect ENOENT lstat ${n0}/${n1} type + + # User owns the sticky directory, but doesn't own the file. + for id in 0 65533; do + expect 0 chown ${n0} 65534 65534 + create_file ${type} ${n0}/${n1} ${id} ${id} + expect ${type},${id},${id} lstat ${n0}/${n1} type,uid,gid + expect 0 -u 65534 -g 65534 unlink ${n0}/${n1} + expect ENOENT lstat ${n0}/${n1} type + done + + # User owns the file, but doesn't own the sticky directory. + for id in 0 65533; do + expect 0 chown ${n0} ${id} ${id} + create_file ${type} ${n0}/${n1} 65534 65534 + expect ${type},65534,65534 lstat ${n0}/${n1} type,uid,gid + expect 0 -u 65534 -g 65534 unlink ${n0}/${n1} + expect ENOENT lstat ${n0}/${n1} type + done + + # User doesn't own the sticky directory nor the file. + for id in 0 65533; do + expect 0 chown ${n0} ${id} ${id} + create_file ${type} ${n0}/${n1} ${id} ${id} + expect ${type},${id},${id} lstat ${n0}/${n1} type,uid,gid + expect "EACCES|EPERM" -u 65534 -g 65534 unlink ${n0}/${n1} + expect ${type},${id},${id} lstat ${n0}/${n1} type,uid,gid + expect 0 unlink ${n0}/${n1} + done +done + +expect 0 rmdir ${n0} + +cd ${cdir} +expect 0 rmdir ${n2} diff --git a/tests/unlink/12.t b/tests/unlink/12.t new file mode 100644 index 000000000000..8f0c81ab6b12 --- /dev/null +++ b/tests/unlink/12.t @@ -0,0 +1,27 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/unlink/12.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="unlink returns EROFS if the named file resides on a read-only file system" + +dir=`dirname $0` +. ${dir}/../misc.sh + +[ "${os}:${fs}" = "FreeBSD:UFS" ] || quick_exit + +echo "1..5" + +n0=`namegen` +n1=`namegen` + +expect 0 mkdir ${n0} 0755 +n=`mdconfig -a -n -t malloc -s 1m` +newfs /dev/md${n} >/dev/null +mount /dev/md${n} ${n0} +expect 0 create ${n0}/${n1} 0644 +mount -ur /dev/md${n} +expect EROFS unlink ${n0}/${n1} +mount -uw /dev/md${n} +expect 0 unlink ${n0}/${n1} +umount /dev/md${n} +mdconfig -d -u ${n} +expect 0 rmdir ${n0} diff --git a/tests/unlink/13.t b/tests/unlink/13.t new file mode 100644 index 000000000000..c424b7ed0094 --- /dev/null +++ b/tests/unlink/13.t @@ -0,0 +1,12 @@ +#!/bin/sh +# $FreeBSD: head/tools/regression/pjdfstest/tests/unlink/13.t 211352 2010-08-15 21:24:17Z pjd $ + +desc="unlink returns EFAULT if the path argument points outside the process's allocated address space" + +dir=`dirname $0` +. ${dir}/../misc.sh + +echo "1..2" + +expect EFAULT unlink NULL +expect EFAULT unlink DEADCODE