]> git.proxmox.com Git - mirror_zfs.git/blob - tests/zfs-tests/tests/functional/xattr/xattr_007_neg.ksh
Enable xattr tests
[mirror_zfs.git] / tests / zfs-tests / tests / functional / xattr / xattr_007_neg.ksh
1 #!/bin/ksh -p
2 #
3 # CDDL HEADER START
4 #
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.
8 #
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.
13 #
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]
19 #
20 # CDDL HEADER END
21 #
22 # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 # Use is subject to license terms.
24 #
25
26 #
27 # Copyright (c) 2013, 2016 by Delphix. All rights reserved.
28 #
29
30 . $STF_SUITE/include/libtest.shlib
31 . $STF_SUITE/tests/functional/xattr/xattr_common.kshlib
32
33 #
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.
39 #
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
46 #
47
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.$$
55
56 }
57
58 log_assert "create/write xattr on a snapshot fails"
59 log_onexit cleanup
60
61 # create a file, and an xattr on it
62 log_must touch $TESTDIR/myfile.$$
63 create_xattr $TESTDIR/myfile.$$ passwd /etc/passwd
64
65 # create another file that doesn't have an xattr
66 log_must touch $TESTDIR/myfile2.$$
67
68 # snapshot the filesystem
69 log_must zfs snapshot $TESTPOOL/$TESTFS@snap
70
71 # we shouldn't be able to alter the first file's xattr
72 if is_linux; then
73 log_mustnot eval "attr -s cp $TESTDIR/.zfs/snapshot/snap/myfile.$$ \
74 </etc/passwd >/tmp/output.$$ 2>&1"
75 log_must grep -i Read-only /tmp/output.$$
76 log_must eval "attr -q -l $TESTDIR/.zfs/snapshot/snap/myfile2.$$ \
77 >/tmp/output.$$ 2>&1"
78 log_must eval "attr -q -l $TESTDIR/myfile2.$$ >/tmp/expected_output.$$"
79 else
80 log_mustnot eval " runat $TESTDIR/.zfs/snapshot/snap/myfile.$$ \
81 cp /etc/passwd . >/tmp/output.$$ 2>&1"
82 log_must grep -i Read-only /tmp/output.$$
83 log_must eval "runat $TESTDIR/.zfs/snapshot/snap/myfile2.$$ \
84 ls >/tmp/output.$$ 2>&1"
85 create_expected_output /tmp/expected_output.$$ SUNWattr_ro SUNWattr_rw
86 fi
87
88 log_must diff /tmp/output.$$ /tmp/expected_output.$$
89
90 log_pass "create/write xattr on a snapshot fails"