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