2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2020 SUSE Linux Products GmbH. All Rights Reserved.
7 # Test if the file capabilities aren't lost after full and incremental send
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
15 status=1 # failure is the default!
16 trap "cleanup; exit \$status" 0 1 2 3 15
18 # get standard environment, filters and checks
22 # remove previous $seqres.full before test
27 _require_command "$SETCAP_PROG" setcap
28 _require_command "$GETCAP_PROG" getcap
30 FS1="$SCRATCH_MNT/fs1"
31 FS2="$SCRATCH_MNT/fs2"
46 ret=$(_getcap "$file")
47 if [ -z "$ret" ]; then
49 echo "missing capability in file $file"
51 if [[ "$ret" != *$cap* ]]; then
53 echo "Capabilities do not match. Output: $ret"
59 _scratch_mkfs >/dev/null
62 $BTRFS_UTIL_PROG subvolume create "$FS1" > /dev/null
63 $BTRFS_UTIL_PROG subvolume create "$FS2" > /dev/null
66 full_nocap_inc_withcap_send()
72 # Test full send containing a file without capabilities
74 $BTRFS_UTIL_PROG subvolume snapshot -r "$FS1" "$FS1/snap_init" >/dev/null
75 $BTRFS_UTIL_PROG send "$FS1/snap_init" -q | $BTRFS_UTIL_PROG receive "$FS2" -q
76 # ensure that we don't have capabilities set
77 ret=$(_getcap "$FS2/snap_init/foo.bar")
78 if [ -n "$ret" ]; then
79 echo "File contains capabilities when it shouldn't"
82 # Test if incremental send brings the newly added capability
83 $SETCAP_PROG "cap_sys_ptrace+ep cap_sys_nice+ep" "$FS1/foo.bar"
84 $BTRFS_UTIL_PROG subvolume snapshot -r "$FS1" "$FS1/snap_inc" >/dev/null
85 $BTRFS_UTIL_PROG send -p "$FS1/snap_init" "$FS1/snap_inc" -q | \
86 $BTRFS_UTIL_PROG receive "$FS2" -q
87 check_capabilities "$FS2/snap_inc/foo.bar" "cap_sys_ptrace,cap_sys_nice=ep"
96 # files should include foo.bar
101 # create files on fs1, must contain foo.bar
106 # Test full send, checking if the receiving side keeps the capabilities
107 $SETCAP_PROG "cap_sys_ptrace+ep cap_sys_nice+ep" "$FS1/foo.bar"
108 $BTRFS_UTIL_PROG subvolume snapshot -r "$FS1" "$FS1/snap_init" >/dev/null
109 $BTRFS_UTIL_PROG send "$FS1/snap_init" -q | $BTRFS_UTIL_PROG receive "$FS2" -q
110 check_capabilities "$FS2/snap_init/foo.bar" "cap_sys_ptrace,cap_sys_nice=ep"
112 # Test incremental send with different owner/group but same capabilities
113 chgrp 100 "$FS1/foo.bar"
114 $SETCAP_PROG "cap_sys_ptrace+ep cap_sys_nice+ep" "$FS1/foo.bar"
115 $BTRFS_UTIL_PROG subvolume snapshot -r "$FS1" "$FS1/snap_inc" >/dev/null
116 check_capabilities "$FS1/snap_inc/foo.bar" "cap_sys_ptrace,cap_sys_nice=ep"
117 $BTRFS_UTIL_PROG send -p "$FS1/snap_init" "$FS1/snap_inc" -q | \
118 $BTRFS_UTIL_PROG receive "$FS2" -q
119 check_capabilities "$FS2/snap_inc/foo.bar" "cap_sys_ptrace,cap_sys_nice=ep"
121 # Test capabilities after incremental send with different group and capabilities
122 chgrp 0 "$FS1/foo.bar"
123 $SETCAP_PROG "cap_sys_time+ep cap_syslog+ep" "$FS1/foo.bar"
124 $BTRFS_UTIL_PROG subvolume snapshot -r "$FS1" "$FS1/snap_inc2" >/dev/null
125 check_capabilities "$FS1/snap_inc2/foo.bar" "cap_sys_time,cap_syslog=ep"
126 $BTRFS_UTIL_PROG send -p "$FS1/snap_inc" "$FS1/snap_inc2" -q | \
127 $BTRFS_UTIL_PROG receive "$FS2" -q
128 check_capabilities "$FS2/snap_inc2/foo.bar" "cap_sys_time,cap_syslog=ep"
133 # real QA test starts here
135 echo "Test full send + file without capabilities, then incremental send bringing a new capability"
136 full_nocap_inc_withcap_send
138 echo "Testing if foo.bar alone can keep its capabilities"
139 roundtrip_send "foo.bar"
141 echo "Test foo.bar being the first item among other files"
142 roundtrip_send "foo.bar foo.bax foo.baz"
144 echo "Test foo.bar with objectid between two other files"
145 roundtrip_send "foo1 foo.bar foo3"
147 echo "Test foo.bar being the last item among other files"
148 roundtrip_send "foo1 foo2 foo.bar"