12fae26bdSAlan Somers#!/usr/local/bin/ksh93 -p
22fae26bdSAlan Somers#
32fae26bdSAlan Somers# CDDL HEADER START
42fae26bdSAlan Somers#
52fae26bdSAlan Somers# The contents of this file are subject to the terms of the
62fae26bdSAlan Somers# Common Development and Distribution License (the "License").
72fae26bdSAlan Somers# You may not use this file except in compliance with the License.
82fae26bdSAlan Somers#
92fae26bdSAlan Somers# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
102fae26bdSAlan Somers# or http://www.opensolaris.org/os/licensing.
112fae26bdSAlan Somers# See the License for the specific language governing permissions
122fae26bdSAlan Somers# and limitations under the License.
132fae26bdSAlan Somers#
142fae26bdSAlan Somers# When distributing Covered Code, include this CDDL HEADER in each
152fae26bdSAlan Somers# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
162fae26bdSAlan Somers# If applicable, add the following below this CDDL HEADER, with the
172fae26bdSAlan Somers# fields enclosed by brackets "[]" replaced with your own identifying
182fae26bdSAlan Somers# information: Portions Copyright [yyyy] [name of copyright owner]
192fae26bdSAlan Somers#
202fae26bdSAlan Somers# CDDL HEADER END
212fae26bdSAlan Somers#
222fae26bdSAlan Somers
232fae26bdSAlan Somers#
242fae26bdSAlan Somers# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
252fae26bdSAlan Somers# Use is subject to license terms.
262fae26bdSAlan Somers. $STF_SUITE/tests/acl/acl_common.kshlib
272fae26bdSAlan Somers
282fae26bdSAlan Somers################################################################################
292fae26bdSAlan Somers#
302fae26bdSAlan Somers# __stc_assertion_start
312fae26bdSAlan Somers#
322fae26bdSAlan Somers# ID: zfs_acl_mv_001_pos
332fae26bdSAlan Somers#
342fae26bdSAlan Somers# DESCRIPTION:
352fae26bdSAlan Somers# Verify that '/bin/mv' supports ZFS ACL
362fae26bdSAlan Somers#
372fae26bdSAlan Somers# STRATEGY:
382fae26bdSAlan Somers# 1. Create file and  directory in zfs filesystem
392fae26bdSAlan Somers# 2. Set special ACE to the file and directory
402fae26bdSAlan Somers# 3. Copy the file/directory within and across zfs file system
412fae26bdSAlan Somers# 4. Verify that the ACL of file/directroy is not changed
422fae26bdSAlan Somers#
432fae26bdSAlan Somers# TESTABILITY: explicit
442fae26bdSAlan Somers#
452fae26bdSAlan Somers# TEST_AUTOMATION_LEVEL: automated
462fae26bdSAlan Somers#
472fae26bdSAlan Somers# CODING_STATUS: COMPLETED (2005-10-11)
482fae26bdSAlan Somers#
492fae26bdSAlan Somers# __stc_assertion_end
502fae26bdSAlan Somers#
512fae26bdSAlan Somers################################################################################
522fae26bdSAlan Somers
532fae26bdSAlan Somersverify_runnable "both"
542fae26bdSAlan Somers
552fae26bdSAlan Somersfunction cleanup
562fae26bdSAlan Somers{
572fae26bdSAlan Somers	(( ${#cwd} != 0 )) && cd $cwd
582fae26bdSAlan Somers	[[ -d $TESTDIR ]] && log_must $RM -rf $TESTDIR/*
592fae26bdSAlan Somers	[[ -d $TESTDIR1 ]] && log_must $RM -rf $TESTDIR1
602fae26bdSAlan Somers	(( ${#mask} != 0 )) && log_must $UMASK $mask
612fae26bdSAlan Somers}
622fae26bdSAlan Somers
632fae26bdSAlan Somersfunction testing_mv #<flag for file|dir> <file1|dir1> <file2|dir2>
642fae26bdSAlan Somers{
652fae26bdSAlan Somers	typeset flag=$1
662fae26bdSAlan Somers	set -A obj $2 $3
672fae26bdSAlan Somers	typeset -i i=0
682fae26bdSAlan Somers	typeset orig_acl=""
692fae26bdSAlan Somers	typeset orig_mode=""
702fae26bdSAlan Somers	typeset dst_acl=""
712fae26bdSAlan Somers	typeset dst_mode=""
722fae26bdSAlan Somers
732fae26bdSAlan Somers	if [[ $flag == "f" ]]; then
742fae26bdSAlan Somers	while (( i < ${#obj[*]} ))
752fae26bdSAlan Somers	do
762fae26bdSAlan Somers		orig_acl="$(get_acl ${obj[i]})"
772fae26bdSAlan Somers		orig_mode="$(get_mode ${obj[i]})"
782fae26bdSAlan Somers		if (( i < 1 )); then
792fae26bdSAlan Somers			log_must $MV ${obj[i]} $dst_file
802fae26bdSAlan Somers			dst_acl=$(get_acl $dst_file)
812fae26bdSAlan Somers			dst_mode=$(get_mode $dst_file)
822fae26bdSAlan Somers		else
832fae26bdSAlan Somers			log_must $MV ${obj[i]} $TESTDIR1
842fae26bdSAlan Somers			dst_acl=$(get_acl $TESTDIR1/${obj[i]})
852fae26bdSAlan Somers			dst_mode=$(get_mode $TESTDIR1/${obj[i]})
862fae26bdSAlan Somers		fi
872fae26bdSAlan Somers
882fae26bdSAlan Somers		if [[ "$dst_mode" != "$orig_mode" ]] || \
892fae26bdSAlan Somers			[[ "$dst_acl" != "$orig_acl" ]]; then
902fae26bdSAlan Somers			log_fail "$MV fails to keep the acl for file."
912fae26bdSAlan Somers		fi
922fae26bdSAlan Somers
932fae26bdSAlan Somers		(( i = i + 1 ))
942fae26bdSAlan Somers	done
952fae26bdSAlan Somers	else
962fae26bdSAlan Somers	while (( i < ${#obj[*]} ))
972fae26bdSAlan Somers	do
982fae26bdSAlan Somers		typeset orig_nested_acl=""
992fae26bdSAlan Somers		typeset orig_nested_mode=""
1002fae26bdSAlan Somers		typeset dst_nested_acl=""
1012fae26bdSAlan Somers		typeset dst_nested_mode=""
1022fae26bdSAlan Somers
1032fae26bdSAlan Somers		orig_acl=$(get_acl ${obj[i]})
1042fae26bdSAlan Somers		orig_mode=$(get_mode ${obj[i]})
1052fae26bdSAlan Somers		orig_nested_acl=$(get_acl ${obj[i]}/$nestedfile)
1062fae26bdSAlan Somers		orig_nested_mode=$(get_mode ${obj[i]}/$nestedfile)
1072fae26bdSAlan Somers		if (( i < 1 )); then
1082fae26bdSAlan Somers			log_must $MV ${obj[i]} $dst_dir
1092fae26bdSAlan Somers			dst_acl=$(get_acl $dst_dir)
1102fae26bdSAlan Somers			dst_mode=$(get_mode $dst_dir)
1112fae26bdSAlan Somers			dst_nested_acl=$(get_acl $dst_dir/$nestedfile)
1122fae26bdSAlan Somers			dst_nested_mode=$(get_mode $dst_dir/$nestedfile)
1132fae26bdSAlan Somers		else
1142fae26bdSAlan Somers			log_must $MV ${obj[i]} $TESTDIR1
1152fae26bdSAlan Somers			dst_acl=$(get_acl $TESTDIR1/${obj[i]})
1162fae26bdSAlan Somers			dst_mode=$(get_mode $TESTDIR1/${obj[i]})
1172fae26bdSAlan Somers			dst_nested_acl=$(get_acl \
1182fae26bdSAlan Somers				$TESTDIR1/${obj[i]}/$nestedfile)
1192fae26bdSAlan Somers			dst_nested_mode=$(get_mode \
1202fae26bdSAlan Somers				$TESTDIR1/${obj[i]}/$nestedfile)
1212fae26bdSAlan Somers		fi
1222fae26bdSAlan Somers
1232fae26bdSAlan Somers		if [[ "$orig_mode" != "$dst_mode" ]] || \
1242fae26bdSAlan Somers		   [[ "$orig_acl" != "$dst_acl" ]] || \
1252fae26bdSAlan Somers		   [[ "$dst_nested_mode" != "$orig_nested_mode" ]] || \
1262fae26bdSAlan Somers		   [[ "$dst_nested_acl" != "$orig_nested_acl" ]]; then
1272fae26bdSAlan Somers			log_fail "$MV fails to recursively keep the acl for " \
1282fae26bdSAlan Somers				"directory."
1292fae26bdSAlan Somers		fi
1302fae26bdSAlan Somers
1312fae26bdSAlan Somers		(( i = i + 1 ))
1322fae26bdSAlan Somers	done
1332fae26bdSAlan Somers	fi
1342fae26bdSAlan Somers}
1352fae26bdSAlan Somers
1362fae26bdSAlan Somerslog_assert "Verify that '$MV' supports ZFS ACLs."
1372fae26bdSAlan Somerslog_onexit cleanup
1382fae26bdSAlan Somers
1392fae26bdSAlan Somerstest_requires ZFS_ACL
1402fae26bdSAlan Somers
1412fae26bdSAlan Somersspec_ace="everyone@:execute:allow"
1422fae26bdSAlan Somersset -A orig_file "origfile1.${TESTCASE_ID}" "origfile2.${TESTCASE_ID}"
1432fae26bdSAlan Somersset -A orig_dir "origdir1.${TESTCASE_ID}" "origdir2.${TESTCASE_ID}"
1442fae26bdSAlan Somersnestedfile="nestedfile.${TESTCASE_ID}"
1452fae26bdSAlan Somersdst_file=dstfile.${TESTCASE_ID}
1462fae26bdSAlan Somersdst_dir=dstdir.${TESTCASE_ID}
1472fae26bdSAlan Somerscwd=$PWD
1482fae26bdSAlan Somersmask=`$UMASK`
1492fae26bdSAlan Somers$UMASK 0022
1502fae26bdSAlan Somers
1512fae26bdSAlan Somers#
1522fae26bdSAlan Somers# This assertion should only test 'mv' within the same filesystem
1532fae26bdSAlan Somers#
1542fae26bdSAlan SomersTESTDIR1=$TESTDIR/testdir1${TESTCASE_ID}
1552fae26bdSAlan Somers
1562fae26bdSAlan Somers[[ ! -d $TESTDIR1 ]] && \
1572fae26bdSAlan Somers	log_must $MKDIR -p $TESTDIR1
1582fae26bdSAlan Somers
1592fae26bdSAlan Somerslog_note "Create files and directories and set special ace on them for testing. "
1602fae26bdSAlan Somerscd $TESTDIR
1612fae26bdSAlan Somerstypeset -i i=0
1622fae26bdSAlan Somerswhile (( i < ${#orig_file[*]} ))
1632fae26bdSAlan Somersdo
1642fae26bdSAlan Somers	log_must $TOUCH ${orig_file[i]}
1652fae26bdSAlan Somers	log_must $CHMOD A0+$spec_ace ${orig_file[i]}
1662fae26bdSAlan Somers
1672fae26bdSAlan Somers	(( i = i + 1 ))
1682fae26bdSAlan Somersdone
1692fae26bdSAlan Somersi=0
1702fae26bdSAlan Somerswhile (( i < ${#orig_dir[*]} ))
1712fae26bdSAlan Somersdo
1722fae26bdSAlan Somers	log_must $MKDIR ${orig_dir[i]}
1732fae26bdSAlan Somers	log_must $TOUCH ${orig_dir[i]}/$nestedfile
1742fae26bdSAlan Somers
1752fae26bdSAlan Somers	for obj in ${orig_dir[i]} ${orig_dir[i]}/$nestedfile; do
1762fae26bdSAlan Somers		log_must $CHMOD A0+$spec_ace $obj
1772fae26bdSAlan Somers	done
1782fae26bdSAlan Somers
1792fae26bdSAlan Somers	(( i = i + 1 ))
1802fae26bdSAlan Somersdone
1812fae26bdSAlan Somers
1822fae26bdSAlan Somerstesting_mv "f" ${orig_file[0]} ${orig_file[1]}
1832fae26bdSAlan Somerstesting_mv "d" ${orig_dir[0]} ${orig_dir[1]}
1842fae26bdSAlan Somers
1852fae26bdSAlan Somerslog_pass "'$MV' succeeds to support ZFS ACLs."
186