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. Delete all the attribute files.
42#	2. Verify all the specified files can not be found with '-xattr',
43#	3. Verify all the attribute files can not be found with '-exec runat ls'
44#
45
46verify_runnable "both"
47
48log_assert "verifies -xattr doesn't include files without " \
49		"attribute and using '-exec runat ls'"
50log_onexit cleanup
51
52for user in root $ZFS_ACL_STAFF1; do
53	log_must set_cur_usr $user
54
55	log_must create_files $TESTDIR
56
57	initfiles=$(ls -R $INI_DIR/*)
58	typeset -i i=0
59	while (( i < NUM_FILE )); do
60		f=$(getitem $i $initfiles)
61		usr_exec runat $f rm attribute*
62		(( i += 1 ))
63	done
64
65	i=0
66	while (( i < NUM_FILE )); do
67		f=$(getitem $i $initfiles)
68		ff=$(usr_exec find $INI_DIR -type f -name ${f##*/} \
69			-xattr -print)
70		if [[ $ff == $f ]]; then
71			log_fail "find not containing attribute should fail."
72		fi
73
74		typeset -i j=0
75		while (( j < NUM_ATTR )); do
76			fa=$(usr_exec find $INI_DIR -type f -name ${f##*/} \
77				-xattr -exec runat {} ls attribute.$j \\\;)
78			if [[ $fa == attribute.$j ]]; then
79				log_fail "find file attribute should fail."
80			fi
81			(( j += 1 ))
82		done
83		log_note "Failed to find $f and its attribute file as expected."
84
85		(( i += 1 ))
86	done
87
88	log_must cleanup
89done
90
91log_pass "find files which have no attrabute files with -xattr passed."
92