shadow/tests/newuidmap/02_newuidmap_relaxed_gid_check/newuidmap.test
Serge Hallyn 962c820fba fix newuidmap testcase
sleep 2s before running newxidmap - it seems we were sometimes
racing, causing newxidmap to fail.

Make sure to remove /tmp/test-xidmap, for some reason they
were sometimes still there, causing test to fail.

Fix some irregular tabbing.

Signed-off-by: Serge Hallyn <serge@hallyn.com>
2021-12-27 09:27:44 -06:00

55 lines
1.4 KiB
Bash
Executable File

#!/bin/sh
set -ex
cd $(dirname $0)
. ../../common/config.sh
. ../../common/log.sh
log_start "$0" "setup uid mapping when primary groups don't match"
save_config
unpriv_userns=$( sysctl -n kernel.unprivileged_userns_clone )
# restore the files on exit
trap 'log_status "$0" "FAILURE"; restore_config; \
rm -rf /tmp/test-uidmap; \
sysctl -q kernel.unprivileged_userns_clone=$unpriv_userns' 0
change_config
sysctl -q kernel.unprivileged_userns_clone=1
echo -n "Create world writable tmp directory..."
rm -rf /tmp/test-uidmap
mkdir -m 0777 /tmp/test-uidmap
echo "OK"
echo -n "setup uidmapping... "
base=$(id -u foo)
runuser foo -g foo -c "unshare -U sleep 10 & pid=\$!; \
sleep 2; newuidmap \$pid 0 $base 1 1 1000000 1000; ret=\$?; \
cat /proc/\$pid/uid_map >/tmp/test-uidmap/uid_map;
kill \$pid; exit \$ret"
../../common/compare_file.pl /tmp/test-uidmap/uid_map data/uid_map
echo "OK"
echo -n "setup uidmapping with different primary group... "
runuser foo -g bar -c "unshare -U sleep 10 & pid=\$!; \
sleep 2; newuidmap \$pid 0 $base 1 1 1000000 1000; ret=\$?; \
cat /proc/\$pid/uid_map >/tmp/test-uidmap/uid_map;
kill \$pid; exit \$ret"
../../common/compare_file.pl /tmp/test-uidmap/uid_map data/uid_map
echo "OK"
log_status "$0" "SUCCESS"
sysctl -q kernel.unprivileged_userns_clone=$unpriv_userns
rm -rf /tmp/test-uidmap;
restore_config
trap '' 0