xfstests: convert tests to use new results directory
[xfstests-dev.git] / tests / generic / 193
1 #! /bin/bash
2 # FS QA Test No. 193
3 #
4 # Test permission checks in ->setattr
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2008 Christoph Hellwig.
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation.
12 #
13 # This program is distributed in the hope that it would be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 #-----------------------------------------------------------------------
22 #
23
24 seq=`basename $0`
25 seqres=$RESULT_DIR/$seq
26 seqres=$RESULT_DIR/$seq
27 seqres=$RESULT_DIR/$seq
28 echo "QA output created by $seq"
29
30 here=`pwd`
31 tmp=/tmp/$$
32 status=1        # failure is the default!
33 trap "_cleanup_files; exit \$status" 0 1 2 3 15
34 tag="added by qa $seq"
35
36 #
37 # For some tests we need a secondary group for the qa_user.  Currently
38 # that's not available in the framework, so the tests using it are
39 # commented out.
40 #
41 #group2=foo
42
43 #
44 # Create two files, one owned by root, one by the qa_user
45 #
46 _create_files()
47 {
48         touch test.root
49         touch test.${qa_user}
50         chown ${qa_user}:${qa_user} test.${qa_user}
51 }
52
53 #
54 # Remove our files again
55 #
56 _cleanup_files()
57 {
58         rm -f test.${qa_user}
59         rm -f test.root
60 }
61
62 # get standard environment, filters and checks
63 . ./common.rc
64 . ./common.filter
65
66 # real QA test starts here
67 _supported_fs generic
68 _supported_os Linux
69
70 _require_user
71 _need_to_be_root
72
73
74 #
75 # make sure we have a normal umask set
76 #
77 umask 022
78
79
80 #
81 # Test the ATTR_UID case
82 #
83 echo
84 echo "testing ATTR_UID"
85 echo
86
87 _create_files
88
89 echo "user: chown root owned file to qa_user (should fail)"
90 su ${qa_user} -c "chown ${qa_user} test.root"
91
92 echo "user: chown root owned file to root (should fail)"
93 su ${qa_user} -c "chown root test.root"
94
95 echo "user: chown qa_user owned file to qa_user (should succeed)"
96 su ${qa_user} -c "chown ${qa_user} test.${qa_user}"
97
98 # this would work without _POSIX_CHOWN_RESTRICTED
99 echo "user: chown qa_user owned file to root (should fail)"
100 su ${qa_user} -c "chown root test.${qa_user}"
101
102 _cleanup_files
103
104 #
105 # Test the ATTR_GID case
106 #
107 echo
108 echo "testing ATTR_GID"
109 echo
110
111 _create_files
112
113 echo "user: chgrp root owned file to root (should fail)"
114 su ${qa_user} -c "chgrp root test.root"
115
116 echo "user: chgrp qa_user owned file to root (should fail)"
117 su ${qa_user} -c "chgrp root test.${qa_user}"
118
119 echo "user: chgrp root owned file to qa_user (should fail)"
120 su ${qa_user} -c "chgrp ${qa_user} test.root"
121
122 echo "user: chgrp qa_user owned file to qa_user (should succeed)"
123 su ${qa_user} -c "chgrp ${qa_user} test.${qa_user}"
124
125 #echo "user: chgrp qa_user owned file to secondary group (should succeed)"
126 #su ${qa_user} -c "chgrp ${group2} test.${qa_user}"
127
128 _cleanup_files
129
130
131 #
132 # Test the ATTR_MODE case
133 #
134 echo
135 echo "testing ATTR_MODE"
136 echo
137
138 _create_files
139
140 echo "user: chmod a+r on qa_user owned file (should succeed)"
141 su ${qa_user} -c "chmod a+r test.${qa_user}"
142
143 echo "user: chmod a+r on root owned file (should fail)"
144 su ${qa_user} -c "chmod a+r test.root"
145
146 #
147 # Setup a file owned by the qa_user, but with a group ID that
148 # is not present in the qa_users group list (use root to make it easier for it)
149 # and mark it with set sgid bit
150 #
151 # From Posix (www.opengroup.org) for chmod:
152 #       "If the calling process does not have appropriate privileges, and
153 #       if the group ID of the file does not match the effective group ID
154 #       or one of the supplementary group IDs and if the file is a regular
155 #       file, bit S_ISGID (set-group-ID on execution) in the file's mode
156 #       shall be cleared upon successful return from chmod()."
157 # i.e.
158 # reg file + file's gid not in process' group set + no approp. privileges -> clear sgid
159 #
160 echo "check that the sgid bit is cleared"
161 chown ${qa_user}:root test.${qa_user}
162 chmod g+s test.${qa_user}
163
164 # and let the qa_user change permission bits
165 su ${qa_user} -c "chmod a+w test.${qa_user}"
166 stat -c '%A' test.${qa_user}
167
168 #
169 # Setup a file owned by the qa_user and with the suid bit set.
170 # A chmod by root should not clear the suid bit.
171 # There is nothing in Posix that says it should but just checking.
172 #
173 echo "check that suid bit is not cleared"
174 chmod u+s test.${qa_user}
175 chmod a+w test.${qa_user}
176 stat -c '%A' test.${qa_user}
177
178 _cleanup_files
179
180 _create_files
181 # Now test out the clear of suid/sgid for chown
182 #
183 # From Posix (www.opengroup.org) for chown:
184 #       "If the specified file is a regular file, one or more of the S_IXUSR,
185 #       S_IXGRP, or S_IXOTH bits of the file mode are set, and the process
186 #       does not have appropriate privileges, the set-user-ID (S_ISUID) and
187 #       set-group-ID (S_ISGID) bits of the file mode shall be cleared upon
188 #       successful return from chown(). If the specified file is a regular
189 #       file, one or more of the S_IXUSR, S_IXGRP, or S_IXOTH bits of the
190 #       file mode are set, and the process has appropriate privileges, it
191 #       is implementation-defined whether the set-user-ID and set-group-ID
192 #       bits are altered. If the chown() function is successfully invoked
193 #       on a file that is not a regular file and one or more of the S_IXUSR,
194 #       S_IXGRP, or S_IXOTH bits of the file mode are set, the set-user-ID
195 #       and set-group-ID bits may be cleared."
196 # i.e.
197 # reg file + exec-mode-bits set + no appropriate privileges -> clear suid,sgid
198 # reg file + exec-mode-bits set + appropriate privileges -> maybe clear suid,sgid
199 # non reg file + exec-mode-bits set + chown success on file (??) -> maybe clear suid/sgid
200 #
201 echo "check that suid/sgid bits are cleared after successful chown..."
202
203 echo "with no exec perm"
204 chmod ug+s test.${qa_user}
205 echo -n "before: "; stat -c '%A' test.${qa_user}
206 chown root test.${qa_user}
207 echo -n "after:  "; stat -c '%A' test.${qa_user}
208
209 echo "with user exec perm"
210 chmod ug+s test.${qa_user}
211 chmod u+x test.${qa_user}
212 echo -n "before: "; stat -c '%A' test.${qa_user}
213 chown root test.${qa_user}
214 echo -n "after:  "; stat -c '%A' test.${qa_user}
215
216 echo "with group exec perm"
217 chmod ug+s test.${qa_user}
218 chmod g+x test.${qa_user}
219 chmod u-x test.${qa_user}
220 echo -n "before: "; stat -c '%A' test.${qa_user}
221 chown root test.${qa_user}
222 echo -n "after:  "; stat -c '%A' test.${qa_user}
223
224 echo "with user+group exec perm"
225 chmod ug+s test.${qa_user}
226 chmod ug+x test.${qa_user}
227 echo -n "before: "; stat -c '%A' test.${qa_user}
228 chown root test.${qa_user}
229 echo -n "after:  "; stat -c '%A' test.${qa_user}
230
231 _cleanup_files
232
233
234 #
235 # Test ATTR_*TIMES_SET
236 #
237 echo
238 echo "testing ATTR_*TIMES_SET"
239 echo
240
241 _create_files
242
243 echo "user: touch qa_user file (should succeed)"
244 su ${qa_user} -c "touch test.${qa_user}"
245
246 echo "user: touch root file (should fail)"
247 su ${qa_user} -c "touch test.root"
248
249 _cleanup_files
250
251 # success, all done
252 echo "*** done"
253 rm -f $seqres.full
254 status=0