generic: test adding filesystem-level fscrypt key via key_id
[xfstests-dev.git] / tests / generic / 555
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2019 CTERA Networks. All Rights Reserved.
4 #
5 # FS QA Test No. 555
6 #
7 # Check that we can't set FS_XFLAG_APPEND and FS_XFLAG_IMMUTABLE inode
8 # flags without capbility CAP_LINUX_IMMUTABLE.
9 #
10 # This test uses xfs_io chattr, rather than the (e2fsprogs) chattr
11 # program to exercise the FS_IOC_FSSETXATTR ioctl.
12 #
13 seq=`basename $0`
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
16
17 here=`pwd`
18 tmp=/tmp/$$
19 status=1    # failure is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
21
22 _cleanup()
23 {
24         # Cleanup of flags on both file in case test is aborted
25         # (i.e. CTRL-C), so we have no immutable/append-only files
26         $XFS_IO_PROG -f -r -c "chattr -ia" $workdir/file1 >/dev/null 2>&1
27         $XFS_IO_PROG -f -r -c "chattr -ia" $workdir/file2 >/dev/null 2>&1
28
29         cd /
30         rm -rf $tmp.* $workdir
31 }
32
33 # get standard environment, filters and checks
34 . ./common/rc
35 . ./common/filter
36 . ./common/attr
37
38 # real QA test starts here
39 _supported_os Linux
40 _supported_fs generic
41
42 _require_test
43 _require_xfs_io_command "chattr" "ia"
44 _require_command "$CAPSH_PROG" "capsh"
45
46 workdir="$TEST_DIR/test-$seq"
47 rm -rf $workdir
48 mkdir $workdir
49
50 echo "Create the original files"
51 touch $workdir/file1
52 touch $workdir/file2
53
54 do_filter_output()
55 {
56         grep -o "Operation not permitted"
57 }
58
59 echo "Try to xfs_io chattr +ia with capabilities CAP_LINUX_IMMUTABLE"
60 $XFS_IO_PROG -f -c "chattr +ia" $workdir/file1
61
62 echo "Try to xfs_io chattr +ia/-ia without capability CAP_LINUX_IMMUTABLE"
63 $CAPSH_PROG --drop=cap_linux_immutable -- -c "$XFS_IO_PROG -f -c 'chattr +a' $workdir/file2" 2>&1 | do_filter_output
64 $CAPSH_PROG --drop=cap_linux_immutable -- -c "$XFS_IO_PROG -f -c 'chattr +i' $workdir/file2" 2>&1 | do_filter_output
65
66 $CAPSH_PROG --drop=cap_linux_immutable -- -c "$XFS_IO_PROG -f -r -c 'chattr -i' $workdir/file1" 2>&1 | do_filter_output
67 $CAPSH_PROG --drop=cap_linux_immutable -- -c "$XFS_IO_PROG -f -r -c 'chattr -a' $workdir/file1" 2>&1 | do_filter_output
68
69 echo "Try to xfs_io chattr -ia with capability CAP_LINUX_IMMUTABLE"
70 $XFS_IO_PROG -f -r -c "chattr -ia" $workdir/file1
71
72 # success, all done
73 status=0
74 exit