xref: /illumos-gate/usr/src/test/util-tests/tests/find/findroot.ksh (revision 9bfeae155b3e1a3e699b678dba5e3b7f2223eca1)
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# Copyright 2024 Bill Sommerfeld <sommerfeld@hamachi.org>
13# Copyright 2025 MNX Cloud, Inc.
14#
15
16#
17# Tests for find(1) that exercise file ownership tests and thus need
18# to run as root to set up the test
19#
20
21# Regression test for SID operations
22
23. "$(dirname $0)/find.kshlib"
24
25# If we need to, and can, enable idmap temporarily as that's all that
26# should be needed to run this test.
27pretest_idmap_state=$(svcs -H -o state svc:/system/idmap)
28if [ "$pretest_idmap_state" == "disabled" ]; then
29    svcadm enable -st svc:/system/idmap
30fi
31
32# Now check for sure if we're can run this test.
33if [ $(svcs -H -o state svc:/system/idmap) != "online" ]; then
34    echo "svc:/system/idmap not enabled and online; can't do SID-to-UID mapping" >&2
35    # Disable idmap if we brought it up solely for this test.
36    if [ "$pretest_idmap_state" == "disabled" ]; then
37	svcadm disable svc:/system/idmap
38    fi
39    exit 4
40fi
41
42sida=S-1-5-21-11111111-22222222-33333333
43sidb=S-1-5-21-44444444-55555555-66666666
44
45mkdir -p $find_dir/a
46mkdir -p $find_dir/b
47
48# Functional test for -usid and -gsid
49
50chown -s $sida $find_dir/a
51chgrp -s $sidb $find_dir/b
52
53cd $find_dir
54
55testfind "./a", $find_prog . -usid ${sida}
56testfind "./b", $find_prog . -gsid ${sidb}
57
58# Functional test for -usidacl and -gsidacl
59
60chmod A+groupsid:${sidb}:read_set:allow $find_dir/a
61chmod A+usersid:${sida}:read_set:allow $find_dir/b
62
63testfind "./a", $find_prog . -gsidacl ${sidb}
64testfind "./b", $find_prog . -usidacl ${sida}
65
66# Functional test for -sidacl
67
68mkdir $find_dir/c
69mkdir $find_dir/d
70
71chmod A+groupsid:${sida}:read_set:allow $find_dir/c
72chmod A+usersid:${sidb}:read_set:allow $find_dir/d
73
74testfind "./b,./c," $find_prog . -sidacl ${sida}
75testfind "./a,./d," $find_prog . -sidacl ${sidb}
76
77cd -
78rm -rf $find_dir
79
80# Disable idmap if we brought it up solely for this test.
81if [ "$pretest_idmap_state" == "disabled" ]; then
82    svcadm disable svc:/system/idmap
83fi
84
85exit $find_exit
86