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