1#!/usr/local/bin/ksh93 -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
23# $FreeBSD$
24
25#
26# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28#
29# ident	"@(#)zfs_acl_mv_001_pos.ksh	1.2	07/01/09 SMI"
30#
31. $STF_SUITE/tests/acl/acl_common.kshlib
32
33################################################################################
34#
35# __stc_assertion_start
36#
37# ID: zfs_acl_mv_001_pos
38#
39# DESCRIPTION:
40# Verify that '/bin/mv' supports ZFS ACL
41#
42# STRATEGY:
43# 1. Create file and  directory in zfs filesystem
44# 2. Set special ACE to the file and directory
45# 3. Copy the file/directory within and across zfs file system
46# 4. Verify that the ACL of file/directroy is not changed
47#
48# TESTABILITY: explicit
49#
50# TEST_AUTOMATION_LEVEL: automated
51#
52# CODING_STATUS: COMPLETED (2005-10-11)
53#
54# __stc_assertion_end
55#
56################################################################################
57
58verify_runnable "both"
59
60function cleanup
61{
62	(( ${#cwd} != 0 )) && cd $cwd
63	[[ -d $TESTDIR ]] && log_must $RM -rf $TESTDIR/*
64	[[ -d $TESTDIR1 ]] && log_must $RM -rf $TESTDIR1
65	(( ${#mask} != 0 )) && log_must $UMASK $mask
66}
67
68function testing_mv #<flag for file|dir> <file1|dir1> <file2|dir2>
69{
70	typeset flag=$1
71	set -A obj $2 $3
72	typeset -i i=0
73	typeset orig_acl=""
74	typeset orig_mode=""
75	typeset dst_acl=""
76	typeset dst_mode=""
77
78	if [[ $flag == "f" ]]; then
79	while (( i < ${#obj[*]} ))
80	do
81		orig_acl="$(get_acl ${obj[i]})"
82		orig_mode="$(get_mode ${obj[i]})"
83		if (( i < 1 )); then
84			log_must $MV ${obj[i]} $dst_file
85			dst_acl=$(get_acl $dst_file)
86			dst_mode=$(get_mode $dst_file)
87		else
88			log_must $MV ${obj[i]} $TESTDIR1
89			dst_acl=$(get_acl $TESTDIR1/${obj[i]})
90			dst_mode=$(get_mode $TESTDIR1/${obj[i]})
91		fi
92
93		if [[ "$dst_mode" != "$orig_mode" ]] || \
94			[[ "$dst_acl" != "$orig_acl" ]]; then
95			log_fail "$MV fails to keep the acl for file."
96		fi
97
98		(( i = i + 1 ))
99	done
100	else
101	while (( i < ${#obj[*]} ))
102	do
103		typeset orig_nested_acl=""
104		typeset orig_nested_mode=""
105		typeset dst_nested_acl=""
106		typeset dst_nested_mode=""
107
108		orig_acl=$(get_acl ${obj[i]})
109		orig_mode=$(get_mode ${obj[i]})
110		orig_nested_acl=$(get_acl ${obj[i]}/$nestedfile)
111		orig_nested_mode=$(get_mode ${obj[i]}/$nestedfile)
112		if (( i < 1 )); then
113			log_must $MV ${obj[i]} $dst_dir
114			dst_acl=$(get_acl $dst_dir)
115			dst_mode=$(get_mode $dst_dir)
116			dst_nested_acl=$(get_acl $dst_dir/$nestedfile)
117			dst_nested_mode=$(get_mode $dst_dir/$nestedfile)
118		else
119			log_must $MV ${obj[i]} $TESTDIR1
120			dst_acl=$(get_acl $TESTDIR1/${obj[i]})
121			dst_mode=$(get_mode $TESTDIR1/${obj[i]})
122			dst_nested_acl=$(get_acl \
123				$TESTDIR1/${obj[i]}/$nestedfile)
124			dst_nested_mode=$(get_mode \
125				$TESTDIR1/${obj[i]}/$nestedfile)
126		fi
127
128		if [[ "$orig_mode" != "$dst_mode" ]] || \
129		   [[ "$orig_acl" != "$dst_acl" ]] || \
130		   [[ "$dst_nested_mode" != "$orig_nested_mode" ]] || \
131		   [[ "$dst_nested_acl" != "$orig_nested_acl" ]]; then
132			log_fail "$MV fails to recursively keep the acl for " \
133				"directory."
134		fi
135
136		(( i = i + 1 ))
137	done
138	fi
139}
140
141log_assert "Verify that '$MV' supports ZFS ACLs."
142log_onexit cleanup
143
144test_requires ZFS_ACL
145
146spec_ace="everyone@:execute:allow"
147set -A orig_file "origfile1.${TESTCASE_ID}" "origfile2.${TESTCASE_ID}"
148set -A orig_dir "origdir1.${TESTCASE_ID}" "origdir2.${TESTCASE_ID}"
149nestedfile="nestedfile.${TESTCASE_ID}"
150dst_file=dstfile.${TESTCASE_ID}
151dst_dir=dstdir.${TESTCASE_ID}
152cwd=$PWD
153mask=`$UMASK`
154$UMASK 0022
155
156#
157# This assertion should only test 'mv' within the same filesystem
158#
159TESTDIR1=$TESTDIR/testdir1${TESTCASE_ID}
160
161[[ ! -d $TESTDIR1 ]] && \
162	log_must $MKDIR -p $TESTDIR1
163
164log_note "Create files and directories and set special ace on them for testing. "
165cd $TESTDIR
166typeset -i i=0
167while (( i < ${#orig_file[*]} ))
168do
169	log_must $TOUCH ${orig_file[i]}
170	log_must $CHMOD A0+$spec_ace ${orig_file[i]}
171
172	(( i = i + 1 ))
173done
174i=0
175while (( i < ${#orig_dir[*]} ))
176do
177	log_must $MKDIR ${orig_dir[i]}
178	log_must $TOUCH ${orig_dir[i]}/$nestedfile
179
180	for obj in ${orig_dir[i]} ${orig_dir[i]}/$nestedfile; do
181		log_must $CHMOD A0+$spec_ace $obj
182	done
183
184	(( i = i + 1 ))
185done
186
187testing_mv "f" ${orig_file[0]} ${orig_file[1]}
188testing_mv "d" ${orig_dir[0]} ${orig_dir[1]}
189
190log_pass "'$MV' succeeds to support ZFS ACLs."
191