xref: /freebsd/sys/contrib/openzfs/tests/zfs-tests/tests/functional/idmap_mount/idmap_mount_002.ksh (revision 61145dc2b94f12f6a47344fb9aac702321880e43)
1#!/bin/ksh -p
2# SPDX-License-Identifier: CDDL-1.0
3#
4# CDDL HEADER START
5#
6# The contents of this file are subject to the terms of the
7# Common Development and Distribution License (the "License").
8# You may not use this file except in compliance with the License.
9#
10# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11# or https://opensource.org/licenses/CDDL-1.0.
12# See the License for the specific language governing permissions
13# and limitations under the License.
14#
15# When distributing Covered Code, include this CDDL HEADER in each
16# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17# If applicable, add the following below this CDDL HEADER, with the
18# fields enclosed by brackets "[]" replaced with your own identifying
19# information: Portions Copyright [yyyy] [name of copyright owner]
20#
21# CDDL HEADER END
22#
23
24. $STF_SUITE/tests/functional/idmap_mount/idmap_mount_common.kshlib
25
26#
27#
28# DESCRIPTION:
29#       Perform file operations in idmapped folder, check owner in its base.
30#
31#
32# STRATEGY:
33#       1. Create folder "idmap_test"
34#       2. Idmap the folder to "idmap_dest"
35#       3. Do basic file operations in "idmap_dest" folder, verify the owner in
36#          the base folder "idmap_test"
37#
38
39verify_runnable "global"
40
41export WORKDIR=$TESTDIR/idmap_test
42export IDMAPDIR=$TESTDIR/idmap_dest
43
44function cleanup
45{
46	log_must rm -rf $IDMAPDIR/*
47	if mountpoint $IDMAPDIR; then
48		log_must umount $IDMAPDIR
49	fi
50	log_must rm -rf $IDMAPDIR $WORKDIR
51}
52
53log_onexit cleanup
54
55if ! idmap_util -c $TESTDIR; then
56	log_unsupported "Idmap mount not supported."
57fi
58
59log_must mkdir -p $WORKDIR
60log_must mkdir -p $IDMAPDIR
61
62log_must chown $UID1:$GID1 $WORKDIR
63log_must idmap_util -m "u:${UID1}:${UID2}:1" -m "g:${GID1}:${GID2}:1" $WORKDIR $IDMAPDIR
64
65SETPRIV="setpriv --reuid $UID2 --regid $GID2 --clear-groups"
66
67log_must $SETPRIV touch $IDMAPDIR/file1
68log_must test "$UID1 $GID1" = "$(stat -c '%u %g' $WORKDIR/file1)"
69
70log_must $SETPRIV mv $IDMAPDIR/file1 $IDMAPDIR/file1_renamed
71log_must test "$UID1 $GID1" = "$(stat -c '%u %g' $WORKDIR/file1_renamed)"
72
73log_must $SETPRIV mv $IDMAPDIR/file1_renamed $IDMAPDIR/file1
74log_must test "$UID1 $GID1" = "$(stat -c '%u %g' $WORKDIR/file1)"
75
76log_must $SETPRIV mkdir $IDMAPDIR/subdir
77log_must test "$UID1 $GID1" = "$(stat -c '%u %g' $WORKDIR/subdir)"
78
79log_must $SETPRIV ln -s $IDMAPDIR/file1 $IDMAPDIR/file1_sym
80log_must test "$UID1 $GID1" = "$(stat -c '%u %g' $WORKDIR/file1_sym)"
81
82log_must $SETPRIV ln $IDMAPDIR/file1 $IDMAPDIR/subdir/file1_hard
83log_must test "$UID1 $GID1" = "$(stat -c '%u %g' $WORKDIR/subdir/file1_hard)"
84
85log_must $SETPRIV touch $IDMAPDIR/subdir/file2
86log_must $SETPRIV chown $UID2:$GID2 $IDMAPDIR/subdir/file2
87log_mustnot $SETPRIV chown $UID1 $IDMAPDIR/subdir/file2
88
89log_must $SETPRIV cp -r $IDMAPDIR/subdir $IDMAPDIR/subdir1
90log_must test "$UID1 $GID1" = "$(stat -c '%u %g' $WORKDIR/subdir1/file2)"
91log_must $SETPRIV rm -rf $IDMAPDIR/subdir1
92
93log_must $SETPRIV cp -rp $IDMAPDIR/subdir $IDMAPDIR/subdir1
94log_must test "$UID1 $GID1" = "$(stat -c '%u %g' $WORKDIR/subdir1/file1_hard)"
95log_must $SETPRIV rm -rf $IDMAPDIR/subdir1
96
97log_pass "Owner verification of entries under base folder is successful."
98
99