1#!/usr/local/bin/ksh93 -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. $STF_SUITE/include/libtest.kshlib
25. $STF_SUITE/tests/xattr/xattr_common.kshlib
26
27################################################################################
28#
29# __stc_assertion_start
30#
31# ID:  xattr_007_neg
32#
33# DESCRIPTION:
34# Creating and writing xattrs on files in snapshot directories fails. Also,
35# we shouldn't be able to list the xattrs of files in snapshots who didn't have
36# xattrs when the snapshot was created (the xattr namespace wouldn't have been
37# created yet, and snapshots are read-only) See fsattr(5) for more details.
38#
39# STRATEGY:
40#	1. Create a file and add an xattr to it.
41#	2. Create another file, but don't add an xattr to it.
42#       3. Snapshot the filesystem
43#	4. Verify we're unable to alter the xattr on the first file
44#	5. Verify we're unable to list the xattrs on the second file
45#
46# TESTABILITY: explicit
47#
48# TEST_AUTOMATION_LEVEL: automated
49#
50# CODING_STATUS: COMPLETED (2006-12-13)
51#
52# __stc_assertion_end
53#
54################################################################################
55
56function cleanup {
57	log_must $ZFS destroy $TESTPOOL/$TESTFS@snap
58	log_must $RM $TESTDIR/myfile2.${TESTCASE_ID}
59	log_must $RM $TESTDIR/myfile.${TESTCASE_ID}
60	log_must $RM $TMPDIR/output.${TESTCASE_ID}
61	[[ -e $TMPDIR/expected_output.${TESTCASE_ID} ]]  && log_must $RM  \
62	$TMPDIR/expected_output.${TESTCASE_ID}
63
64}
65
66log_assert "create/write xattr on a snapshot fails"
67log_onexit cleanup
68
69# create a file, and an xattr on it
70log_must $TOUCH $TESTDIR/myfile.${TESTCASE_ID}
71create_xattr $TESTDIR/myfile.${TESTCASE_ID} passwd /etc/passwd
72
73# create another file that doesn't have an xattr
74log_must $TOUCH $TESTDIR/myfile2.${TESTCASE_ID}
75
76# snapshot the filesystem
77log_must $ZFS snapshot $TESTPOOL/$TESTFS@snap
78
79# we shouldn't be able to alter the first file's xattr
80log_mustnot eval " $RUNAT $TESTDIR/$(get_snapdir_name)/snap/myfile.${TESTCASE_ID} \
81	$CP /etc/passwd .  >$TMPDIR/output.${TESTCASE_ID}  2>&1"
82log_must $GREP  -i  Read-only  $TMPDIR/output.${TESTCASE_ID}
83
84if check_version "5.10"
85then
86	# we shouldn't be able to list xattrs at all on the second file
87	log_mustnot eval " $RUNAT $TESTDIR/$(get_snapdir_name)/snap/myfile2.${TESTCASE_ID} \
88	 $LS  >$TMPDIR/output.${TESTCASE_ID}  2>&1"
89	log_must $GREP  -i  Read-only  $TMPDIR/output.${TESTCASE_ID}
90else
91	log_must eval "$RUNAT $TESTDIR/$(get_snapdir_name)/snap/myfile2.${TESTCASE_ID}  \
92	$LS >$TMPDIR/output.${TESTCASE_ID}  2>&1"
93	create_expected_output  $TMPDIR/expected_output.${TESTCASE_ID}   SUNWattr_ro  \
94	 SUNWattr_rw
95	log_must $DIFF $TMPDIR/output.${TESTCASE_ID} $TMPDIR/expected_output.${TESTCASE_ID}
96fi
97log_pass "create/write xattr on a snapshot fails"
98