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