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