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