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 _begin_fstest auto quick send snapshot
12 _register_cleanup "cleanup"
14 # Import common functions.
19 _require_command "$SETCAP_PROG" setcap
20 _require_command "$GETCAP_PROG" getcap
22 FS1="$SCRATCH_MNT/fs1"
23 FS2="$SCRATCH_MNT/fs2"
38 ret=$(_getcap "$file")
39 if [ -z "$ret" ]; then
41 echo "missing capability in file $file"
43 if [[ "$ret" != *$cap* ]]; then
45 echo "Capabilities do not match. Output: $ret"
51 _scratch_mkfs >/dev/null
54 $BTRFS_UTIL_PROG subvolume create "$FS1" > /dev/null
55 $BTRFS_UTIL_PROG subvolume create "$FS2" > /dev/null
58 full_nocap_inc_withcap_send()
64 # Test full send containing a file without capabilities
66 $BTRFS_UTIL_PROG subvolume snapshot -r "$FS1" "$FS1/snap_init" >/dev/null
67 $BTRFS_UTIL_PROG send "$FS1/snap_init" -q | $BTRFS_UTIL_PROG receive "$FS2" -q
68 # ensure that we don't have capabilities set
69 ret=$(_getcap "$FS2/snap_init/foo.bar")
70 if [ -n "$ret" ]; then
71 echo "File contains capabilities when it shouldn't"
74 # Test if incremental send brings the newly added capability
75 $SETCAP_PROG "cap_sys_ptrace+ep cap_sys_nice+ep" "$FS1/foo.bar"
76 $BTRFS_UTIL_PROG subvolume snapshot -r "$FS1" "$FS1/snap_inc" >/dev/null
77 $BTRFS_UTIL_PROG send -p "$FS1/snap_init" "$FS1/snap_inc" -q | \
78 $BTRFS_UTIL_PROG receive "$FS2" -q
79 check_capabilities "$FS2/snap_inc/foo.bar" "cap_sys_ptrace,cap_sys_nice=ep"
88 # files should include foo.bar
93 # create files on fs1, must contain foo.bar
98 # Test full send, checking if the receiving side keeps the capabilities
99 $SETCAP_PROG "cap_sys_ptrace+ep cap_sys_nice+ep" "$FS1/foo.bar"
100 $BTRFS_UTIL_PROG subvolume snapshot -r "$FS1" "$FS1/snap_init" >/dev/null
101 $BTRFS_UTIL_PROG send "$FS1/snap_init" -q | $BTRFS_UTIL_PROG receive "$FS2" -q
102 check_capabilities "$FS2/snap_init/foo.bar" "cap_sys_ptrace,cap_sys_nice=ep"
104 # Test incremental send with different owner/group but same capabilities
105 chgrp 100 "$FS1/foo.bar"
106 $SETCAP_PROG "cap_sys_ptrace+ep cap_sys_nice+ep" "$FS1/foo.bar"
107 $BTRFS_UTIL_PROG subvolume snapshot -r "$FS1" "$FS1/snap_inc" >/dev/null
108 check_capabilities "$FS1/snap_inc/foo.bar" "cap_sys_ptrace,cap_sys_nice=ep"
109 $BTRFS_UTIL_PROG send -p "$FS1/snap_init" "$FS1/snap_inc" -q | \
110 $BTRFS_UTIL_PROG receive "$FS2" -q
111 check_capabilities "$FS2/snap_inc/foo.bar" "cap_sys_ptrace,cap_sys_nice=ep"
113 # Test capabilities after incremental send with different group and capabilities
114 chgrp 0 "$FS1/foo.bar"
115 $SETCAP_PROG "cap_sys_time+ep cap_syslog+ep" "$FS1/foo.bar"
116 $BTRFS_UTIL_PROG subvolume snapshot -r "$FS1" "$FS1/snap_inc2" >/dev/null
117 check_capabilities "$FS1/snap_inc2/foo.bar" "cap_sys_time,cap_syslog=ep"
118 $BTRFS_UTIL_PROG send -p "$FS1/snap_inc" "$FS1/snap_inc2" -q | \
119 $BTRFS_UTIL_PROG receive "$FS2" -q
120 check_capabilities "$FS2/snap_inc2/foo.bar" "cap_sys_time,cap_syslog=ep"
125 # real QA test starts here
127 echo "Test full send + file without capabilities, then incremental send bringing a new capability"
128 full_nocap_inc_withcap_send
130 echo "Testing if foo.bar alone can keep its capabilities"
131 roundtrip_send "foo.bar"
133 echo "Test foo.bar being the first item among other files"
134 roundtrip_send "foo.bar foo.bax foo.baz"
136 echo "Test foo.bar with objectid between two other files"
137 roundtrip_send "foo1 foo.bar foo3"
139 echo "Test foo.bar being the last item among other files"
140 roundtrip_send "foo1 foo2 foo.bar"