xfstests: test ext4 statfs
[xfstests-dev.git] / 093
1 #! /bin/bash
2 # FS QA Test No. 093
3 #
4 # Test out for IRIX the removal of file capabilities when
5 # writing to the file (when it doesn't have CAP_FSETID & CAP_SETFCAP)
6 # i.e. not root.
7 # Test out fix for pv#901019
8 #
9 #-----------------------------------------------------------------------
10 # Copyright (c) 2000-2004 Silicon Graphics, Inc.  All Rights Reserved.
11 #
12 # This program is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License as
14 # published by the Free Software Foundation.
15 #
16 # This program is distributed in the hope that it would be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write the Free Software Foundation,
23 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
24 #
25 #-----------------------------------------------------------------------
26 #
27 # creator
28 owner=tes@sgi.com
29
30 seq=`basename $0`
31
32 here=`pwd`
33 tmp=/tmp/$$
34 runas=$here/src/runas
35 status=1        # FAILure is the default!
36 trap "_cleanup; exit \$status" 0 1 2 3 15
37
38 # get standard environment, filters and checks
39 . ./common.rc
40 . ./common.filter
41 . ./common.attr
42
43 _cleanup()
44 {
45     [ -n "$testdir" ] && rm -f $file
46     _cleanup_testdir
47 }
48
49 _testfilter()
50 {
51     sed -e "s#$testdir#TESTDIR#g"
52 }
53
54 _filefilter()
55 {
56     sed -e "s#$tmp##" -e "s#$file#file#"
57 }
58
59 # real QA test starts here
60 _supported_fs generic
61 _supported_os IRIX
62
63 _require_attrs
64
65 [ -x $runas ] || _notrun "$runas executable not found"
66
67 rm -f $seq.full
68
69 _setup_testdir
70 _need_to_be_root
71
72 echo "QA output created by $seq"
73 echo ""
74 file=$testdir/$seq.file
75
76 user=`grep ':all=:all=' /etc/capability | tail -1 | $AWK_PROG -F: '{print $1}'`
77 uid=`_cat_passwd | grep $user | $AWK_PROG -F: '{print $3}'`
78
79 cat >$tmp.append <<EOF
80 #!/bin/bash
81 echo data >>$file
82 EOF
83 chmod ugo+x $tmp.append
84
85 echo "touch file"
86 touch $file
87 chmod ugo+w $file 
88
89 echo "chcap on file"
90 chcap CAP_CHOWN+p $file
91
92 echo "ls -P on file"
93 ls -P $file | _testfilter
94
95 echo "append to file as root"
96 $tmp.append
97
98 echo "ls -P on file"
99 ls -P $file | _testfilter
100
101 echo "cat file"
102 echo "----"
103 cat $file
104 echo "----"
105
106 echo "append to file as user without caps"
107 # in particular user doesn't have FSETID or SETFCAP
108 $runas -u $uid $tmp.append
109
110 echo "cat file"
111 echo "----"
112 cat $file
113 echo "----"
114
115 echo "ls -P on file"
116 ls -P $file | _testfilter
117
118 # try again when it doesn't have the EA
119 echo "append to file as user without caps a 2nd time"
120 $runas -u $uid $tmp.append
121
122 echo "ls -P on file"
123 ls -P $file | _testfilter
124
125 echo "cat file"
126 echo "----"
127 cat $file
128 echo "----"
129
130 echo "only let root write to file"
131 chmod 700 $file
132 chown root $file 
133
134 echo "as non-root try to append to file"
135 $runas -u $uid $tmp.append 2>&1 | _filefilter
136
137 echo "restore perms on file"
138 chmod 777 $file
139
140 echo "set a root EA on file"
141 ${ATTR_PROG} -R -s test -V testval $file | _filefilter
142
143 echo "list EA on file"
144 ${ATTR_PROG} -R -l $file | _filefilter
145
146 echo "as non-root try to append to file"
147 $runas -u $uid $tmp.append 2>&1 | _filefilter
148
149 echo "list EA on file"
150 ${ATTR_PROG} -R -l $file | _filefilter
151
152 chown $uid $file
153 chmod ugo+w $testdir
154 echo "as non-root call writemod"
155 $runas -u $uid src/writemod $file 2>&1 | _filefilter
156
157 echo "cat file"
158 echo "----"
159 cat $file
160 echo "----"
161
162 # success, all done
163 status=0
164 exit