blob: 9551e47cb13b06ed2f5c0684bc0bd0ea672b8bae [file] [log] [blame]
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2022 Oracle. All Rights Reserved.
#
# FS QA Test No. 727
#
# Functional test for dropping capability bits as part of an atomic file
# commit.
#
. ./common/preamble
_begin_fstest auto fiexchange quick
# Override the default cleanup function.
# _cleanup()
# {
# cd /
# rm -r -f $tmp.*
# }
# Import common functions.
. ./common/filter
. ./common/attr
# Modify as appropriate.
_require_user
_require_command "$GETCAP_PROG" getcap
_require_command "$SETCAP_PROG" setcap
_require_xfs_io_command exchangerange
_require_xfs_io_command startupdate
_require_scratch
_require_attrs security
_scratch_mkfs >> $seqres.full
_scratch_mount
_require_congruent_file_oplen $SCRATCH_MNT 1048576
chmod a+rw $SCRATCH_MNT/
setup_testfile() {
rm -f $SCRATCH_MNT/a $SCRATCH_MNT/b
_pwrite_byte 0x58 0 1m $SCRATCH_MNT/a >> $seqres.full
_pwrite_byte 0x57 0 1m $SCRATCH_MNT/b >> $seqres.full
chmod a+rw $SCRATCH_MNT/a $SCRATCH_MNT/b
$SETCAP_PROG cap_setgid,cap_setuid+ep $SCRATCH_MNT/a
_scratch_sync
}
commit_and_check() {
local user="$1"
md5sum $SCRATCH_MNT/a | _filter_scratch
stat -c '%a %A %n' $SCRATCH_MNT/a | _filter_scratch
_getcap -v $SCRATCH_MNT/a | _filter_scratch
local cmd="$XFS_IO_PROG -c 'startupdate' -c 'pwrite -S 0x57 0 1m' -c 'commitupdate' $SCRATCH_MNT/a"
if [ -n "$user" ]; then
_su - "$user" -c "$cmd" >> $seqres.full
else
$SHELL -c "$cmd" >> $seqres.full
fi
_scratch_cycle_mount
md5sum $SCRATCH_MNT/a | _filter_scratch
stat -c '%a %A %n' $SCRATCH_MNT/a | _filter_scratch
_getcap -v $SCRATCH_MNT/a | _filter_scratch
# Blank line in output
echo
}
# Commit by an unprivileged user clears capability bits.
echo "Test 1 - qa_user"
setup_testfile
commit_and_check "$qa_user"
# Commit by root leaves capability bits.
echo "Test 2 - root"
setup_testfile
commit_and_check
# success, all done
status=0
exit