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# $FreeBSD$
242fae26bdSAlan Somers
252fae26bdSAlan Somers#
262fae26bdSAlan Somers# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
272fae26bdSAlan Somers# Use is subject to license terms.
282fae26bdSAlan Somers#
292fae26bdSAlan Somers# ident	"@(#)zfs_acl_mv_001_pos.ksh	1.2	07/01/09 SMI"
302fae26bdSAlan Somers#
312fae26bdSAlan Somers. $STF_SUITE/tests/acl/acl_common.kshlib
322fae26bdSAlan Somers
332fae26bdSAlan Somers################################################################################
342fae26bdSAlan Somers#
352fae26bdSAlan Somers# __stc_assertion_start
362fae26bdSAlan Somers#
372fae26bdSAlan Somers# ID: zfs_acl_mv_001_pos
382fae26bdSAlan Somers#
392fae26bdSAlan Somers# DESCRIPTION:
402fae26bdSAlan Somers# Verify that '/bin/mv' supports ZFS ACL
412fae26bdSAlan Somers#
422fae26bdSAlan Somers# STRATEGY:
432fae26bdSAlan Somers# 1. Create file and  directory in zfs filesystem
442fae26bdSAlan Somers# 2. Set special ACE to the file and directory
452fae26bdSAlan Somers# 3. Copy the file/directory within and across zfs file system
462fae26bdSAlan Somers# 4. Verify that the ACL of file/directroy is not changed
472fae26bdSAlan Somers#
482fae26bdSAlan Somers# TESTABILITY: explicit
492fae26bdSAlan Somers#
502fae26bdSAlan Somers# TEST_AUTOMATION_LEVEL: automated
512fae26bdSAlan Somers#
522fae26bdSAlan Somers# CODING_STATUS: COMPLETED (2005-10-11)
532fae26bdSAlan Somers#
542fae26bdSAlan Somers# __stc_assertion_end
552fae26bdSAlan Somers#
562fae26bdSAlan Somers################################################################################
572fae26bdSAlan Somers
582fae26bdSAlan Somersverify_runnable "both"
592fae26bdSAlan Somers
602fae26bdSAlan Somersfunction cleanup
612fae26bdSAlan Somers{
622fae26bdSAlan Somers	(( ${#cwd} != 0 )) && cd $cwd
632fae26bdSAlan Somers	[[ -d $TESTDIR ]] && log_must $RM -rf $TESTDIR/*
642fae26bdSAlan Somers	[[ -d $TESTDIR1 ]] && log_must $RM -rf $TESTDIR1
652fae26bdSAlan Somers	(( ${#mask} != 0 )) && log_must $UMASK $mask
662fae26bdSAlan Somers}
672fae26bdSAlan Somers
682fae26bdSAlan Somersfunction testing_mv #<flag for file|dir> <file1|dir1> <file2|dir2>
692fae26bdSAlan Somers{
702fae26bdSAlan Somers	typeset flag=$1
712fae26bdSAlan Somers	set -A obj $2 $3
722fae26bdSAlan Somers	typeset -i i=0
732fae26bdSAlan Somers	typeset orig_acl=""
742fae26bdSAlan Somers	typeset orig_mode=""
752fae26bdSAlan Somers	typeset dst_acl=""
762fae26bdSAlan Somers	typeset dst_mode=""
772fae26bdSAlan Somers
782fae26bdSAlan Somers	if [[ $flag == "f" ]]; then
792fae26bdSAlan Somers	while (( i < ${#obj[*]} ))
802fae26bdSAlan Somers	do
812fae26bdSAlan Somers		orig_acl="$(get_acl ${obj[i]})"
822fae26bdSAlan Somers		orig_mode="$(get_mode ${obj[i]})"
832fae26bdSAlan Somers		if (( i < 1 )); then
842fae26bdSAlan Somers			log_must $MV ${obj[i]} $dst_file
852fae26bdSAlan Somers			dst_acl=$(get_acl $dst_file)
862fae26bdSAlan Somers			dst_mode=$(get_mode $dst_file)
872fae26bdSAlan Somers		else
882fae26bdSAlan Somers			log_must $MV ${obj[i]} $TESTDIR1
892fae26bdSAlan Somers			dst_acl=$(get_acl $TESTDIR1/${obj[i]})
902fae26bdSAlan Somers			dst_mode=$(get_mode $TESTDIR1/${obj[i]})
912fae26bdSAlan Somers		fi
922fae26bdSAlan Somers
932fae26bdSAlan Somers		if [[ "$dst_mode" != "$orig_mode" ]] || \
942fae26bdSAlan Somers			[[ "$dst_acl" != "$orig_acl" ]]; then
952fae26bdSAlan Somers			log_fail "$MV fails to keep the acl for file."
962fae26bdSAlan Somers		fi
972fae26bdSAlan Somers
982fae26bdSAlan Somers		(( i = i + 1 ))
992fae26bdSAlan Somers	done
1002fae26bdSAlan Somers	else
1012fae26bdSAlan Somers	while (( i < ${#obj[*]} ))
1022fae26bdSAlan Somers	do
1032fae26bdSAlan Somers		typeset orig_nested_acl=""
1042fae26bdSAlan Somers		typeset orig_nested_mode=""
1052fae26bdSAlan Somers		typeset dst_nested_acl=""
1062fae26bdSAlan Somers		typeset dst_nested_mode=""
1072fae26bdSAlan Somers
1082fae26bdSAlan Somers		orig_acl=$(get_acl ${obj[i]})
1092fae26bdSAlan Somers		orig_mode=$(get_mode ${obj[i]})
1102fae26bdSAlan Somers		orig_nested_acl=$(get_acl ${obj[i]}/$nestedfile)
1112fae26bdSAlan Somers		orig_nested_mode=$(get_mode ${obj[i]}/$nestedfile)
1122fae26bdSAlan Somers		if (( i < 1 )); then
1132fae26bdSAlan Somers			log_must $MV ${obj[i]} $dst_dir
1142fae26bdSAlan Somers			dst_acl=$(get_acl $dst_dir)
1152fae26bdSAlan Somers			dst_mode=$(get_mode $dst_dir)
1162fae26bdSAlan Somers			dst_nested_acl=$(get_acl $dst_dir/$nestedfile)
1172fae26bdSAlan Somers			dst_nested_mode=$(get_mode $dst_dir/$nestedfile)
1182fae26bdSAlan Somers		else
1192fae26bdSAlan Somers			log_must $MV ${obj[i]} $TESTDIR1
1202fae26bdSAlan Somers			dst_acl=$(get_acl $TESTDIR1/${obj[i]})
1212fae26bdSAlan Somers			dst_mode=$(get_mode $TESTDIR1/${obj[i]})
1222fae26bdSAlan Somers			dst_nested_acl=$(get_acl \
1232fae26bdSAlan Somers				$TESTDIR1/${obj[i]}/$nestedfile)
1242fae26bdSAlan Somers			dst_nested_mode=$(get_mode \
1252fae26bdSAlan Somers				$TESTDIR1/${obj[i]}/$nestedfile)
1262fae26bdSAlan Somers		fi
1272fae26bdSAlan Somers
1282fae26bdSAlan Somers		if [[ "$orig_mode" != "$dst_mode" ]] || \
1292fae26bdSAlan Somers		   [[ "$orig_acl" != "$dst_acl" ]] || \
1302fae26bdSAlan Somers		   [[ "$dst_nested_mode" != "$orig_nested_mode" ]] || \
1312fae26bdSAlan Somers		   [[ "$dst_nested_acl" != "$orig_nested_acl" ]]; then
1322fae26bdSAlan Somers			log_fail "$MV fails to recursively keep the acl for " \
1332fae26bdSAlan Somers				"directory."
1342fae26bdSAlan Somers		fi
1352fae26bdSAlan Somers
1362fae26bdSAlan Somers		(( i = i + 1 ))
1372fae26bdSAlan Somers	done
1382fae26bdSAlan Somers	fi
1392fae26bdSAlan Somers}
1402fae26bdSAlan Somers
1412fae26bdSAlan Somerslog_assert "Verify that '$MV' supports ZFS ACLs."
1422fae26bdSAlan Somerslog_onexit cleanup
1432fae26bdSAlan Somers
1442fae26bdSAlan Somerstest_requires ZFS_ACL
1452fae26bdSAlan Somers
1462fae26bdSAlan Somersspec_ace="everyone@:execute:allow"
1472fae26bdSAlan Somersset -A orig_file "origfile1.${TESTCASE_ID}" "origfile2.${TESTCASE_ID}"
1482fae26bdSAlan Somersset -A orig_dir "origdir1.${TESTCASE_ID}" "origdir2.${TESTCASE_ID}"
1492fae26bdSAlan Somersnestedfile="nestedfile.${TESTCASE_ID}"
1502fae26bdSAlan Somersdst_file=dstfile.${TESTCASE_ID}
1512fae26bdSAlan Somersdst_dir=dstdir.${TESTCASE_ID}
1522fae26bdSAlan Somerscwd=$PWD
1532fae26bdSAlan Somersmask=`$UMASK`
1542fae26bdSAlan Somers$UMASK 0022
1552fae26bdSAlan Somers
1562fae26bdSAlan Somers#
1572fae26bdSAlan Somers# This assertion should only test 'mv' within the same filesystem
1582fae26bdSAlan Somers#
1592fae26bdSAlan SomersTESTDIR1=$TESTDIR/testdir1${TESTCASE_ID}
1602fae26bdSAlan Somers
1612fae26bdSAlan Somers[[ ! -d $TESTDIR1 ]] && \
1622fae26bdSAlan Somers	log_must $MKDIR -p $TESTDIR1
1632fae26bdSAlan Somers
1642fae26bdSAlan Somerslog_note "Create files and directories and set special ace on them for testing. "
1652fae26bdSAlan Somerscd $TESTDIR
1662fae26bdSAlan Somerstypeset -i i=0
1672fae26bdSAlan Somerswhile (( i < ${#orig_file[*]} ))
1682fae26bdSAlan Somersdo
1692fae26bdSAlan Somers	log_must $TOUCH ${orig_file[i]}
1702fae26bdSAlan Somers	log_must $CHMOD A0+$spec_ace ${orig_file[i]}
1712fae26bdSAlan Somers
1722fae26bdSAlan Somers	(( i = i + 1 ))
1732fae26bdSAlan Somersdone
1742fae26bdSAlan Somersi=0
1752fae26bdSAlan Somerswhile (( i < ${#orig_dir[*]} ))
1762fae26bdSAlan Somersdo
1772fae26bdSAlan Somers	log_must $MKDIR ${orig_dir[i]}
1782fae26bdSAlan Somers	log_must $TOUCH ${orig_dir[i]}/$nestedfile
1792fae26bdSAlan Somers
1802fae26bdSAlan Somers	for obj in ${orig_dir[i]} ${orig_dir[i]}/$nestedfile; do
1812fae26bdSAlan Somers		log_must $CHMOD A0+$spec_ace $obj
1822fae26bdSAlan Somers	done
1832fae26bdSAlan Somers
1842fae26bdSAlan Somers	(( i = i + 1 ))
1852fae26bdSAlan Somersdone
1862fae26bdSAlan Somers
1872fae26bdSAlan Somerstesting_mv "f" ${orig_file[0]} ${orig_file[1]}
1882fae26bdSAlan Somerstesting_mv "d" ${orig_dir[0]} ${orig_dir[1]}
1892fae26bdSAlan Somers
1902fae26bdSAlan Somerslog_pass "'$MV' succeeds to support ZFS ACLs."
191