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 2007 Sun Microsystems, Inc.  All rights reserved.
23# Use is subject to license terms.
24#
25# ident	"@(#)xattr_011_pos.ksh	1.1	07/02/06 SMI"
26#
27
28# $FreeBSD$
29
30. $STF_SUITE/include/libtest.kshlib
31. $STF_SUITE/tests/xattr/xattr_common.kshlib
32
33################################################################################
34#
35# __stc_assertion_start
36#
37# ID:  xattr_011_pos
38#
39# DESCRIPTION:
40#
41# Basic applications work with xattrs: cpio cp find mv pax tar
42#
43# STRATEGY:
44#	1. For each application
45#       2. Create an xattr and archive/move/copy/find files with xattr support
46#	3. Also check that when appropriate flag is not used, the xattr
47#	   doesn't get copied
48#
49# TESTABILITY: explicit
50#
51# TEST_AUTOMATION_LEVEL: automated
52#
53# CODING_STATUS: COMPLETED (2006-12-15)
54#
55# __stc_assertion_end
56#
57################################################################################
58
59function cleanup {
60
61	log_must $RM $TESTDIR/myfile.${TESTCASE_ID}
62}
63
64log_assert "Basic applications work with xattrs: cpio cp find mv pax tar"
65log_onexit cleanup
66
67test_requires RUNAT
68
69# Create a file, and set an xattr on it. This file is used in several of the
70# test scenarios below.
71log_must $TOUCH $TESTDIR/myfile.${TESTCASE_ID}
72create_xattr $TESTDIR/myfile.${TESTCASE_ID} passwd /etc/passwd
73
74
75# For the archive applications below (tar, cpio, pax)
76# we create two archives, one with xattrs, one without
77# and try various cpio options extracting the archives
78# with and without xattr support, checking for correct behaviour
79
80
81log_note "Checking cpio"
82log_must $TOUCH $TESTDIR/cpio.${TESTCASE_ID}
83create_xattr $TESTDIR/cpio.${TESTCASE_ID} passwd /etc/passwd
84$ECHO $TESTDIR/cpio.${TESTCASE_ID} | $CPIO -o@ > $TMPDIR/xattr.${TESTCASE_ID}.cpio
85$ECHO $TESTDIR/cpio.${TESTCASE_ID} | $CPIO -o > $TMPDIR/noxattr.${TESTCASE_ID}.cpio
86
87# we should have no xattr here
88log_must $CPIO -iu < $TMPDIR/xattr.${TESTCASE_ID}.cpio
89log_mustnot eval "$RUNAT $TESTDIR/cpio.${TESTCASE_ID} $CAT passwd > /dev/null 2>&1"
90
91# we should have an xattr here
92log_must $CPIO -iu@ < $TMPDIR/xattr.${TESTCASE_ID}.cpio
93log_must eval "$RUNAT $TESTDIR/cpio.${TESTCASE_ID} $CAT passwd > /dev/null 2>&1"
94
95# we should have no xattr here
96log_must $CPIO -iu < $TMPDIR/noxattr.${TESTCASE_ID}.cpio
97log_mustnot eval "$RUNAT $TESTDIR/cpio.${TESTCASE_ID} $CAT passwd > /dev/null 2>&1"
98
99# we should have no xattr here
100log_must $CPIO -iu@ < $TMPDIR/noxattr.${TESTCASE_ID}.cpio
101log_mustnot eval "$RUNAT $TESTDIR/cpio.${TESTCASE_ID} $CAT passwd > /dev/null 2>&1"
102log_must $RM $TESTDIR/cpio.${TESTCASE_ID} $TMPDIR/xattr.${TESTCASE_ID}.cpio $TMPDIR/noxattr.${TESTCASE_ID}.cpio
103
104
105
106log_note "Checking cp"
107# check that with the right flag, the xattr is preserved
108log_must $CP -@ $TESTDIR/myfile.${TESTCASE_ID} $TESTDIR/myfile2.${TESTCASE_ID}
109compare_xattrs $TESTDIR/myfile.${TESTCASE_ID} $TESTDIR/myfile2.${TESTCASE_ID} passwd
110log_must $RM $TESTDIR/myfile2.${TESTCASE_ID}
111
112# without the right flag, there should be no xattr
113log_must $CP $TESTDIR/myfile.${TESTCASE_ID} $TESTDIR/myfile2.${TESTCASE_ID}
114log_mustnot eval "$RUNAT $TESTDIR/myfile2.${TESTCASE_ID} $LS passwd > /dev/null 2>&1"
115log_must $RM $TESTDIR/myfile2.${TESTCASE_ID}
116
117
118
119log_note "Checking find"
120# create a file without xattrs, and check that find -xattr only finds
121# our test file that has an xattr.
122log_must $MKDIR $TESTDIR/noxattrs
123log_must $TOUCH $TESTDIR/noxattrs/no-xattr
124
125$FIND $TESTDIR -xattr | $GREP myfile.${TESTCASE_ID}
126if [ $? -ne 0 ]
127then
128	log_fail "find -xattr didn't find our file that had an xattr."
129fi
130$FIND $TESTDIR -xattr | $GREP no-xattr
131if [ $? -eq 0 ]
132then
133	log_fail "find -xattr found a file that didn't have an xattr."
134fi
135log_must $RM -rf $TESTDIR/noxattrs
136
137
138
139log_note "Checking mv"
140# mv doesn't have any flags to preserve/ommit xattrs - they're
141# always moved.
142log_must $TOUCH $TESTDIR/mvfile.${TESTCASE_ID}
143create_xattr $TESTDIR/mvfile.${TESTCASE_ID} passwd /etc/passwd
144log_must $MV $TESTDIR/mvfile.${TESTCASE_ID} $TESTDIR/mvfile2.${TESTCASE_ID}
145verify_xattr $TESTDIR/mvfile2.${TESTCASE_ID} passwd /etc/passwd
146log_must $RM $TESTDIR/mvfile2.${TESTCASE_ID}
147
148
149log_note "Checking pax"
150log_must $TOUCH $TESTDIR/pax.${TESTCASE_ID}
151create_xattr $TESTDIR/pax.${TESTCASE_ID} passwd /etc/passwd
152log_must $PAX -w -f $TESTDIR/noxattr.pax $TESTDIR/pax.${TESTCASE_ID}
153log_must $PAX -w@ -f $TESTDIR/xattr.pax $TESTDIR/pax.${TESTCASE_ID}
154log_must $RM $TESTDIR/pax.${TESTCASE_ID}
155
156# we should have no xattr here
157log_must $PAX -r -f $TESTDIR/noxattr.pax
158log_mustnot eval "$RUNAT $TESTDIR/pax.${TESTCASE_ID} $CAT passwd > /dev/null 2>&1"
159log_must $RM $TESTDIR/pax.${TESTCASE_ID}
160
161# we should have no xattr here
162log_must $PAX -r@ -f $TESTDIR/noxattr.pax
163log_mustnot eval "$RUNAT $TESTDIR/pax.${TESTCASE_ID} $CAT passwd > /dev/null 2>&1"
164log_must $RM $TESTDIR/pax.${TESTCASE_ID}
165
166
167# we should have an xattr here
168log_must $PAX -r@ -f $TESTDIR/xattr.pax
169verify_xattr $TESTDIR/pax.${TESTCASE_ID} passwd /etc/passwd
170log_must $RM $TESTDIR/pax.${TESTCASE_ID}
171
172# we should have no xattr here
173log_must $PAX -r -f $TESTDIR/xattr.pax
174log_mustnot eval "$RUNAT $TESTDIR/pax.${TESTCASE_ID} $CAT passwd > /dev/null 2>&1"
175log_must $RM $TESTDIR/pax.${TESTCASE_ID} $TESTDIR/noxattr.pax $TESTDIR/xattr.pax
176
177
178log_note "Checking tar"
179log_must $TOUCH $TESTDIR/tar.${TESTCASE_ID}
180create_xattr $TESTDIR/tar.${TESTCASE_ID} passwd /etc/passwd
181log_must $TAR cf $TESTDIR/noxattr.tar $TESTDIR/tar.${TESTCASE_ID}
182log_must $TAR c@f $TESTDIR/xattr.tar $TESTDIR/tar.${TESTCASE_ID}
183log_must $RM $TESTDIR/tar.${TESTCASE_ID}
184
185# we should have no xattr here
186log_must $TAR xf $TESTDIR/xattr.tar
187log_mustnot eval "$RUNAT $TESTDIR/tar.${TESTCASE_ID} $CAT passwd > /dev/null 2>&1"
188log_must $RM $TESTDIR/tar.${TESTCASE_ID}
189
190# we should have an xattr here
191log_must $TAR x@f $TESTDIR/xattr.tar
192verify_xattr $TESTDIR/tar.${TESTCASE_ID} passwd /etc/passwd
193log_must $RM $TESTDIR/tar.${TESTCASE_ID}
194
195# we should have no xattr here
196log_must $TAR xf $TESTDIR/noxattr.tar
197log_mustnot eval "$RUNAT $TESTDIR/tar.${TESTCASE_ID} $CAT passwd > /dev/null 2>&1"
198log_must $RM $TESTDIR/tar.${TESTCASE_ID}
199
200# we should have no xattr here
201log_must $TAR x@f $TESTDIR/noxattr.tar
202log_mustnot eval "$RUNAT $TESTDIR/tar.${TESTCASE_ID} $CAT passwd > /dev/null 2>&1"
203log_must $RM $TESTDIR/tar.${TESTCASE_ID} $TESTDIR/noxattr.tar $TESTDIR/xattr.tar
204