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
28 _require_command "$SETCAP_PROG" setcap
29 _require_command "$GETCAP_PROG" getcap
31 FS1="$SCRATCH_MNT/fs1"
32 FS2="$SCRATCH_MNT/fs2"
47 ret=$($GETCAP_PROG "$file")
48 if [ -z "$ret" ]; then
50 echo "missing capability in file $file"
52 if [[ "$ret" != *$cap* ]]; then
54 echo "Capabilities do not match. Output: $ret"
60 _scratch_mkfs >/dev/null
63 $BTRFS_UTIL_PROG subvolume create "$FS1" > /dev/null
64 $BTRFS_UTIL_PROG subvolume create "$FS2" > /dev/null
67 full_nocap_inc_withcap_send()
73 # Test full send containing a file without capabilities
75 $BTRFS_UTIL_PROG subvolume snapshot -r "$FS1" "$FS1/snap_init" >/dev/null
76 $BTRFS_UTIL_PROG send "$FS1/snap_init" -q | $BTRFS_UTIL_PROG receive "$FS2" -q
77 # ensure that we don't have capabilities set
78 ret=$($GETCAP_PROG "$FS2/snap_init/foo.bar")
79 if [ -n "$ret" ]; then
80 echo "File contains capabilities when it shouldn't"
83 # Test if incremental send brings the newly added capability
84 $SETCAP_PROG "cap_sys_ptrace+ep cap_sys_nice+ep" "$FS1/foo.bar"
85 $BTRFS_UTIL_PROG subvolume snapshot -r "$FS1" "$FS1/snap_inc" >/dev/null
86 $BTRFS_UTIL_PROG send -p "$FS1/snap_init" "$FS1/snap_inc" -q | \
87 $BTRFS_UTIL_PROG receive "$FS2" -q
88 check_capabilities "$FS2/snap_inc/foo.bar" "cap_sys_ptrace,cap_sys_nice+ep"
97 # files should include foo.bar
102 # create files on fs1, must contain foo.bar
107 # Test full send, checking if the receiving side keeps the capabilities
108 $SETCAP_PROG "cap_sys_ptrace+ep cap_sys_nice+ep" "$FS1/foo.bar"
109 $BTRFS_UTIL_PROG subvolume snapshot -r "$FS1" "$FS1/snap_init" >/dev/null
110 $BTRFS_UTIL_PROG send "$FS1/snap_init" -q | $BTRFS_UTIL_PROG receive "$FS2" -q
111 check_capabilities "$FS2/snap_init/foo.bar" "cap_sys_ptrace,cap_sys_nice+ep"
113 # Test incremental send with different owner/group but same capabilities
114 chgrp 100 "$FS1/foo.bar"
115 $SETCAP_PROG "cap_sys_ptrace+ep cap_sys_nice+ep" "$FS1/foo.bar"
116 $BTRFS_UTIL_PROG subvolume snapshot -r "$FS1" "$FS1/snap_inc" >/dev/null
117 check_capabilities "$FS1/snap_inc/foo.bar" "cap_sys_ptrace,cap_sys_nice+ep"
118 $BTRFS_UTIL_PROG send -p "$FS1/snap_init" "$FS1/snap_inc" -q | \
119 $BTRFS_UTIL_PROG receive "$FS2" -q
120 check_capabilities "$FS2/snap_inc/foo.bar" "cap_sys_ptrace,cap_sys_nice+ep"
122 # Test capabilities after incremental send with different group and capabilities
123 chgrp 0 "$FS1/foo.bar"
124 $SETCAP_PROG "cap_sys_time+ep cap_syslog+ep" "$FS1/foo.bar"
125 $BTRFS_UTIL_PROG subvolume snapshot -r "$FS1" "$FS1/snap_inc2" >/dev/null
126 check_capabilities "$FS1/snap_inc2/foo.bar" "cap_sys_time,cap_syslog+ep"
127 $BTRFS_UTIL_PROG send -p "$FS1/snap_inc" "$FS1/snap_inc2" -q | \
128 $BTRFS_UTIL_PROG receive "$FS2" -q
129 check_capabilities "$FS2/snap_inc2/foo.bar" "cap_sys_time,cap_syslog+ep"
134 # real QA test starts here
136 echo "Test full send + file without capabilities, then incremental send bringing a new capability"
137 full_nocap_inc_withcap_send
139 echo "Testing if foo.bar alone can keep its capabilities"
140 roundtrip_send "foo.bar"
142 echo "Test foo.bar being the first item among other files"
143 roundtrip_send "foo.bar foo.bax foo.baz"
145 echo "Test foo.bar with objectid between two other files"
146 roundtrip_send "foo1 foo.bar foo3"
148 echo "Test foo.bar being the last item among other files"
149 roundtrip_send "foo1 foo2 foo.bar"