Debian Codegraph @

tests/newuidmap/02_newuidmap_relaxed_gid_check/newuidmap.test

raw
1 #!/bin/sh
2
3 set -ex
4
5 cd $(dirname $0)
6
7 . ../../common/config.sh
8 . ../../common/log.sh
9
10 log_start "$0" "setup uid mapping when primary groups don't match"
11
12 save_config
13
14 unpriv_userns=$( sysctl -n kernel.unprivileged_userns_clone )
15
16 # restore the files on exit
17 trap 'log_status "$0" "FAILURE"; restore_config; \
18 rm -rf /tmp/test-uidmap; \
19 sysctl -q kernel.unprivileged_userns_clone=$unpriv_userns' 0
20
21 change_config
22
23 sysctl -q kernel.unprivileged_userns_clone=1
24
25 echo -n "Create world writable tmp directory..."
26 rm -rf /tmp/test-uidmap
27 mkdir -m 0777 /tmp/test-uidmap
28 echo "OK"
29
30 echo -n "setup uidmapping... "
31 base=$(id -u foo)
32 runuser foo -g foo -c "unshare -U sleep 10 & pid=\$!; \
33 sleep 2; newuidmap \$pid 0 $base 1 1 1000000 1000; ret=\$?; \
34 cat /proc/\$pid/uid_map >/tmp/test-uidmap/uid_map;
35 kill \$pid; exit \$ret"
36 ../../common/compare_file.pl /tmp/test-uidmap/uid_map data/uid_map
37 echo "OK"
38
39 echo -n "setup uidmapping with different primary group... "
40 runuser foo -g bar -c "unshare -U sleep 10 & pid=\$!; \
41 sleep 2; newuidmap \$pid 0 $base 1 1 1000000 1000; ret=\$?; \
42 cat /proc/\$pid/uid_map >/tmp/test-uidmap/uid_map;
43 kill \$pid; exit \$ret"
44 ../../common/compare_file.pl /tmp/test-uidmap/uid_map data/uid_map
45 echo "OK"
46
47 log_status "$0" "SUCCESS"
48
49 sysctl -q kernel.unprivileged_userns_clone=$unpriv_userns
50 rm -rf /tmp/test-uidmap;
51
52 restore_config
53 trap '' 0
54