Debian Codegraph @

tests/ts/mount/set_ugid_mode

raw
1 #!/bin/bash
2 # SPDX-License-Identifier: 0BSD
3
4
5 TS_TOPDIR="${0%/*}/../.."
6 TS_DESC="X-mount.{owner,group,mode}="
7
8 . "$TS_TOPDIR"/functions.sh
9 ts_init "$*"
10
11 ts_check_test_command "$TS_CMD_MOUNT"
12 ts_check_test_command "$TS_CMD_UMOUNT"
13
14 ts_skip_nonroot
15 ts_check_losetup
16 ts_check_prog "mkfs.ext2"
17 ts_check_prog "id"
18 ts_check_prog "stat"
19
20
21 do_one() {
22 expected="$1"; shift
23 what="$1"; shift
24 where="$1"; shift
25 $TS_CMD_MOUNT "$@" "$what" "$where" >> $TS_OUTPUT 2>> $TS_ERRLOG
26 actual=$(stat --format="%A %u %g" "$where")
27 [ "$actual" = "$expected" ] || echo "$*: $actual != $expected" >> $TS_ERRLOG
28 $TS_CMD_UMOUNT "$where" >> $TS_OUTPUT 2>> $TS_ERRLOG
29 }
30
31 ts_device_init
32
33 mkfs.ext2 "$TS_LODEV" > /dev/null 2>&1 || ts_die "Cannot make ext2 on $TS_LODEV"
34 ts_device_has "TYPE" "ext2" "$TS_LODEV" || ts_die "Cannot find ext2 on $TS_LODEV"
35
36 user_1="$(id -un 1)"
37 group_2="$(id -gn 2)"
38
39
40 mkdir -p "$TS_MOUNTPOINT"
41
42 do_one "drwxr-xr-x 0 0" "$TS_LODEV" "$TS_MOUNTPOINT"
43 do_one "drwxr-xr-x 1 0" "$TS_LODEV" "$TS_MOUNTPOINT" -o "X-mount.owner=$user_1"
44 do_one "drwxr-xr-x 1 2" "$TS_LODEV" "$TS_MOUNTPOINT" -o "X-mount.group=$group_2"
45 do_one "d-w--wxr-T 132 2" "$TS_LODEV" "$TS_MOUNTPOINT" -o "X-mount.owner=132,X-mount.mode=1234"
46 do_one "d-ws-w---x 132 123" "$TS_LODEV" "$TS_MOUNTPOINT" -o "X-mount.mode=4321,X-mount.group=123"
47 do_one "d-ws-w---x 1 321" "$TS_LODEV" "$TS_MOUNTPOINT" -o "X-mount.owner=$user_1,X-mount.group=321"
48
49
50 > "$TS_MOUNTPOINT/bind"
51 > "$TS_MOUNTPOINT/bindsrc"
52
53 do_one "-rw-r--r-- 0 0" "$TS_MOUNTPOINT/bindsrc" "$TS_MOUNTPOINT/bind" --bind
54 do_one "-rw-r--r-- 1 0" "$TS_MOUNTPOINT/bindsrc" "$TS_MOUNTPOINT/bind" --bind -o "X-mount.owner=$user_1"
55 do_one "-rw-r--r-- 1 2" "$TS_MOUNTPOINT/bindsrc" "$TS_MOUNTPOINT/bind" --bind -o "X-mount.group=$group_2"
56 do_one "--w--wxr-T 132 2" "$TS_MOUNTPOINT/bindsrc" "$TS_MOUNTPOINT/bind" --bind -o "X-mount.owner=132,X-mount.mode=1234"
57 do_one "--ws-w---x 132 123" "$TS_MOUNTPOINT/bindsrc" "$TS_MOUNTPOINT/bind" --bind -o "X-mount.mode=4321,X-mount.group=123"
58 do_one "--wx-w---x 1 321" "$TS_MOUNTPOINT/bindsrc" "$TS_MOUNTPOINT/bind" --bind -o "X-mount.owner=$user_1,X-mount.group=321"
59
60
61 rm -fd "$TS_MOUNTPOINT/bind" "$TS_MOUNTPOINT/bindsrc" "$TS_MOUNTPOINT"
62
63 ts_log "Success"
64 ts_finalize