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