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 in user namespace, 29# then check the owner in its base. 30# 31# 32# STRATEGY: 33# 1. Create folder "idmap_test" 34# 2. Idmap the folder to "idmap_dest" 35# 3. Perform file operations in the idmapped folder in the user 36# namespace having the same idmap info as the idmapped mount 37# 4. Verify the owner of entries under the base folder "idmap_test" 38# 39 40verify_runnable "global" 41 42export WORKDIR=$TESTDIR/idmap_test 43export IDMAPDIR=$TESTDIR/idmap_dest 44 45function cleanup 46{ 47 kill -TERM ${unshared_pid} 48 log_must rm -rf $IDMAPDIR/* 49 if mountpoint $IDMAPDIR; then 50 log_must umount $IDMAPDIR 51 fi 52 log_must rm -rf $IDMAPDIR $WORKDIR 53} 54 55log_onexit cleanup 56 57if ! idmap_util -c $TESTDIR; then 58 log_unsupported "Idmap mount not supported." 59fi 60 61log_must mkdir -p $WORKDIR 62log_must mkdir -p $IDMAPDIR 63 64log_must chown $UID1:$GID1 $WORKDIR 65log_must idmap_util -m "u:${UID1}:${UID2}:1" -m "g:${GID1}:${GID2}:1" $WORKDIR $IDMAPDIR 66 67# Create a user namespace with the same idmapping 68unshare -Urm echo test 69if [ "$?" -ne "0" ]; then 70 log_unsupported "Failed to create user namespace" 71fi 72unshare -Um /usr/bin/sleep 2h & 73unshared_pid=$! 74if [ "$?" -ne "0" ]; then 75 log_unsupported "Failed to create user namespace" 76fi 77# wait for userns to be ready 78sleep 1 79echo "${UID1} ${UID2} 1" > /proc/$unshared_pid/uid_map 80if [ "$?" -ne "0" ]; then 81 log_unsupported "Failed to write to uid_map" 82fi 83echo "${GID1} ${GID2} 1" > /proc/$unshared_pid/gid_map 84if [ "$?" -ne "0" ]; then 85 log_unsupported "Failed to write to gid_map" 86fi 87 88NSENTER="nsenter -t $unshared_pid --all -S ${UID1} -G ${GID1}" 89 90log_must $NSENTER touch $IDMAPDIR/file1 91log_must test "$UID1 $GID1" = "$(stat -c '%u %g' $WORKDIR/file1)" 92 93log_must $NSENTER mv $IDMAPDIR/file1 $IDMAPDIR/file1_renamed 94log_must test "$UID1 $GID1" = "$(stat -c '%u %g' $WORKDIR/file1_renamed)" 95 96log_must $NSENTER mv $IDMAPDIR/file1_renamed $IDMAPDIR/file1 97log_must test "$UID1 $GID1" = "$(stat -c '%u %g' $WORKDIR/file1)" 98 99log_must $NSENTER mkdir $IDMAPDIR/subdir 100log_must test "$UID1 $GID1" = "$(stat -c '%u %g' $WORKDIR/subdir)" 101 102log_must $NSENTER ln -s $IDMAPDIR/file1 $IDMAPDIR/file1_sym 103log_must test "$UID1 $GID1" = "$(stat -c '%u %g' $WORKDIR/file1_sym)" 104 105log_must $NSENTER ln $IDMAPDIR/file1 $IDMAPDIR/subdir/file1_hard 106log_must test "$UID1 $GID1" = "$(stat -c '%u %g' $WORKDIR/subdir/file1_hard)" 107 108log_must $NSENTER touch $IDMAPDIR/subdir/file2 109log_must $NSENTER chown $UID1:$GID1 $IDMAPDIR/subdir/file2 110log_mustnot $NSENTER chown $UID2 $IDMAPDIR/subdir/file2 111 112log_must $NSENTER cp -r $IDMAPDIR/subdir $IDMAPDIR/subdir1 113log_must test "$UID1 $GID1" = "$(stat -c '%u %g' $WORKDIR/subdir1/file2)" 114log_must $NSENTER rm -rf $IDMAPDIR/subdir1 115 116log_must $NSENTER cp -rp $IDMAPDIR/subdir $IDMAPDIR/subdir1 117log_must test "$UID1 $GID1" = "$(stat -c '%u %g' $WORKDIR/subdir1/file1_hard)" 118log_must $NSENTER rm -rf $IDMAPDIR/subdir1 119 120log_pass "Owner verification of entries under the base folder is successful." 121 122