generic/611: Use _getfattr instead of GETFATTR_PROG
[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_fs generic
37
38 _require_test
39 _require_chattr i
40 _require_chattr a
41 _require_command "$CAPSH_PROG" "capsh"
42
43 workdir="$TEST_DIR/test-$seq"
44 rm -rf $workdir
45 mkdir $workdir
46
47 echo "Create the original files"
48 touch $workdir/file1
49 touch $workdir/file2
50
51 do_filter_output()
52 {
53         grep -o "Operation not permitted"
54 }
55
56 echo "Try to chattr +ia with capabilities CAP_LINUX_IMMUTABLE"
57 $CHATTR_PROG +a $workdir/file1
58 $CHATTR_PROG +i $workdir/file1
59
60 echo "Try to chattr +ia/-ia without capability CAP_LINUX_IMMUTABLE"
61 $CAPSH_PROG --drop=cap_linux_immutable -- -c "$CHATTR_PROG +a $workdir/file2" 2>&1 | do_filter_output
62 $CAPSH_PROG --drop=cap_linux_immutable -- -c "$CHATTR_PROG +i $workdir/file2" 2>&1 | do_filter_output
63
64 $CAPSH_PROG --drop=cap_linux_immutable -- -c "$CHATTR_PROG -i $workdir/file1" 2>&1 | do_filter_output
65 $CAPSH_PROG --drop=cap_linux_immutable -- -c "$CHATTR_PROG -a $workdir/file1" 2>&1 | do_filter_output
66
67 echo "Try to chattr -ia with capability CAP_LINUX_IMMUTABLE"
68 $CHATTR_PROG -i $workdir/file1
69 $CHATTR_PROG -a $workdir/file1
70
71 # success, all done
72 status=0
73 exit