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# Copyright 2007 Sun Microsystems, Inc. All rights reserved. 23# Use is subject to license terms. 24# 25 26# 27# Copyright (c) 2012, 2016 by Delphix. All rights reserved. 28# 29 30# 31# Copyright (c) 2013, 2016 by Delphix. All rights reserved. 32# 33 34. $STF_SUITE/include/libtest.shlib 35. $STF_SUITE/tests/functional/xattr/xattr_common.kshlib 36 37# 38# DESCRIPTION: 39# 40# Basic applications work with xattrs: cpio cp find mv pax tar 41# 42# STRATEGY: 43# 1. For each application 44# 2. Create an xattr and archive/move/copy/find files with xattr support 45# 3. Also check that when appropriate flag is not used, the xattr 46# doesn't get copied 47# 48 49function cleanup { 50 51 log_must rm $TESTDIR/myfile.$$ 52} 53 54log_assert "Basic applications work with xattrs: cpio cp find mv pax tar" 55log_onexit cleanup 56 57# Create a file, and set an xattr on it. This file is used in several of the 58# test scenarios below. 59log_must touch $TESTDIR/myfile.$$ 60create_xattr $TESTDIR/myfile.$$ passwd /etc/passwd 61 62 63# For the archive applications below (tar, cpio, pax) 64# we create two archives, one with xattrs, one without 65# and try various cpio options extracting the archives 66# with and without xattr support, checking for correct behaviour 67 68if is_illumos; then 69 log_note "Checking cpio" 70 log_must touch $TESTDIR/cpio.$$ 71 create_xattr $TESTDIR/cpio.$$ passwd /etc/passwd 72 echo $TESTDIR/cpio.$$ | cpio -o@ > $TEST_BASE_DIR/xattr.$$.cpio 73 echo $TESTDIR/cpio.$$ | cpio -o > $TEST_BASE_DIR/noxattr.$$.cpio 74 75 # we should have no xattr here 76 log_must cpio -iu < $TEST_BASE_DIR/xattr.$$.cpio 77 log_mustnot eval "runat $TESTDIR/cpio.$$ cat passwd > /dev/null 2>&1" 78 79 # we should have an xattr here 80 log_must cpio -iu@ < $TEST_BASE_DIR/xattr.$$.cpio 81 log_must eval "runat $TESTDIR/cpio.$$ cat passwd > /dev/null 2>&1" 82 83 # we should have no xattr here 84 log_must cpio -iu < $TEST_BASE_DIR/noxattr.$$.cpio 85 log_mustnot eval "runat $TESTDIR/cpio.$$ cat passwd > /dev/null 2>&1" 86 87 # we should have no xattr here 88 log_must cpio -iu@ < $TEST_BASE_DIR/noxattr.$$.cpio 89 log_mustnot eval "runat $TESTDIR/cpio.$$ cat passwd > /dev/null 2>&1" 90 log_must rm $TESTDIR/cpio.$$ $TEST_BASE_DIR/xattr.$$.cpio $TEST_BASE_DIR/noxattr.$$.cpio 91else 92 log_note "Checking cpio - unsupported" 93fi 94 95# check that with the right flag, the xattr is preserved 96if is_freebsd; then 97 log_note "Checking cp - unsupported" 98elif is_linux; then 99 log_note "Checking cp" 100 log_must cp -a $TESTDIR/myfile.$$ $TESTDIR/myfile2.$$ 101 102 compare_xattrs $TESTDIR/myfile.$$ $TESTDIR/myfile2.$$ passwd 103 log_must rm $TESTDIR/myfile2.$$ 104 105 # without the right flag, there should be no xattr 106 log_must cp $TESTDIR/myfile.$$ $TESTDIR/myfile2.$$ 107 log_mustnot get_xattr passwd $TESTDIR/myfile2.$$ 108 log_must rm $TESTDIR/myfile2.$$ 109else 110 log_note "Checking cp" 111 log_must cp -@ $TESTDIR/myfile.$$ $TESTDIR/myfile2.$$ 112 113 compare_xattrs $TESTDIR/myfile.$$ $TESTDIR/myfile2.$$ passwd 114 log_must rm $TESTDIR/myfile2.$$ 115 116 # without the right flag, there should be no xattr 117 log_must cp $TESTDIR/myfile.$$ $TESTDIR/myfile2.$$ 118 log_mustnot eval "runat $TESTDIR/myfile2.$$ ls passwd > /dev/null 2>&1" 119 log_must rm $TESTDIR/myfile2.$$ 120fi 121 122# create a file without xattrs, and check that find -xattr only finds 123# our test file that has an xattr. 124if is_illumos; then 125 log_note "Checking find" 126 log_must mkdir $TESTDIR/noxattrs 127 log_must touch $TESTDIR/noxattrs/no-xattr 128 129 find $TESTDIR -xattr | grep myfile.$$ 130 [[ $? -ne 0 ]] && \ 131 log_fail "find -xattr didn't find our file that had an xattr." 132 find $TESTDIR -xattr | grep no-xattr 133 [[ $? -eq 0 ]] && \ 134 log_fail "find -xattr found a file that didn't have an xattr." 135 log_must rm -rf $TESTDIR/noxattrs 136else 137 log_note "Checking find - unsupported" 138fi 139 140log_note "Checking mv" 141# mv doesn't have any flags to preserve/omit xattrs - they're 142# always moved. 143log_must touch $TESTDIR/mvfile.$$ 144create_xattr $TESTDIR/mvfile.$$ passwd /etc/passwd 145log_must mv $TESTDIR/mvfile.$$ $TESTDIR/mvfile2.$$ 146verify_xattr $TESTDIR/mvfile2.$$ passwd /etc/passwd 147log_must rm $TESTDIR/mvfile2.$$ 148 149if is_illumos; then 150 log_note "Checking pax" 151 log_must touch $TESTDIR/pax.$$ 152 create_xattr $TESTDIR/pax.$$ passwd /etc/passwd 153 log_must pax -w -f $TESTDIR/noxattr.pax $TESTDIR/pax.$$ 154 log_must pax -w@ -f $TESTDIR/xattr.pax $TESTDIR/pax.$$ 155 log_must rm $TESTDIR/pax.$$ 156 157 # we should have no xattr here 158 log_must pax -r -f $TESTDIR/noxattr.pax 159 log_mustnot eval "runat $TESTDIR/pax.$$ cat passwd > /dev/null 2>&1" 160 log_must rm $TESTDIR/pax.$$ 161 162 # we should have no xattr here 163 log_must pax -r@ -f $TESTDIR/noxattr.pax 164 log_mustnot eval "runat $TESTDIR/pax.$$ cat passwd > /dev/null 2>&1" 165 log_must rm $TESTDIR/pax.$$ 166 167 # we should have an xattr here 168 log_must pax -r@ -f $TESTDIR/xattr.pax 169 verify_xattr $TESTDIR/pax.$$ passwd /etc/passwd 170 log_must rm $TESTDIR/pax.$$ 171 172 # we should have no xattr here 173 log_must pax -r -f $TESTDIR/xattr.pax $TESTDIR 174 log_mustnot eval "runat $TESTDIR/pax.$$ cat passwd > /dev/null 2>&1" 175 log_must rm $TESTDIR/pax.$$ $TESTDIR/noxattr.pax $TESTDIR/xattr.pax 176else 177 log_note "Checking pax - unsupported" 178fi 179 180log_note "Checking tar" 181if is_illumos; then 182 log_must touch $TESTDIR/tar.$$ 183 create_xattr $TESTDIR/tar.$$ passwd /etc/passwd 184 185 log_must cd $TESTDIR 186 187 log_must tar cf noxattr.tar tar.$$ 188 log_must tar c@f xattr.tar tar.$$ 189 log_must rm $TESTDIR/tar.$$ 190 191 # we should have no xattr here 192 log_must tar xf xattr.tar 193 log_mustnot eval "runat $TESTDIR/tar.$$ cat passwd > /dev/null 2>&1" 194 log_must rm $TESTDIR/tar.$$ 195 196 # we should have an xattr here 197 log_must tar x@f xattr.tar 198 verify_xattr tar.$$ passwd /etc/passwd 199 log_must rm $TESTDIR/tar.$$ 200 201 # we should have no xattr here 202 log_must tar xf $TESTDIR/noxattr.tar 203 log_mustnot eval "runat $TESTDIR/tar.$$ cat passwd > /dev/null 2>&1" 204 log_must rm $TESTDIR/tar.$$ 205 206 # we should have no xattr here 207 log_must tar x@f $TESTDIR/noxattr.tar 208 log_mustnot eval "runat $TESTDIR/tar.$$ cat passwd > /dev/null 2>&1" 209 log_must rm $TESTDIR/tar.$$ $TESTDIR/noxattr.tar $TESTDIR/xattr.tar 210else 211 log_must touch $TESTDIR/tar.$$ 212 create_xattr $TESTDIR/tar.$$ passwd /etc/passwd 213 214 log_must cd $TESTDIR 215 216 log_must tar --no-xattrs -cf noxattr.tar tar.$$ 217 log_must tar --xattrs -cf xattr.tar tar.$$ 218 log_must rm $TESTDIR/tar.$$ 219 220 # we should have no xattr here 221 log_must tar --no-xattrs -xf xattr.tar 222 log_mustnot get_xattr passwd $TESTDIR/tar.$$ 223 log_must rm $TESTDIR/tar.$$ 224 225 # we should have an xattr here 226 log_must tar --xattrs -xf xattr.tar 227 verify_xattr tar.$$ passwd /etc/passwd 228 log_must rm $TESTDIR/tar.$$ 229 230 # we should have no xattr here 231 log_must tar --no-xattrs -xf $TESTDIR/noxattr.tar 232 log_mustnot get_xattr passwd $TESTDIR/tar.$$ 233 log_must rm $TESTDIR/tar.$$ 234 235 # we should have no xattr here 236 log_must tar --xattrs -xf $TESTDIR/noxattr.tar 237 log_mustnot get_xattr passwd $TESTDIR/tar.$$ 238 log_must rm $TESTDIR/tar.$$ $TESTDIR/noxattr.tar $TESTDIR/xattr.tar 239fi 240 241log_assert "Basic applications work with xattrs: cpio cp find mv pax tar" 242