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#
24# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27# ident	"@(#)zfs_acl_find_001_pos.ksh	1.2	07/01/09 SMI"
28#
29
30. $STF_SUITE/tests/acl/acl_common.kshlib
31
32################################################################################
33#
34# __stc_assertion_start
35#
36# ID: zfs_acl_find_001_pos
37#
38# DESCRIPTION:
39# Verify that '$FIND' command with '-ls' and '-acl' options supports ZFS ACL
40#
41# STRATEGY:
42# 1. Create 5 files and 5 directories in zfs filesystem
43# 2. Select a file or directory and add a few ACEs to it
44# 3. Use $FIND -ls to check the "+" existen only with the selected file or
45#    directory
46# 4. Use $FIND -acl to check only the selected file/directory in the list
47#
48# TESTABILITY: explicit
49#
50# TEST_AUTOMATION_LEVEL: automated
51#
52# CODING_STATUS: COMPLETED (2005-09-26)
53#
54# __stc_assertion_end
55#
56################################################################################
57
58verify_runnable "both"
59
60function cleanup
61{
62	[[ -d $TESTDIR ]] && $RM -rf $TESTDIR/*
63	(( ${#cwd} != 0 )) && cd $cwd
64	(( ${#mask} != 0 )) && $UMASK $mask
65}
66
67function find_ls_acl #<opt> <obj>
68{
69	typeset opt=$1 # -ls or -acl
70	typeset obj=$2
71	typeset rst_str=""
72
73	if [[ $opt == "ls" ]]; then
74		rst_str=`$FIND . -ls | $GREP "+" | $AWK '{print $11}'`
75	else
76		rst_str=`$FIND . -acl`
77	fi
78
79	if [[ $rst_str == "./$obj" ]]; then
80		return 0
81	else
82		return 1
83	fi
84}
85
86log_assert "Verify that '$FIND' command supports ZFS ACLs."
87log_onexit cleanup
88
89test_requires ZFS_ACL
90
91set -A ops " A+everyone@:read_data:allow" \
92	" A+owner@:write_data:allow"
93
94f_base=testfile.${TESTCASE_ID} # Base file name for tested files
95d_base=testdir.${TESTCASE_ID} # Base directory name for tested directory
96cwd=$PWD
97mask=`$UMASK`
98
99log_note "Create five files and directories in the zfs filesystem. "
100cd $TESTDIR
101$UMASK 0777
102typeset -i i=0
103while (( i < 5 ))
104do
105	log_must $TOUCH ${f_base}.$i
106	log_must $MKDIR ${d_base}.$i
107
108	(( i = i + 1 ))
109done
110
111for obj in ${f_base}.3 ${d_base}.3
112do
113	i=0
114	while (( i < ${#ops[*]} ))
115	do
116		log_must $CHMOD ${ops[i]} $obj
117
118		(( i = i + 1 ))
119	done
120
121	for opt in "ls" "acl"
122	do
123		log_must find_ls_acl $opt $obj
124	done
125
126	log_note "Check the file access permission according to the added ACEs"
127	if [[ ! -r $obj || ! -w $obj ]]; then
128		log_fail "The added ACEs for $obj cannot be represented in " \
129			"mode."
130	fi
131
132	log_note "Remove the added ACEs from ACL."
133	i=0
134	while (( i < ${#ops[*]} ))
135	do
136		log_must $CHMOD A0- $obj
137
138		(( i = i + 1 ))
139	done
140done
141
142log_pass "'$FIND' command succeeds to support ZFS ACLs."
143