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