generic: shutdown fs after log recovery
[xfstests-dev.git] / tests / generic / 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
28 seq=`basename $0`
29 seqres=$RESULT_DIR/$seq
30
31 here=`pwd`
32 tmp=/tmp/$$
33 status=1        # FAILure is the default!
34 trap "_cleanup; exit \$status" 0 1 2 3 15
35
36 # get standard environment, filters and checks
37 . ./common/rc
38 . ./common/filter
39 . ./common/attr
40
41 _cleanup()
42 {
43     [ -n "$TEST_DIR" ] && rm -f $file
44 }
45
46 _testfilter()
47 {
48     sed -e "s#$TEST_DIR#TESTDIR#g"
49 }
50
51 _filefilter()
52 {
53     sed -e "s#$tmp##" -e "s#$file#file#"
54 }
55
56 # real QA test starts here
57 _supported_fs generic
58 _supported_os IRIX
59
60 _require_test
61 _require_attrs
62 _require_runas
63
64 rm -f $seqres.full
65
66 echo "QA output created by $seq"
67 echo ""
68 file=$TEST_DIR/$seq.file
69
70 user=`grep ':all=:all=' /etc/capability | tail -1 | $AWK_PROG -F: '{print $1}'`
71 uid=`_cat_passwd | grep $user | $AWK_PROG -F: '{print $3}'`
72
73 cat >$tmp.append <<EOF
74 #!/bin/bash
75 echo data >>$file
76 EOF
77 chmod ugo+x $tmp.append
78
79 echo "touch file"
80 touch $file
81 chmod ugo+w $file 
82
83 echo "chcap on file"
84 chcap CAP_CHOWN+p $file
85
86 echo "ls -P on file"
87 ls -P $file | _testfilter
88
89 echo "append to file as root"
90 $tmp.append
91
92 echo "ls -P on file"
93 ls -P $file | _testfilter
94
95 echo "cat file"
96 echo "----"
97 cat $file
98 echo "----"
99
100 echo "append to file as user without caps"
101 # in particular user doesn't have FSETID or SETFCAP
102 _runas -u $uid $tmp.append
103
104 echo "cat file"
105 echo "----"
106 cat $file
107 echo "----"
108
109 echo "ls -P on file"
110 ls -P $file | _testfilter
111
112 # try again when it doesn't have the EA
113 echo "append to file as user without caps a 2nd time"
114 _runas -u $uid $tmp.append
115
116 echo "ls -P on file"
117 ls -P $file | _testfilter
118
119 echo "cat file"
120 echo "----"
121 cat $file
122 echo "----"
123
124 echo "only let root write to file"
125 chmod 700 $file
126 chown root $file 
127
128 echo "as non-root try to append to file"
129 _runas -u $uid $tmp.append 2>&1 | _filefilter
130
131 echo "restore perms on file"
132 chmod 777 $file
133
134 echo "set a root EA on file"
135 ${ATTR_PROG} -R -s test -V testval $file | _filefilter
136
137 echo "list EA on file"
138 ${ATTR_PROG} -R -l $file | _filefilter
139
140 echo "as non-root try to append to file"
141 _runas -u $uid $tmp.append 2>&1 | _filefilter
142
143 echo "list EA on file"
144 ${ATTR_PROG} -R -l $file | _filefilter
145
146 chown $uid $file
147 chmod ugo+w $TEST_DIR
148 echo "as non-root call writemod"
149 _runas -u $uid src/writemod $file 2>&1 | _filefilter
150
151 echo "cat file"
152 echo "----"
153 cat $file
154 echo "----"
155
156 # success, all done
157 status=0
158 exit