xref: /illumos-gate/usr/src/test/util-tests/tests/find/findtest.ksh (revision 7655c6d53c36750b508636f48c73a2de57754e5a)
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 2024 Bill Sommerfeld <sommerfeld@hamachi.org>
16#
17
18#
19# Clearly, grossly incomplete.
20#
21
22. "$(dirname $0)/find.kshlib"
23
24mkdir $find_dir
25mkdir -p $find_dir/1
26mkdir -p $find_dir/.2
27touch $find_dir/.2/1
28touch $find_dir/.2/c
29
30testfind "$find_dir/.2/1,$find_dir/1," \
31    $find_prog $find_dir -name \"1\"
32testfind "$find_dir/.2/1,$find_dir/1," \
33    $find_prog $find_dir -path \"*1\"
34
35cd $find_dir
36
37testfind "" $find_prog . -name \"*2\"
38testfind "./.2," $find_prog_xpg4 . -name \"*2\"
39testfind "./.2," $find_prog . -name \".*2\"
40testfind "./.2," $find_prog_xpg4 . -name \".*2\"
41testfind "./.2/1,./1," $find_prog . -path \"*1\"
42testfind "./.2," $find_prog . -path \"*2\"
43testfind "./.2,./.2/1,./.2/c," $find_prog . -path \"*2*\"
44
45cd -
46rm -rf $find_dir
47
48# Regression test for bug 15353:
49#
50# For the purposes of this test we need a user and group with the same
51# numeric id.
52#
53# We also check that /var/tmp has ZFS/CIFS/NFS4-equivalent acls.
54#
55# (A complete test would also exercise ufs's acls)
56#
57testuser=daemon
58testgroup=other
59
60testuid=$(getent passwd ${testuser} | cut -d: -f 3)
61testgid=$(getent group ${testgroup} | cut -d: -f 3)
62
63[[ "$testuid" == "$testgid" ]] || {
64	echo "TEST FAILED: $cmd" >&2
65	echo "expected ${testuser}'s uid $testuid" \
66	     "to be equal to ${testgroup}'s gid $testgid" >&2
67	find_exit=1
68}
69
70find_dir=/var/tmp/findtest.$$.dir
71mkdir -p $find_dir
72
73# ACL_ENABLED yields 0 for no acls, 1 for old acls, 2 for NFS acls.
74
75_ACL_ACE_ENABLED=2
76_ACL_ACLENT_ENABLED=1
77
78[[ $(getconf ACL_ENABLED $find_dir) == ${_ACL_ACE_ENABLED} ]] || {
79    echo "TEST SKIPPED: ACE acls not available in $find_dir"
80    find_exit=4			# UNSUPPORTED
81    exit $find_exit
82}
83
84mkdir -p $find_dir/a
85mkdir -p $find_dir/b
86chmod A+group:${testgroup}:read_set:allow $find_dir/a
87chmod A+user:${testuser}:read_set:allow $find_dir/b
88
89cd $find_dir
90testfind "./a", $find_prog . -groupacl ${testgroup}
91testfind "./b", $find_prog . -useracl ${testuser}
92
93cd -
94rm -rf $find_dir
95
96exit $find_exit
97