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) 2016 by Delphix. All rights reserved.
30#
31
32. $STF_SUITE/tests/functional/acl/acl_common.kshlib
33
34#
35# DESCRIPTION:
36#	Verifies ability to find files with attribute with -xattr flag and using
37#	"-exec runat ls".
38#
39# STRATEGY:
40#	1. In directory A, create several files and add attribute files for them
41#	2. Verify all the specified files can be found with '-xattr',
42#	3. Verify all the attribute files can be found with '-exec runat ls'
43#
44
45verify_runnable "both"
46
47log_assert "Verifies ability to find files with attribute with" \
48		"-xattr flag and using '-exec runat ls'"
49log_onexit cleanup
50
51for user in root $ZFS_ACL_STAFF1; do
52	log_must set_cur_usr $user
53
54	log_must create_files $TESTDIR
55	initfiles=$(ls -R $INI_DIR/*)
56
57	typeset -i i=0
58	while (( i < NUM_FILE )); do
59		f=$(getitem $i $initfiles)
60		ff=$(usr_exec find $INI_DIR -type f -name ${f##*/} \
61			-xattr -print)
62		if [[ $ff != $f ]]; then
63			log_fail "find file containing attribute fail."
64		else
65			log_note "find $f by '-xattr'."
66		fi
67
68		typeset -i j=0
69		while (( j < NUM_ATTR )); do
70			typeset af=attribute.$j
71			fa=$(usr_exec find $INI_DIR -type f -name ${f##*/} \
72				-xattr -exec runat {} ls $af \\\;)
73			if [[ $fa != $af ]]; then
74				log_fail "find file attribute fail"
75			fi
76			(( j += 1 ))
77		done
78		(( i += 1 ))
79		log_note "find all attribute files of $f"
80	done
81
82	log_must cleanup
83done
84
85log_pass "find files with -xattr passed."
86