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 #-----------------------------------------------------------------------
27 echo "QA output created by $seq"
31 status=1 # failure is the default!
32 trap "_cleanup_files; exit \$status" 0 1 2 3 15
33 tag="added by qa $seq"
36 # For some tests we need a secondary group for the qa_user. Currently
37 # that's not available in the framework, so the tests using it are
43 # Create two files, one owned by root, one by the qa_user
49 chown ${qa_user}:${qa_user} test.${qa_user}
53 # Remove our files again
61 # get standard environment, filters and checks
65 # real QA test starts here
74 # make sure we have a normal umask set
80 # Test the ATTR_UID case
83 echo "testing ATTR_UID"
88 echo "user: chown root owned file to qa_user (should fail)"
89 su ${qa_user} -c "chown ${qa_user} test.root"
91 echo "user: chown root owned file to root (should fail)"
92 su ${qa_user} -c "chown root test.root"
94 echo "user: chown qa_user owned file to qa_user (should succeed)"
95 su ${qa_user} -c "chown ${qa_user} test.${qa_user}"
97 # this would work without _POSIX_CHOWN_RESTRICTED
98 echo "user: chown qa_user owned file to root (should fail)"
99 su ${qa_user} -c "chown root test.${qa_user}"
104 # Test the ATTR_GID case
107 echo "testing ATTR_GID"
112 echo "user: chgrp root owned file to root (should fail)"
113 su ${qa_user} -c "chgrp root test.root"
115 echo "user: chgrp qa_user owned file to root (should fail)"
116 su ${qa_user} -c "chgrp root test.${qa_user}"
118 echo "user: chgrp root owned file to qa_user (should fail)"
119 su ${qa_user} -c "chgrp ${qa_user} test.root"
121 echo "user: chgrp qa_user owned file to qa_user (should succeed)"
122 su ${qa_user} -c "chgrp ${qa_user} test.${qa_user}"
124 #echo "user: chgrp qa_user owned file to secondary group (should succeed)"
125 #su ${qa_user} -c "chgrp ${group2} test.${qa_user}"
131 # Test the ATTR_MODE case
134 echo "testing ATTR_MODE"
139 echo "user: chmod a+r on qa_user owned file (should succeed)"
140 su ${qa_user} -c "chmod a+r test.${qa_user}"
142 echo "user: chmod a+r on root owned file (should fail)"
143 su ${qa_user} -c "chmod a+r test.root"
146 # Setup a file owned by the qa_user, but with a group ID that
147 # is not present in the qa_users group list (use root to make it easier for it)
148 # and mark it with set sgid bit
150 # From Posix (www.opengroup.org) for chmod:
151 # "If the calling process does not have appropriate privileges, and
152 # if the group ID of the file does not match the effective group ID
153 # or one of the supplementary group IDs and if the file is a regular
154 # file, bit S_ISGID (set-group-ID on execution) in the file's mode
155 # shall be cleared upon successful return from chmod()."
157 # reg file + file's gid not in process' group set + no approp. privileges -> clear sgid
159 echo "check that the sgid bit is cleared"
160 chown ${qa_user}:root test.${qa_user}
161 chmod g+s test.${qa_user}
163 # and let the qa_user change permission bits
164 su ${qa_user} -c "chmod a+w test.${qa_user}"
165 stat -c '%A' test.${qa_user}
168 # Setup a file owned by the qa_user and with the suid bit set.
169 # A chmod by root should not clear the suid bit.
170 # There is nothing in Posix that says it should but just checking.
172 echo "check that suid bit is not cleared"
173 chmod u+s test.${qa_user}
174 chmod a+w test.${qa_user}
175 stat -c '%A' test.${qa_user}
180 # Now test out the clear of suid/sgid for chown
182 # From Posix (www.opengroup.org) for chown:
183 # "If the specified file is a regular file, one or more of the S_IXUSR,
184 # S_IXGRP, or S_IXOTH bits of the file mode are set, and the process
185 # does not have appropriate privileges, the set-user-ID (S_ISUID) and
186 # set-group-ID (S_ISGID) bits of the file mode shall be cleared upon
187 # successful return from chown(). If the specified file is a regular
188 # file, one or more of the S_IXUSR, S_IXGRP, or S_IXOTH bits of the
189 # file mode are set, and the process has appropriate privileges, it
190 # is implementation-defined whether the set-user-ID and set-group-ID
191 # bits are altered. If the chown() function is successfully invoked
192 # on a file that is not a regular file and one or more of the S_IXUSR,
193 # S_IXGRP, or S_IXOTH bits of the file mode are set, the set-user-ID
194 # and set-group-ID bits may be cleared."
196 # reg file + exec-mode-bits set + no appropriate privileges -> clear suid,sgid
197 # reg file + exec-mode-bits set + appropriate privileges -> maybe clear suid,sgid
198 # non reg file + exec-mode-bits set + chown success on file (??) -> maybe clear suid/sgid
200 echo "check that suid/sgid bits are cleared after successful chown..."
202 echo "with no exec perm"
203 chmod ug+s test.${qa_user}
204 echo -n "before: "; stat -c '%A' test.${qa_user}
205 chown root test.${qa_user}
206 echo -n "after: "; stat -c '%A' test.${qa_user}
208 echo "with user exec perm"
209 chmod ug+s test.${qa_user}
210 chmod u+x test.${qa_user}
211 echo -n "before: "; stat -c '%A' test.${qa_user}
212 chown root test.${qa_user}
213 echo -n "after: "; stat -c '%A' test.${qa_user}
215 echo "with group exec perm"
216 chmod ug+s test.${qa_user}
217 chmod g+x test.${qa_user}
218 chmod u-x test.${qa_user}
219 echo -n "before: "; stat -c '%A' test.${qa_user}
220 chown root test.${qa_user}
221 echo -n "after: "; stat -c '%A' test.${qa_user}
223 echo "with user+group exec perm"
224 chmod ug+s test.${qa_user}
225 chmod ug+x test.${qa_user}
226 echo -n "before: "; stat -c '%A' test.${qa_user}
227 chown root test.${qa_user}
228 echo -n "after: "; stat -c '%A' test.${qa_user}
234 # Test ATTR_*TIMES_SET
237 echo "testing ATTR_*TIMES_SET"
242 echo "user: touch qa_user file (should succeed)"
243 su ${qa_user} -c "touch test.${qa_user}"
245 echo "user: touch root file (should fail)"
246 su ${qa_user} -c "touch test.root"