4 # Test permission checks in ->setattr
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2008 Christoph Hellwig.
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.
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.
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 #-----------------------------------------------------------------------
25 echo "QA output created by $seq"
29 status=1 # failure is the default!
30 trap "_cleanup_files; exit \$status" 0 1 2 3 15
31 tag="added by qa $seq"
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
41 # Create two files, one owned by root, one by the qa_user
47 chown ${qa_user}:${qa_user} test.${qa_user}
51 # Remove our files again
59 # get standard environment, filters and checks
63 # real QA test starts here
72 # make sure we have a normal umask set
78 # Test the ATTR_UID case
81 echo "testing ATTR_UID"
86 echo "user: chown root owned file to qa_user (should fail)"
87 su ${qa_user} -c "chown ${qa_user} test.root"
89 echo "user: chown root owned file to root (should fail)"
90 su ${qa_user} -c "chown root test.root"
92 echo "user: chown qa_user owned file to qa_user (should succeed)"
93 su ${qa_user} -c "chown ${qa_user} test.${qa_user}"
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}"
102 # Test the ATTR_GID case
105 echo "testing ATTR_GID"
110 echo "user: chgrp root owned file to root (should fail)"
111 su ${qa_user} -c "chgrp root test.root"
113 echo "user: chgrp qa_user owned file to root (should fail)"
114 su ${qa_user} -c "chgrp root test.${qa_user}"
116 echo "user: chgrp root owned file to qa_user (should fail)"
117 su ${qa_user} -c "chgrp ${qa_user} test.root"
119 echo "user: chgrp qa_user owned file to qa_user (should succeed)"
120 su ${qa_user} -c "chgrp ${qa_user} test.${qa_user}"
122 #echo "user: chgrp qa_user owned file to secondary group (should succeed)"
123 #su ${qa_user} -c "chgrp ${group2} test.${qa_user}"
129 # Test the ATTR_MODE case
132 echo "testing ATTR_MODE"
137 echo "user: chmod a+r on qa_user owned file (should succeed)"
138 su ${qa_user} -c "chmod a+r test.${qa_user}"
140 echo "user: chmod a+r on root owned file (should fail)"
141 su ${qa_user} -c "chmod a+r test.root"
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
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()."
155 # reg file + file's gid not in process' group set + no approp. privileges -> clear sgid
157 echo "check that the sgid bit is cleared"
158 chown ${qa_user}:root test.${qa_user}
159 chmod g+s test.${qa_user}
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}
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.
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}
178 # Now test out the clear of suid/sgid for chown
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."
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
198 echo "check that suid/sgid bits are cleared after successful chown..."
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}
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}
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}
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}
232 # Test ATTR_*TIMES_SET
235 echo "testing ATTR_*TIMES_SET"
240 echo "user: touch qa_user file (should succeed)"
241 su ${qa_user} -c "touch test.${qa_user}"
243 echo "user: touch root file (should fail)"
244 su ${qa_user} -c "touch test.root"