1#!/bin/ksh -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
28#
29# Copyright (c) 2012, 2016 by Delphix. All rights reserved.
30#
31
32. $STF_SUITE/tests/functional/acl/acl_common.kshlib
33
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
46verify_runnable "both"
47
48function cleanup
49{
50	[[ -d $TESTDIR ]] && rm -rf $TESTDIR/*
51	(( ${#cmd} != 0 )) && cd $cwd
52	(( ${#mask} != 0 )) && umask $mask
53}
54
55function find_ls_acl #<opt> <obj>
56{
57	typeset opt=$1 # -ls or -acl
58	typeset obj=$2
59	typeset rst_str=""
60
61	if [[ $opt == "ls" ]]; then
62		rst_str=`find . -ls | grep "+" | awk '{print $11}'`
63	else
64		rst_str=`find . -acl`
65	fi
66
67	if [[ $rst_str == "./$obj" ]]; then
68		return 0
69	else
70		return 1
71	fi
72}
73
74log_assert "Verify that 'find' command supports ZFS ACLs."
75
76log_onexit cleanup
77
78set -A ops " A+user:$ZFS_ACL_STAFF1:read_data:allow" \
79	" A+user:$ZFS_ACL_STAFF1:write_data:allow"
80
81f_base=testfile.$$ # Base file name for tested files
82d_base=testdir.$$ # Base directory name for tested directory
83cwd=$PWD
84mask=`umask`
85
86log_note "Create five files and directories in the zfs filesystem. "
87cd $TESTDIR
88umask 0777
89typeset -i i=0
90while ((i < 5))
91do
92	log_must touch ${f_base}.$i
93	log_must mkdir ${d_base}.$i
94
95	((i = i + 1))
96done
97
98for obj in ${f_base}.3 ${d_base}.3
99do
100	i=0
101	while ((i < ${#ops[*]}))
102	do
103		log_must chmod ${ops[i]} $obj
104
105		((i = i + 1))
106	done
107
108	for opt in "ls" "acl"
109	do
110		log_must find_ls_acl $opt $obj
111	done
112
113	log_note "Check the file access permission according to the added ACEs"
114	if [[ ! -r $obj || ! -w $obj ]]; then
115		log_fail "The added ACEs for $obj cannot be represented in " \
116			"mode."
117	fi
118
119	log_note "Remove the added ACEs from ACL."
120	i=0
121	while ((i < ${#ops[*]}))
122	do
123		log_must chmod A0- $obj
124
125		((i = i + 1))
126	done
127done
128
129log_pass "'find' command succeeds to support ZFS ACLs."
130