summaryrefslogtreecommitdiff
path: root/tests/generic/555
blob: d243dccf04bc7dea8acb46d74cfd816c3611b78c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2019 CTERA Networks. All Rights Reserved.
#
# FS QA Test No. 555
#
# Check that we can't set FS_XFLAG_APPEND and FS_XFLAG_IMMUTABLE inode
# flags without capbility CAP_LINUX_IMMUTABLE.
#
# This test uses xfs_io chattr, rather than the (e2fsprogs) chattr
# program to exercise the FS_IOC_FSSETXATTR ioctl.
#
. ./common/preamble
_begin_fstest auto quick cap

# Override the default cleanup function.
_cleanup()
{
	# Cleanup of flags on both file in case test is aborted
	# (i.e. CTRL-C), so we have no immutable/append-only files
	$XFS_IO_PROG -f -r -c "chattr -ia" $workdir/file1 >/dev/null 2>&1
	$XFS_IO_PROG -f -r -c "chattr -ia" $workdir/file2 >/dev/null 2>&1

	cd /
	rm -rf $tmp.* $workdir
}

# Import common functions.
. ./common/filter
. ./common/attr

# real QA test starts here
_supported_fs generic

_require_test
_require_xfs_io_command "chattr" "ia"
_require_command "$CAPSH_PROG" "capsh"

workdir="$TEST_DIR/test-$seq"
rm -rf $workdir
mkdir $workdir

echo "Create the original files"
touch $workdir/file1
touch $workdir/file2

do_filter_output()
{
	grep -o "Operation not permitted"
}

echo "Try to xfs_io chattr +ia with capabilities CAP_LINUX_IMMUTABLE"
$XFS_IO_PROG -f -c "chattr +ia" $workdir/file1

echo "Try to xfs_io chattr +ia/-ia without capability CAP_LINUX_IMMUTABLE"
$CAPSH_PROG --drop=cap_linux_immutable -- -c "$XFS_IO_PROG -f -c 'chattr +a' $workdir/file2" 2>&1 | do_filter_output
$CAPSH_PROG --drop=cap_linux_immutable -- -c "$XFS_IO_PROG -f -c 'chattr +i' $workdir/file2" 2>&1 | do_filter_output

$CAPSH_PROG --drop=cap_linux_immutable -- -c "$XFS_IO_PROG -f -r -c 'chattr -i' $workdir/file1" 2>&1 | do_filter_output
$CAPSH_PROG --drop=cap_linux_immutable -- -c "$XFS_IO_PROG -f -r -c 'chattr -a' $workdir/file1" 2>&1 | do_filter_output

echo "Try to xfs_io chattr -ia with capability CAP_LINUX_IMMUTABLE"
$XFS_IO_PROG -f -r -c "chattr -ia" $workdir/file1

# success, all done
status=0
exit