1f3a525d9SJohn Levon#!/bin/ksh
2f3a525d9SJohn Levon#
3f3a525d9SJohn Levon# This file and its contents are supplied under the terms of the
4f3a525d9SJohn Levon# Common Development and Distribution License ("CDDL"), version 1.0.
5f3a525d9SJohn Levon# You may only use this file in accordance with the terms of version
6f3a525d9SJohn Levon# 1.0 of the CDDL.
7f3a525d9SJohn Levon#
8f3a525d9SJohn Levon# A full copy of the text of the CDDL should have accompanied this
9f3a525d9SJohn Levon# source.  A copy of the CDDL is also available via the Internet at
10f3a525d9SJohn Levon# http://www.illumos.org/license/CDDL.
11f3a525d9SJohn Levon#
12f3a525d9SJohn Levon
13f3a525d9SJohn Levon#
14f3a525d9SJohn Levon# Copyright 2020 Joyent, Inc.
15*ba5b88a2SBill Sommerfeld# Copyright 2023 Bill Sommerfeld <sommerfeld@alum.mit.edu>
16f3a525d9SJohn Levon#
17f3a525d9SJohn Levon
18f3a525d9SJohn Levon#
19f3a525d9SJohn Levon# Clearly, grossly incomplete.
20f3a525d9SJohn Levon#
21f3a525d9SJohn Levon
22f3a525d9SJohn Levonexport LC_ALL=C.UTF-8
23f3a525d9SJohn Levon
24f3a525d9SJohn Levonset -o pipefail
25f3a525d9SJohn Levonunalias -a
26f3a525d9SJohn Levon
27f3a525d9SJohn Levonfind_prog=/usr/bin/find
28f3a525d9SJohn Levonfind_prog_xpg4=/usr/xpg4/bin/find
29f3a525d9SJohn Levonfind_exit=0
30f3a525d9SJohn Levon
312d43002eSJohn Levon# make sure we don't end in 1 or 2, which breaks the tests
322d43002eSJohn Levonfind_dir=/tmp/findtest.$$.dir
332d43002eSJohn Levon
342d43002eSJohn Levonmkdir $find_dir
352d43002eSJohn Levon
36f3a525d9SJohn Levontestfind()
37f3a525d9SJohn Levon{
38f3a525d9SJohn Levon	exp=$1
39f3a525d9SJohn Levon	shift
40f3a525d9SJohn Levon	cmd="$@"
41f3a525d9SJohn Levon
42f3a525d9SJohn Levon	echo "TEST: $cmd"
43f3a525d9SJohn Levon
44f3a525d9SJohn Levon	out=$(eval $cmd | tr '\n' ',')
45f3a525d9SJohn Levon
46*ba5b88a2SBill Sommerfeld	[[ "$exp" == "$out" ]] || {
47f3a525d9SJohn Levon		echo "TEST FAILED: $cmd" >&2
48f3a525d9SJohn Levon		echo "expected: $exp" >&2
49f3a525d9SJohn Levon		echo "got: $out" >&2
50f3a525d9SJohn Levon		find_exit=1
51f3a525d9SJohn Levon	}
52f3a525d9SJohn Levon}
53f3a525d9SJohn Levon
54f3a525d9SJohn Levonmkdir -p $find_dir/1
55f3a525d9SJohn Levonmkdir -p $find_dir/.2
56f3a525d9SJohn Levontouch $find_dir/.2/1
57f3a525d9SJohn Levontouch $find_dir/.2/c
58f3a525d9SJohn Levon
59f3a525d9SJohn Levontestfind "$find_dir/1,$find_dir/.2/1," \
60f3a525d9SJohn Levon    $find_prog $find_dir -name \"1\"
61f3a525d9SJohn Levontestfind "$find_dir/1,$find_dir/.2/1," \
62f3a525d9SJohn Levon    $find_prog $find_dir -path \"*1\"
63f3a525d9SJohn Levon
64f3a525d9SJohn Levoncd $find_dir
65f3a525d9SJohn Levon
66f3a525d9SJohn Levontestfind "" $find_prog . -name \"*2\"
67f3a525d9SJohn Levontestfind "./.2," $find_prog_xpg4 . -name \"*2\"
68f3a525d9SJohn Levontestfind "./.2," $find_prog . -name \".*2\"
69f3a525d9SJohn Levontestfind "./.2," $find_prog_xpg4 . -name \".*2\"
70f3a525d9SJohn Levontestfind "./1,./.2/1," $find_prog . -path \"*1\"
71f3a525d9SJohn Levontestfind "./.2," $find_prog . -path \"*2\"
72f3a525d9SJohn Levontestfind "./.2,./.2/1,./.2/c," $find_prog . -path \"*2*\"
73f3a525d9SJohn Levon
74f3a525d9SJohn Levoncd -
75f3a525d9SJohn Levonrm -rf $find_dir
76f3a525d9SJohn Levon
77*ba5b88a2SBill Sommerfeld# Regression test for bug 15353:
78*ba5b88a2SBill Sommerfeld#
79*ba5b88a2SBill Sommerfeld# For the purposes of this test we need a user and group with the same
80*ba5b88a2SBill Sommerfeld# numeric id.
81*ba5b88a2SBill Sommerfeld#
82*ba5b88a2SBill Sommerfeld# We also check that /var/tmp has ZFS/CIFS/NFS4-equivalent acls.
83*ba5b88a2SBill Sommerfeld#
84*ba5b88a2SBill Sommerfeld# (A complete test would also exercise ufs's acls)
85*ba5b88a2SBill Sommerfeld#
86*ba5b88a2SBill Sommerfeldtestuser=daemon
87*ba5b88a2SBill Sommerfeldtestgroup=other
88*ba5b88a2SBill Sommerfeld
89*ba5b88a2SBill Sommerfeldtestuid=$(getent passwd ${testuser} | cut -d: -f 3)
90*ba5b88a2SBill Sommerfeldtestgid=$(getent group ${testgroup} | cut -d: -f 3)
91*ba5b88a2SBill Sommerfeld
92*ba5b88a2SBill Sommerfeld[[ "$testuid" == "$testgid" ]] || {
93*ba5b88a2SBill Sommerfeld	echo "TEST FAILED: $cmd" >&2
94*ba5b88a2SBill Sommerfeld	echo "expected ${testuser}'s uid $testuid" \
95*ba5b88a2SBill Sommerfeld	     "to be equal to ${testgroup}'s gid $testgid" >&2
96*ba5b88a2SBill Sommerfeld	find_exit=1
97*ba5b88a2SBill Sommerfeld}
98*ba5b88a2SBill Sommerfeld
99*ba5b88a2SBill Sommerfeldfind_dir=/var/tmp/findtest.$$.dir
100*ba5b88a2SBill Sommerfeldmkdir -p $find_dir
101*ba5b88a2SBill Sommerfeld
102*ba5b88a2SBill Sommerfeld# ACL_ENABLED yields 0 for no acls, 1 for old acls, 2 for NFS acls.
103*ba5b88a2SBill Sommerfeld
104*ba5b88a2SBill Sommerfeld_ACL_ACE_ENABLED=2
105*ba5b88a2SBill Sommerfeld_ACL_ACLENT_ENABLED=1
106*ba5b88a2SBill Sommerfeld
107*ba5b88a2SBill Sommerfeld[[ $(getconf ACL_ENABLED $find_dir) == ${_ACL_ACE_ENABLED} ]] || {
108*ba5b88a2SBill Sommerfeld    echo "TEST SKIPPED: ACE acls not available in $find_dir"
109*ba5b88a2SBill Sommerfeld    find_exit=4			# UNSUPPORTED
110*ba5b88a2SBill Sommerfeld    exit $find_exit
111*ba5b88a2SBill Sommerfeld}
112*ba5b88a2SBill Sommerfeld
113*ba5b88a2SBill Sommerfeldmkdir -p $find_dir/a
114*ba5b88a2SBill Sommerfeldmkdir -p $find_dir/b
115*ba5b88a2SBill Sommerfeldchmod A+group:${testgroup}:read_set:allow $find_dir/a
116*ba5b88a2SBill Sommerfeldchmod A+user:${testuser}:read_set:allow $find_dir/b
117*ba5b88a2SBill Sommerfeld
118*ba5b88a2SBill Sommerfeldcd $find_dir
119*ba5b88a2SBill Sommerfeldtestfind "./a", $find_prog . -groupacl ${testgroup}
120*ba5b88a2SBill Sommerfeldtestfind "./b", $find_prog . -useracl ${testuser}
121*ba5b88a2SBill Sommerfeld
122*ba5b88a2SBill Sommerfeldcd -
123*ba5b88a2SBill Sommerfeldrm -rf $find_dir
124*ba5b88a2SBill Sommerfeld
125f3a525d9SJohn Levonexit $find_exit
126