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