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
23#
24# Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
25#
26
27#
28# ID:  xattr_008
29#
30# DESCRIPTION:
31# Verify basic applications work with xattrs: cpio cp find mv pax tar
32#
33# STRATEGY:
34#	1. For each application
35#       2. Create an xattr and archive/move/copy/find files with xattr support
36#	3. Also check that when appropriate flag is not used, the xattr
37#	   doesn't get copied
38#
39
40. $STF_SUITE/include/libtest.ksh
41
42tc_id=xattr_008
43tc_desc="Verify basic applications work with xattrs: cpio cp find mv pax tar"
44print_test_case $tc_id - $tc_desc
45
46if [[ $STC_CIFS_CLIENT_DEBUG == 1 ]] || \
47	[[ *:${STC_CIFS_CLIENT_DEBUG}:* == *:$tc_id:* ]]; then
48    set -x
49fi
50
51server=$(server_name) || return
52
53CDIR=$(pwd)
54testdir_init $TDIR
55smbmount_clean $TMNT
56smbmount_init $TMNT
57
58cmd="mount -F smbfs //$TUSER:$TPASS@$server/public $TMNT"
59cti_execute -i '' FAIL $cmd
60if [[ $? != 0 ]]; then
61	cti_fail "FAIL: smbmount can't mount the public share unexpectedly"
62	return
63else
64	cti_report "PASS: smbmount can mount the public share as expected"
65fi
66
67smbmount_getmntopts $TMNT |grep /xattr/ >/dev/null
68if [[ $? != 0 ]]; then
69	smbmount_clean $TMNT
70	cti_unsupported "UNSUPPORTED (no xattr in this mount)"
71	return
72fi
73
74# Create a file, and set an xattr on it. This file is used in several of the
75# test scenarios below.
76
77cti_execute_cmd "touch $TMNT/test_file"
78create_xattr $TMNT/test_file passwd /etc/passwd
79
80# For the archive applications below (tar, cpio, pax)
81# we create two archives, one with xattrs, one without
82# and try various cpio options extracting the archives
83# with and without xattr support, checking for correct behaviour
84
85cpio_xattr=$CDIR/xattr.cpio
86cpio_noxattr=$CDIR/noxattr.cpio
87
88cti_report "Checking cpio"
89cti_execute_cmd "touch $TMNT/cpio_test"
90create_xattr $TMNT/cpio_test passwd /etc/passwd
91
92cti_execute_cmd "echo cpio_test| (cd $TMNT; cpio -oc@ -O $cpio_xattr)"
93cti_execute_cmd "echo cpio_test| (cd $TMNT; cpio -oc -O $cpio_noxattr)"
94cti_execute_cmd "rm -rf $TMNT/cpio_test"
95
96# we should have no xattr here
97
98cti_execute_cmd "(cd $TMNT; cpio -iu -I $cpio_xattr)"
99cti_execute_cmd "runat $TMNT/cpio_test cat passwd"
100if [[ $? == 0 ]]
101then
102	cti_fail "Fail: we have xattr here unexpectedly"
103	return
104fi
105cti_execute_cmd "rm -rf $TMNT/cpio_test"
106
107# we should have an xattr here
108
109cti_execute_cmd "(cd $TMNT; cpio -iu@ -I $cpio_xattr)"
110verify_xattr $TMNT/cpio_test passwd /etc/passwd
111cti_execute_cmd "rm -rf $TMNT/cpio_test"
112
113#do the same for the second time
114
115cti_execute_cmd "(cd $TMNT; cpio -iu@ -I $cpio_xattr)"
116verify_xattr $TMNT/cpio_test passwd /etc/passwd
117cti_execute_cmd "rm -rf $TMNT/cpio_test"
118
119# we should have no xattr here
120
121cti_execute_cmd "(cd $TMNT; cpio -iu -I $cpio_noxattr)"
122cti_execute_cmd "runat $TMNT/cpio_test cat passwd"
123if [[ $? == 0 ]]
124then
125	cti_fail "Fail: we have xattr here unexpectedly"
126	return
127fi
128cti_execute_cmd "rm -rf $TMNT/cpio_test"
129
130# we should have no xattr here
131
132cti_execute_cmd "(cd $TMNT; cpio -iu@ -I $cpio_noxattr)"
133cti_execute_cmd "runat $TMNT/cpio_test cat passwd"
134if [[ $? == 0 ]]
135then
136	cti_fail "Fail: we have xattr here unexpectedly"
137	return
138fi
139
140cti_execute_cmd "rm -rf $TMNT/cpio_test"
141cti_execute_cmd "rm -rf $cpio_xattr"
142cti_execute_cmd "rm -rf $cpio_noxattr"
143
144cti_report "Checking cp"
145# check that with the right flag, the xattr is preserved
146
147cti_execute_cmd "(cd $TMNT; cp -@ test_file test_file1)"
148compare_xattrs $TMNT/test_file $TMNT/test_file1 passwd
149cti_execute_cmd "rm -rf $TMNT/test_file1"
150
151# without the right flag, there should be no xattr (ls should fail)
152
153cti_execute_cmd "(cd $TMNT; cp test_file test_file1)"
154cti_execute_cmd "runat $TMNT/cpio_test ls passwd"
155if [[ $? == 0 ]]
156then
157	cti_fail "Fail: we have xattr here unexpectedly"
158	return
159fi
160cti_execute_cmd "rm -rf $TMNT/test_file1"
161
162# create a file without xattrs, and check that find -xattr only finds
163# our test file that has an xattr.
164
165cti_report "Checking find"
166cti_execute_cmd "mkdir $TMNT/noxattrs"
167cti_execute_cmd "touch $TMNT/noxattrs/no-xattr"
168
169cti_execute_cmd "find $TMNT -xattr | grep test_file"
170if [ $? -ne 0 ]
171then
172	cti_fail "find -xattr didn't find our file that had an xattr unexpectedly"
173fi
174cti_execute_cmd "find $TMNT -xattr | grep no-xattr"
175if [ $? -eq 0 ]
176then
177	cti_fail "find -xattr found a file that didn't have an xattr unexpectedly"
178fi
179cti_execute_cmd "rm -rf $TMNT/noxattrs"
180
181# mv doesn't have any flags to preserve/ommit xattrs - they're
182# always moved.
183
184cti_report "Checking mv"
185cti_execute_cmd "touch $TMNT/mvtest"
186create_xattr $TMNT/mvtest passwd /etc/passwd
187cti_execute_cmd "(cd $TMNT; mv mvtest mvtest2)"
188verify_xattr $TMNT/mvtest2 passwd /etc/passwd
189cti_execute_cmd "rm $TMNT/mvtest"
190cti_execute_cmd "rm $TMNT/mvtest2"
191
192pax_xattr=$CDIR/xattr.pax
193pax_noxattr=$CDIR/noxattr.pax
194
195cti_report "Checking pax"
196cti_execute_cmd "touch $TMNT/pax_test"
197create_xattr $TMNT/pax_test passwd /etc/passwd
198cti_execute_cmd "(cd $TMNT; pax -w -f $pax_noxattr pax_test)"
199cti_execute_cmd "(cd $TMNT; pax -w@ -f $pax_xattr pax_test)"
200cti_execute_cmd "rm $TMNT/pax_test"
201
202# we should have no xattr here
203
204cti_execute_cmd "(cd $TMNT; pax -r -f $pax_noxattr)"
205cti_execute_cmd "runat $TMNT/pax_test cat passwd"
206if [[ $? == 0 ]]; then
207	cti_fail "FAIL: we have xattr here unexpectedly"
208	return
209else
210	cti_report "PASS: we should have no xattr here as expected"
211fi
212cti_execute_cmd "rm $TMNT/pax_test"
213
214# we should have no xattr here
215
216cti_execute_cmd "(cd $TMNT; pax -r@ -f $pax_noxattr)"
217cti_execute_cmd "runat $TMNT/pax_test cat passwd"
218if [[ $? == 0 ]]; then
219	cti_fail "FAIL: we have xattr here unexpectedly"
220	return
221else
222	cti_report "PASS: we should have no xattr here as expected"
223fi
224cti_execute_cmd "rm $TMNT/pax_test"
225
226# we should have an xattr here
227
228cti_execute_cmd "(cd $TMNT; pax -r@ -f $pax_xattr)"
229verify_xattr $TMNT/pax_test passwd /etc/passwd
230cti_execute_cmd "rm $TMNT/pax_test"
231
232# we should have no xattr here
233
234cti_execute_cmd "(cd $TMNT; pax -r -f $pax_xattr)"
235cti_execute_cmd "runat $TMNT/pax_test cat passwd"
236if [[ $? == 0 ]]; then
237	cti_fail "FAIL: we have xattr here unexpectedly"
238	return
239else
240	cti_report "PASS: we should have no xattr here as expected"
241fi
242cti_execute_cmd "rm $TMNT/pax_test"
243cti_execute_cmd "rm $pax_noxattr"
244cti_execute_cmd "rm $pax_xattr"
245
246tar_xattr=$CDIR/xattr.tar
247tar_noxattr=$CDIR/noxattr.tar
248
249cti_report "Checking tar"
250cti_execute_cmd "touch $TMNT/tar_test"
251create_xattr $TMNT/tar_test passwd /etc/passwd
252cti_execute_cmd "(cd $TMNT; tar cf $tar_noxattr tar_test)"
253cti_execute_cmd "(cd $TMNT; tar c@f $tar_xattr tar_test)"
254cti_execute_cmd "rm $TMNT/tar_test"
255
256# we should have no xattr here
257
258cti_execute_cmd "(cd $TMNT; tar xf $tar_xattr)"
259cti_execute_cmd "runat $TMNT/tar_test cat passwd"
260if [[ $? == 0 ]]; then
261	cti_fail "FAIL: we have xattr here unexpectedly"
262	return
263else
264	cti_report "PASS: we should have no xattr here as expected"
265fi
266cti_execute_cmd "rm $TMNT/tar_test"
267
268# we should have an xattr here
269
270cti_execute_cmd "(cd $TMNT; tar x@f $tar_xattr)"
271verify_xattr $TMNT/tar_test passwd /etc/passwd
272cti_execute_cmd "rm $TMNT/tar_test"
273
274# we should have no xattr here
275
276cti_execute_cmd "(cd $TMNT; tar xf $tar_noxattr)"
277cti_execute_cmd "runat $TMNT/tar_test cat passwd"
278if [[ $? == 0 ]]; then
279	cti_fail "FAIL: we have xattr here unexpectedly"
280	return
281else
282	cti_report "PASS: we should have no xattr here as expected"
283fi
284cti_execute_cmd "rm $TMNT/tar_test"
285
286# we should have no xattr here
287
288cti_execute_cmd "(cd $TMNT; tar x@f $tar_noxattr)"
289cti_execute_cmd "runat $TMNT/tar_test cat passwd"
290if [[ $? == 0 ]]; then
291	cti_fail "FAIL: we have xattr here unexpectedly"
292	return
293else
294	cti_report "PASS: we should have no xattr here as expected"
295fi
296cti_execute_cmd "rm $TMNT/tar_test"
297cti_execute_cmd "rm $tar_noxattr"
298cti_execute_cmd "rm $tar_xattr"
299
300cti_execute_cmd "rm -rf $TMNT/*"
301
302smbmount_clean $TMNT
303cti_pass "$tc_id: PASS"
304