7290 ZFS test suite needs to control what utilities it can run
[unleashed.git] / usr / src / test / zfs-tests / tests / functional / xattr / xattr_007_neg.ksh
blob6b3feeafc05bc63cc08cfbec8b9da2a03f8a15c0
1 #!/bin/ksh -p
3 # CDDL HEADER START
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
20 # CDDL HEADER END
22 # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 # Use is subject to license terms.
27 # Copyright (c) 2013, 2016 by Delphix. All rights reserved.
30 . $STF_SUITE/include/libtest.shlib
31 . $STF_SUITE/tests/functional/xattr/xattr_common.kshlib
34 # DESCRIPTION:
35 # Creating and writing xattrs on files in snapshot directories fails. Also,
36 # we shouldn't be able to list the xattrs of files in snapshots who didn't have
37 # xattrs when the snapshot was created (the xattr namespace wouldn't have been
38 # created yet, and snapshots are read-only) See fsattr(5) for more details.
40 # STRATEGY:
41 # 1. Create a file and add an xattr to it.
42 # 2. Create another file, but don't add an xattr to it.
43 # 3. Snapshot the filesystem
44 # 4. Verify we're unable to alter the xattr on the first file
45 # 5. Verify we're unable to list the xattrs on the second file
48 function cleanup {
49 log_must zfs destroy $TESTPOOL/$TESTFS@snap
50 log_must rm $TESTDIR/myfile2.$$
51 log_must rm $TESTDIR/myfile.$$
52 log_must rm /tmp/output.$$
53 [[ -e /tmp/expected_output.$$ ]] && log_must rm \
54 /tmp/expected_output.$$
58 log_assert "create/write xattr on a snapshot fails"
59 log_onexit cleanup
61 # create a file, and an xattr on it
62 log_must touch $TESTDIR/myfile.$$
63 create_xattr $TESTDIR/myfile.$$ passwd /etc/passwd
65 # create another file that doesn't have an xattr
66 log_must touch $TESTDIR/myfile2.$$
68 # snapshot the filesystem
69 log_must zfs snapshot $TESTPOOL/$TESTFS@snap
71 # we shouldn't be able to alter the first file's xattr
72 log_mustnot eval " runat $TESTDIR/.zfs/snapshot/snap/myfile.$$ \
73 cp /etc/passwd . >/tmp/output.$$ 2>&1"
74 log_must grep -i Read-only /tmp/output.$$
76 log_must eval "runat $TESTDIR/.zfs/snapshot/snap/myfile2.$$ \
77 ls >/tmp/output.$$ 2>&1"
78 create_expected_output /tmp/expected_output.$$ SUNWattr_ro SUNWattr_rw
79 log_must diff /tmp/output.$$ /tmp/expected_output.$$
81 log_pass "create/write xattr on a snapshot fails"