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