lib/: spdx license conversion
[xfstests-dev.git] / tests / generic / 093
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2000-2004 Silicon Graphics, Inc.  All Rights Reserved.
4 # Copyright (c) 2017 Google, Inc.  All Rights Reserved.
5 #
6 # FS QA Test No. 093
7 #
8 # Test clearing of capabilities on write.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1        # FAILure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 # get standard environment, filters and checks
19 . ./common/rc
20 . ./common/filter
21 . ./common/attr
22
23 _cleanup()
24 {
25     [ -n "$TEST_DIR" ] && rm -f $file
26 }
27
28 filefilter()
29 {
30     sed -e "s#$file#file#"
31 }
32
33 # real QA test starts here
34 _supported_fs generic
35 _supported_os Linux
36
37 _require_test
38 _require_attrs
39 _require_user
40 _require_test_program "writemod"
41 _require_command "$SETCAP_PROG" "setcap"
42 _require_command "$GETCAP_PROG" "getcap"
43
44 rm -f $seqres.full
45
46 echo "QA output created by $seq"
47 echo ""
48 file=$TEST_DIR/$seq.file
49
50 rm -f $file
51 touch $file
52
53 echo "**** Verifying that appending to file clears capabilities ****"
54 $SETCAP_PROG cap_chown+ep $file
55 $GETCAP_PROG $file | filefilter
56 echo data1 >> $file
57 cat $file
58 $GETCAP_PROG $file | filefilter
59 echo
60
61 echo "**** Verifying that appending to file doesn't clear other xattrs ****"
62 $SETCAP_PROG cap_chown+ep $file
63 $SETFATTR_PROG -n trusted.name -v value $file
64 echo data2 >> $file
65 cat $file
66 $GETFATTR_PROG -m '^trusted\.*' --absolute-names $file | filefilter
67
68 echo "**** Verifying that chmod doesn't affect open file descriptors ****"
69 rm -f $file
70 touch $file
71 chown $qa_user $file
72 chmod ugo+w $TEST_DIR
73 su $qa_user -c "src/writemod $file" | filefilter
74 cat $file
75
76 # success, all done
77 status=0
78 exit