e70273bca7f230d12f1a187af41e227d05f12ee1
[xfstests-dev.git] / tests / generic / 093
1 #! /bin/bash
2 # FS QA Test No. 093
3 #
4 # Test clearing of capabilities on write.
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2000-2004 Silicon Graphics, Inc.  All Rights Reserved.
8 # Copyright (c) 2017 Google, Inc.  All Rights Reserved.
9 #
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License as
12 # published by the Free Software Foundation.
13 #
14 # This program is distributed in the hope that it would be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write the Free Software Foundation,
21 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22 #
23 #-----------------------------------------------------------------------
24 #
25
26 seq=`basename $0`
27 seqres=$RESULT_DIR/$seq
28
29 here=`pwd`
30 tmp=/tmp/$$
31 status=1        # FAILure is the default!
32 trap "_cleanup; exit \$status" 0 1 2 3 15
33
34 # get standard environment, filters and checks
35 . ./common/rc
36 . ./common/filter
37 . ./common/attr
38
39 _cleanup()
40 {
41     [ -n "$TEST_DIR" ] && rm -f $file
42 }
43
44 filefilter()
45 {
46     sed -e "s#$file#file#"
47 }
48
49 # real QA test starts here
50 _supported_fs generic
51 _supported_os Linux
52
53 _require_test
54 _require_attrs
55 _require_user
56 _require_test_program "writemod"
57 _require_command "$SETCAP_PROG" "setcap"
58 _require_command "$GETCAP_PROG" "getcap"
59
60 rm -f $seqres.full
61
62 echo "QA output created by $seq"
63 echo ""
64 file=$TEST_DIR/$seq.file
65
66 rm -f $file
67 touch $file
68
69 echo "**** Verifying that appending to file clears capabilities ****"
70 $SETCAP_PROG cap_chown+ep $file
71 $GETCAP_PROG $file | filefilter
72 echo data1 >> $file
73 cat $file
74 $GETCAP_PROG $file | filefilter
75 echo
76
77 echo "**** Verifying that appending to file doesn't clear other xattrs ****"
78 $SETCAP_PROG cap_chown+ep $file
79 $SETFATTR_PROG -n trusted.name -v value $file
80 echo data2 >> $file
81 cat $file
82 $GETFATTR_PROG -m '^trusted\.*' --absolute-names $file | filefilter
83
84 echo "**** Verifying that chmod doesn't affect open file descriptors ****"
85 rm -f $file
86 touch $file
87 chown $qa_user $file
88 chmod ugo+w $TEST_DIR
89 su $qa_user -c "src/writemod $file" | filefilter
90 cat $file
91
92 # success, all done
93 status=0
94 exit