xref: /freebsd-head/sys/contrib/openzfs/tests/zfs-tests/tests/functional/xattr/xattr_007_neg.ksh (revision 61145dc2b94f12f6a47344fb9aac702321880e43)
1#!/bin/ksh -p
2# SPDX-License-Identifier: CDDL-1.0
3#
4# CDDL HEADER START
5#
6# The contents of this file are subject to the terms of the
7# Common Development and Distribution License (the "License").
8# You may not use this file except in compliance with the License.
9#
10# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11# or https://opensource.org/licenses/CDDL-1.0.
12# See the License for the specific language governing permissions
13# and limitations under the License.
14#
15# When distributing Covered Code, include this CDDL HEADER in each
16# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17# If applicable, add the following below this CDDL HEADER, with the
18# fields enclosed by brackets "[]" replaced with your own identifying
19# information: Portions Copyright [yyyy] [name of copyright owner]
20#
21# CDDL HEADER END
22#
23# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24# Use is subject to license terms.
25#
26
27#
28# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
29#
30
31. $STF_SUITE/include/libtest.shlib
32. $STF_SUITE/tests/functional/xattr/xattr_common.kshlib
33
34#
35# DESCRIPTION:
36# Creating and writing xattrs on files in snapshot directories fails. Also,
37# we shouldn't be able to list the xattrs of files in snapshots who didn't have
38# xattrs when the snapshot was created (the xattr namespace wouldn't have been
39# created yet, and snapshots are read-only) See fsattr(5) for more details.
40#
41# STRATEGY:
42#	1. Create a file and add an xattr to it.
43#	2. Create another file, but don't add an xattr to it.
44#       3. Snapshot the filesystem
45#	4. Verify we're unable to alter the xattr on the first file
46#	5. Verify we're unable to list the xattrs on the second file
47#
48
49function cleanup {
50	log_must zfs destroy $TESTPOOL/$TESTFS@snap
51	log_must rm $TESTDIR/myfile2.$$
52	log_must rm $TESTDIR/myfile.$$
53	log_must rm $TEST_BASE_DIR/output.$$
54	[[ -e $TEST_BASE_DIR/expected_output.$$ ]]  && log_must rm  \
55	$TEST_BASE_DIR/expected_output.$$
56}
57
58log_assert "create/write xattr on a snapshot fails"
59log_onexit cleanup
60
61# create a file, and an xattr on it
62log_must touch $TESTDIR/myfile.$$
63create_xattr $TESTDIR/myfile.$$ passwd /etc/passwd
64
65# create another file that doesn't have an xattr
66log_must touch $TESTDIR/myfile2.$$
67
68# snapshot the filesystem
69log_must zfs snapshot $TESTPOOL/$TESTFS@snap
70
71# we shouldn't be able to alter the first file's xattr
72if is_illumos; then
73	log_mustnot eval " runat $TESTDIR/.zfs/snapshot/snap/myfile.$$ \
74	    cp /etc/passwd .  > $TEST_BASE_DIR/output.$$  2>&1"
75	log_must grep  -i  Read-only  $TEST_BASE_DIR/output.$$
76	log_must eval "runat $TESTDIR/.zfs/snapshot/snap/myfile2.$$  \
77	    ls > $TEST_BASE_DIR/output.$$  2>&1"
78	create_expected_output  $TEST_BASE_DIR/expected_output.$$ SUNWattr_ro SUNWattr_rw
79else
80	log_mustnot eval "set_xattr_stdin cp $TESTDIR/.zfs/snapshot/snap/myfile.$$ \
81	     </etc/passwd  > $TEST_BASE_DIR/output.$$  2>&1"
82	log_must grep  -i  Read-only  $TEST_BASE_DIR/output.$$
83	log_must eval "ls_xattr $TESTDIR/.zfs/snapshot/snap/myfile2.$$ \
84	    > $TEST_BASE_DIR/output.$$  2>&1"
85	log_must eval "ls_xattr $TESTDIR/myfile2.$$ > $TEST_BASE_DIR/expected_output.$$"
86fi
87
88log_must diff $TEST_BASE_DIR/output.$$ $TEST_BASE_DIR/expected_output.$$
89
90log_pass "create/write xattr on a snapshot fails"
91