f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# CDDL HEADER START
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# The contents of this file are subject to the terms of the
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Common Development and Distribution License (the "License").
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# You may not use this file except in compliance with the License.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# or http://www.opensolaris.org/os/licensing.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# See the License for the specific language governing permissions
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# and limitations under the License.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# When distributing Covered Code, include this CDDL HEADER in each
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# If applicable, add the following below this CDDL HEADER, with the
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# fields enclosed by brackets "[]" replaced with your own identifying
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# information: Portions Copyright [yyyy] [name of copyright owner]
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# CDDL HEADER END
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Use is subject to license terms.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy. $STF_SUITE/include/libtest.shlib
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# a function that takes a file, then creates and verifies
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# an xattr on that file. The xattr_contents is the file
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# that should appear in the xattr namespace.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfunction create_xattr { # filename xattr_name xattr_contents
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset FILE=$1
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset XATTR_NAME=$2
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset XATTR_CONTENTS=$3
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy # read any empty xattr on that file
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must runat $FILE ls
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy # create the xattr
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must runat $FILE cp $XATTR_CONTENTS $XATTR_NAME
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy verify_xattr $FILE $XATTR_NAME $XATTR_CONTENTS
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy}
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# a function that compares the a single xattr between two files
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# and checks to see if their contents are identical
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfunction compare_xattrs { # filename1 filename2 xattr_name
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset FILE1=$1
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset FILE2=$2
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset XATTR_NAME=$3
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy runat $FILE1 cat $XATTR_NAME > /tmp/file1.$$
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy runat $FILE2 cat $XATTR_NAME > /tmp/file2.$$
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must diff /tmp/file1.$$ /tmp/file2.$$
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must rm /tmp/file1.$$ /tmp/file2.$$
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy}
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfunction verify_xattr { # filename xattr_name xattr_contents
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset FILE=$1
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset XATTR_NAME=$2
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset XATTR_CONTENTS=$3
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy # read the xattr, writing it to a temp file
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must eval "runat $FILE cat $XATTR_NAME > /tmp/$XATTR_NAME.$$ 2>&1"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must diff $XATTR_CONTENTS /tmp/$XATTR_NAME.$$
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy rm /tmp/$XATTR_NAME.$$
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy}
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfunction delete_xattr { # filename xattr_name
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset FILE=$1
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset XATTR_NAME=$2
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy # delete the xattr
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must runat $FILE rm $XATTR_NAME
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_mustnot eval "runat $FILE ls $XATTR_NAME > /dev/null 2>&1"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy}
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# not sure about this : really this should be testing write/append
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfunction verify_write_xattr { # filename xattr_name
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset FILE=$1
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset XATTR_NAME=$2
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must eval "runat $FILE dd if=/etc/passwd of=$XATTR_NAME"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must eval "runat $FILE cat $XATTR_NAME > /tmp/$XATTR_NAME.$$ 2>&1"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must dd if=/etc/passwd of=/tmp/passwd_dd.$$
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must diff /tmp/passwd_dd.$$ /tmp/$XATTR_NAME.$$
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must rm /tmp/passwd_dd.$$ /tmp/$XATTR_NAME.$$
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy}
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# this function is to create the expected output
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfunction create_expected_output { # expected_output_file contents_of_the_output
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset FILE=$1
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy shift
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy if [[ -f $FILE ]]; then
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must rm $FILE
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy fi
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy for line in $@
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy do
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must eval "echo $line >> $FILE"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy done
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy }