1f38cb554SJohn Wren Kennedy#!/bin/ksh -p 2f38cb554SJohn Wren Kennedy# 3f38cb554SJohn Wren Kennedy# CDDL HEADER START 4f38cb554SJohn Wren Kennedy# 5f38cb554SJohn Wren Kennedy# The contents of this file are subject to the terms of the 6f38cb554SJohn Wren Kennedy# Common Development and Distribution License (the "License"). 7f38cb554SJohn Wren Kennedy# You may not use this file except in compliance with the License. 8f38cb554SJohn Wren Kennedy# 9f38cb554SJohn Wren Kennedy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10f38cb554SJohn Wren Kennedy# or http://www.opensolaris.org/os/licensing. 11f38cb554SJohn Wren Kennedy# See the License for the specific language governing permissions 12f38cb554SJohn Wren Kennedy# and limitations under the License. 13f38cb554SJohn Wren Kennedy# 14f38cb554SJohn Wren Kennedy# When distributing Covered Code, include this CDDL HEADER in each 15f38cb554SJohn Wren Kennedy# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16f38cb554SJohn Wren Kennedy# If applicable, add the following below this CDDL HEADER, with the 17f38cb554SJohn Wren Kennedy# fields enclosed by brackets "[]" replaced with your own identifying 18f38cb554SJohn Wren Kennedy# information: Portions Copyright [yyyy] [name of copyright owner] 19f38cb554SJohn Wren Kennedy# 20f38cb554SJohn Wren Kennedy# CDDL HEADER END 21f38cb554SJohn Wren Kennedy# 22f38cb554SJohn Wren Kennedy# Copyright 2007 Sun Microsystems, Inc. All rights reserved. 23f38cb554SJohn Wren Kennedy# Use is subject to license terms. 24f38cb554SJohn Wren Kennedy# 25f38cb554SJohn Wren Kennedy 26f38cb554SJohn Wren Kennedy# 27*1d32ba66SJohn Wren Kennedy# Copyright (c) 2012, 2016 by Delphix. All rights reserved. 28f38cb554SJohn Wren Kennedy# 29f38cb554SJohn Wren Kennedy 30f38cb554SJohn Wren Kennedy# 31*1d32ba66SJohn Wren Kennedy# Copyright (c) 2013, 2016 by Delphix. All rights reserved. 32f38cb554SJohn Wren Kennedy# 33f38cb554SJohn Wren Kennedy 34f38cb554SJohn Wren Kennedy. $STF_SUITE/include/libtest.shlib 35f38cb554SJohn Wren Kennedy. $STF_SUITE/tests/functional/xattr/xattr_common.kshlib 36f38cb554SJohn Wren Kennedy 37f38cb554SJohn Wren Kennedy# 38f38cb554SJohn Wren Kennedy# DESCRIPTION: 39f38cb554SJohn Wren Kennedy# 40f38cb554SJohn Wren Kennedy# Basic applications work with xattrs: cpio cp find mv pax tar 41f38cb554SJohn Wren Kennedy# 42f38cb554SJohn Wren Kennedy# STRATEGY: 43f38cb554SJohn Wren Kennedy# 1. For each application 44f38cb554SJohn Wren Kennedy# 2. Create an xattr and archive/move/copy/find files with xattr support 45f38cb554SJohn Wren Kennedy# 3. Also check that when appropriate flag is not used, the xattr 46f38cb554SJohn Wren Kennedy# doesn't get copied 47f38cb554SJohn Wren Kennedy# 48f38cb554SJohn Wren Kennedy 49f38cb554SJohn Wren Kennedyfunction cleanup { 50f38cb554SJohn Wren Kennedy 51*1d32ba66SJohn Wren Kennedy log_must rm $TESTDIR/myfile.$$ 52f38cb554SJohn Wren Kennedy} 53f38cb554SJohn Wren Kennedy 54f38cb554SJohn Wren Kennedylog_assert "Basic applications work with xattrs: cpio cp find mv pax tar" 55f38cb554SJohn Wren Kennedylog_onexit cleanup 56f38cb554SJohn Wren Kennedy 57f38cb554SJohn Wren Kennedy# Create a file, and set an xattr on it. This file is used in several of the 58f38cb554SJohn Wren Kennedy# test scenarios below. 59*1d32ba66SJohn Wren Kennedylog_must touch $TESTDIR/myfile.$$ 60f38cb554SJohn Wren Kennedycreate_xattr $TESTDIR/myfile.$$ passwd /etc/passwd 61f38cb554SJohn Wren Kennedy 62f38cb554SJohn Wren Kennedy 63f38cb554SJohn Wren Kennedy# For the archive applications below (tar, cpio, pax) 64f38cb554SJohn Wren Kennedy# we create two archives, one with xattrs, one without 65f38cb554SJohn Wren Kennedy# and try various cpio options extracting the archives 66f38cb554SJohn Wren Kennedy# with and without xattr support, checking for correct behaviour 67f38cb554SJohn Wren Kennedy 68f38cb554SJohn Wren Kennedy 69f38cb554SJohn Wren Kennedylog_note "Checking cpio" 70*1d32ba66SJohn Wren Kennedylog_must touch $TESTDIR/cpio.$$ 71f38cb554SJohn Wren Kennedycreate_xattr $TESTDIR/cpio.$$ passwd /etc/passwd 72*1d32ba66SJohn Wren Kennedyecho $TESTDIR/cpio.$$ | cpio -o@ > /tmp/xattr.$$.cpio 73*1d32ba66SJohn Wren Kennedyecho $TESTDIR/cpio.$$ | cpio -o > /tmp/noxattr.$$.cpio 74f38cb554SJohn Wren Kennedy 75f38cb554SJohn Wren Kennedy# we should have no xattr here 76*1d32ba66SJohn Wren Kennedylog_must cpio -iu < /tmp/xattr.$$.cpio 77*1d32ba66SJohn Wren Kennedylog_mustnot eval "runat $TESTDIR/cpio.$$ cat passwd > /dev/null 2>&1" 78f38cb554SJohn Wren Kennedy 79f38cb554SJohn Wren Kennedy# we should have an xattr here 80*1d32ba66SJohn Wren Kennedylog_must cpio -iu@ < /tmp/xattr.$$.cpio 81*1d32ba66SJohn Wren Kennedylog_must eval "runat $TESTDIR/cpio.$$ cat passwd > /dev/null 2>&1" 82f38cb554SJohn Wren Kennedy 83f38cb554SJohn Wren Kennedy# we should have no xattr here 84*1d32ba66SJohn Wren Kennedylog_must cpio -iu < /tmp/noxattr.$$.cpio 85*1d32ba66SJohn Wren Kennedylog_mustnot eval "runat $TESTDIR/cpio.$$ cat passwd > /dev/null 2>&1" 86f38cb554SJohn Wren Kennedy 87f38cb554SJohn Wren Kennedy# we should have no xattr here 88*1d32ba66SJohn Wren Kennedylog_must cpio -iu@ < /tmp/noxattr.$$.cpio 89*1d32ba66SJohn Wren Kennedylog_mustnot eval "runat $TESTDIR/cpio.$$ cat passwd > /dev/null 2>&1" 90*1d32ba66SJohn Wren Kennedylog_must rm $TESTDIR/cpio.$$ /tmp/xattr.$$.cpio /tmp/noxattr.$$.cpio 91f38cb554SJohn Wren Kennedy 92f38cb554SJohn Wren Kennedy 93f38cb554SJohn Wren Kennedy 94f38cb554SJohn Wren Kennedylog_note "Checking cp" 95f38cb554SJohn Wren Kennedy# check that with the right flag, the xattr is preserved 96*1d32ba66SJohn Wren Kennedylog_must cp -@ $TESTDIR/myfile.$$ $TESTDIR/myfile2.$$ 97f38cb554SJohn Wren Kennedycompare_xattrs $TESTDIR/myfile.$$ $TESTDIR/myfile2.$$ passwd 98*1d32ba66SJohn Wren Kennedylog_must rm $TESTDIR/myfile2.$$ 99f38cb554SJohn Wren Kennedy 100f38cb554SJohn Wren Kennedy# without the right flag, there should be no xattr 101*1d32ba66SJohn Wren Kennedylog_must cp $TESTDIR/myfile.$$ $TESTDIR/myfile2.$$ 102*1d32ba66SJohn Wren Kennedylog_mustnot eval "runat $TESTDIR/myfile2.$$ ls passwd > /dev/null 2>&1" 103*1d32ba66SJohn Wren Kennedylog_must rm $TESTDIR/myfile2.$$ 104f38cb554SJohn Wren Kennedy 105f38cb554SJohn Wren Kennedy 106f38cb554SJohn Wren Kennedy 107f38cb554SJohn Wren Kennedylog_note "Checking find" 108f38cb554SJohn Wren Kennedy# create a file without xattrs, and check that find -xattr only finds 109f38cb554SJohn Wren Kennedy# our test file that has an xattr. 110*1d32ba66SJohn Wren Kennedylog_must mkdir $TESTDIR/noxattrs 111*1d32ba66SJohn Wren Kennedylog_must touch $TESTDIR/noxattrs/no-xattr 112f38cb554SJohn Wren Kennedy 113*1d32ba66SJohn Wren Kennedyfind $TESTDIR -xattr | grep myfile.$$ 114f38cb554SJohn Wren Kennedy[[ $? -ne 0 ]] && \ 115f38cb554SJohn Wren Kennedy log_fail "find -xattr didn't find our file that had an xattr." 116*1d32ba66SJohn Wren Kennedyfind $TESTDIR -xattr | grep no-xattr 117f38cb554SJohn Wren Kennedy[[ $? -eq 0 ]] && \ 118f38cb554SJohn Wren Kennedy log_fail "find -xattr found a file that didn't have an xattr." 119*1d32ba66SJohn Wren Kennedylog_must rm -rf $TESTDIR/noxattrs 120f38cb554SJohn Wren Kennedy 121f38cb554SJohn Wren Kennedy 122f38cb554SJohn Wren Kennedy 123f38cb554SJohn Wren Kennedylog_note "Checking mv" 124f38cb554SJohn Wren Kennedy# mv doesn't have any flags to preserve/ommit xattrs - they're 125f38cb554SJohn Wren Kennedy# always moved. 126*1d32ba66SJohn Wren Kennedylog_must touch $TESTDIR/mvfile.$$ 127f38cb554SJohn Wren Kennedycreate_xattr $TESTDIR/mvfile.$$ passwd /etc/passwd 128*1d32ba66SJohn Wren Kennedylog_must mv $TESTDIR/mvfile.$$ $TESTDIR/mvfile2.$$ 129f38cb554SJohn Wren Kennedyverify_xattr $TESTDIR/mvfile2.$$ passwd /etc/passwd 130*1d32ba66SJohn Wren Kennedylog_must rm $TESTDIR/mvfile2.$$ 131f38cb554SJohn Wren Kennedy 132f38cb554SJohn Wren Kennedy 133f38cb554SJohn Wren Kennedylog_note "Checking pax" 134*1d32ba66SJohn Wren Kennedylog_must touch $TESTDIR/pax.$$ 135f38cb554SJohn Wren Kennedycreate_xattr $TESTDIR/pax.$$ passwd /etc/passwd 136*1d32ba66SJohn Wren Kennedylog_must pax -w -f $TESTDIR/noxattr.pax $TESTDIR/pax.$$ 137*1d32ba66SJohn Wren Kennedylog_must pax -w@ -f $TESTDIR/xattr.pax $TESTDIR/pax.$$ 138*1d32ba66SJohn Wren Kennedylog_must rm $TESTDIR/pax.$$ 139f38cb554SJohn Wren Kennedy 140f38cb554SJohn Wren Kennedy# we should have no xattr here 141*1d32ba66SJohn Wren Kennedylog_must pax -r -f $TESTDIR/noxattr.pax 142*1d32ba66SJohn Wren Kennedylog_mustnot eval "runat $TESTDIR/pax.$$ cat passwd > /dev/null 2>&1" 143*1d32ba66SJohn Wren Kennedylog_must rm $TESTDIR/pax.$$ 144f38cb554SJohn Wren Kennedy 145f38cb554SJohn Wren Kennedy# we should have no xattr here 146*1d32ba66SJohn Wren Kennedylog_must pax -r@ -f $TESTDIR/noxattr.pax 147*1d32ba66SJohn Wren Kennedylog_mustnot eval "runat $TESTDIR/pax.$$ cat passwd > /dev/null 2>&1" 148*1d32ba66SJohn Wren Kennedylog_must rm $TESTDIR/pax.$$ 149f38cb554SJohn Wren Kennedy 150f38cb554SJohn Wren Kennedy 151f38cb554SJohn Wren Kennedy# we should have an xattr here 152*1d32ba66SJohn Wren Kennedylog_must pax -r@ -f $TESTDIR/xattr.pax 153f38cb554SJohn Wren Kennedyverify_xattr $TESTDIR/pax.$$ passwd /etc/passwd 154*1d32ba66SJohn Wren Kennedylog_must rm $TESTDIR/pax.$$ 155f38cb554SJohn Wren Kennedy 156f38cb554SJohn Wren Kennedy# we should have no xattr here 157*1d32ba66SJohn Wren Kennedylog_must pax -r -f $TESTDIR/xattr.pax $TESTDIR 158*1d32ba66SJohn Wren Kennedylog_mustnot eval "runat $TESTDIR/pax.$$ cat passwd > /dev/null 2>&1" 159*1d32ba66SJohn Wren Kennedylog_must rm $TESTDIR/pax.$$ $TESTDIR/noxattr.pax $TESTDIR/xattr.pax 160f38cb554SJohn Wren Kennedy 161f38cb554SJohn Wren Kennedy 162f38cb554SJohn Wren Kennedylog_note "Checking tar" 163*1d32ba66SJohn Wren Kennedylog_must touch $TESTDIR/tar.$$ 164f38cb554SJohn Wren Kennedycreate_xattr $TESTDIR/tar.$$ passwd /etc/passwd 165f38cb554SJohn Wren Kennedy 166f38cb554SJohn Wren Kennedylog_must cd $TESTDIR 167f38cb554SJohn Wren Kennedy 168*1d32ba66SJohn Wren Kennedylog_must tar cf noxattr.tar tar.$$ 169*1d32ba66SJohn Wren Kennedylog_must tar c@f xattr.tar tar.$$ 170*1d32ba66SJohn Wren Kennedylog_must rm $TESTDIR/tar.$$ 171f38cb554SJohn Wren Kennedy 172f38cb554SJohn Wren Kennedy# we should have no xattr here 173*1d32ba66SJohn Wren Kennedylog_must tar xf xattr.tar 174*1d32ba66SJohn Wren Kennedylog_mustnot eval "runat $TESTDIR/tar.$$ cat passwd > /dev/null 2>&1" 175*1d32ba66SJohn Wren Kennedylog_must rm $TESTDIR/tar.$$ 176f38cb554SJohn Wren Kennedy 177f38cb554SJohn Wren Kennedy# we should have an xattr here 178*1d32ba66SJohn Wren Kennedylog_must tar x@f xattr.tar 179f38cb554SJohn Wren Kennedyverify_xattr tar.$$ passwd /etc/passwd 180*1d32ba66SJohn Wren Kennedylog_must rm $TESTDIR/tar.$$ 181f38cb554SJohn Wren Kennedy 182f38cb554SJohn Wren Kennedy# we should have no xattr here 183*1d32ba66SJohn Wren Kennedylog_must tar xf $TESTDIR/noxattr.tar 184*1d32ba66SJohn Wren Kennedylog_mustnot eval "runat $TESTDIR/tar.$$ cat passwd > /dev/null 2>&1" 185*1d32ba66SJohn Wren Kennedylog_must rm $TESTDIR/tar.$$ 186f38cb554SJohn Wren Kennedy 187f38cb554SJohn Wren Kennedy# we should have no xattr here 188*1d32ba66SJohn Wren Kennedylog_must tar x@f $TESTDIR/noxattr.tar 189*1d32ba66SJohn Wren Kennedylog_mustnot eval "runat $TESTDIR/tar.$$ cat passwd > /dev/null 2>&1" 190*1d32ba66SJohn Wren Kennedylog_must rm $TESTDIR/tar.$$ $TESTDIR/noxattr.tar $TESTDIR/xattr.tar 191f38cb554SJohn Wren Kennedy 192f38cb554SJohn Wren Kennedy 193f38cb554SJohn Wren Kennedylog_assert "Basic applications work with xattrs: cpio cp find mv pax tar" 194