2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2019 Alibaba Group. All Rights Reserved.
7 # Check that we can't set the FS_APPEND_FL and FS_IMMUTABLE_FL inode
8 # flags without capbility CAP_LINUX_IMMUTABLE
11 _begin_fstest auto quick cap
13 # Override the default cleanup function.
16 # Cleanup of flags on both file in case test is aborted
17 # (i.e. CTRL-C), so we have no immutable/append-only files
18 $CHATTR_PROG -ia $workdir/file1 >/dev/null 2>&1
19 $CHATTR_PROG -ia $workdir/file2 >/dev/null 2>&1
22 rm -rf $tmp.* $workdir
25 # Import common functions.
29 # real QA test starts here
35 _require_command "$CAPSH_PROG" "capsh"
37 workdir="$TEST_DIR/test-$seq"
41 echo "Create the original files"
47 grep -o "Operation not permitted"
50 echo "Try to chattr +ia with capabilities CAP_LINUX_IMMUTABLE"
51 $CHATTR_PROG +a $workdir/file1
52 $CHATTR_PROG +i $workdir/file1
54 echo "Try to chattr +ia/-ia without capability CAP_LINUX_IMMUTABLE"
55 $CAPSH_PROG --drop=cap_linux_immutable -- -c "$CHATTR_PROG +a $workdir/file2" 2>&1 | do_filter_output
56 $CAPSH_PROG --drop=cap_linux_immutable -- -c "$CHATTR_PROG +i $workdir/file2" 2>&1 | do_filter_output
58 $CAPSH_PROG --drop=cap_linux_immutable -- -c "$CHATTR_PROG -i $workdir/file1" 2>&1 | do_filter_output
59 $CAPSH_PROG --drop=cap_linux_immutable -- -c "$CHATTR_PROG -a $workdir/file1" 2>&1 | do_filter_output
61 echo "Try to chattr -ia with capability CAP_LINUX_IMMUTABLE"
62 $CHATTR_PROG -i $workdir/file1
63 $CHATTR_PROG -a $workdir/file1