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 seqres=$RESULT_DIR/$seq
26 seqres=$RESULT_DIR/$seq
27 seqres=$RESULT_DIR/$seq
28 echo "QA output created by $seq"
32 status=1 # failure is the default!
33 trap "_cleanup_files; exit \$status" 0 1 2 3 15
34 tag="added by qa $seq"
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
44 # Create two files, one owned by root, one by the qa_user
50 chown ${qa_user}:${qa_user} test.${qa_user}
54 # Remove our files again
62 # get standard environment, filters and checks
66 # real QA test starts here
75 # make sure we have a normal umask set
81 # Test the ATTR_UID case
84 echo "testing ATTR_UID"
89 echo "user: chown root owned file to qa_user (should fail)"
90 su ${qa_user} -c "chown ${qa_user} test.root"
92 echo "user: chown root owned file to root (should fail)"
93 su ${qa_user} -c "chown root test.root"
95 echo "user: chown qa_user owned file to qa_user (should succeed)"
96 su ${qa_user} -c "chown ${qa_user} test.${qa_user}"
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}"
105 # Test the ATTR_GID case
108 echo "testing ATTR_GID"
113 echo "user: chgrp root owned file to root (should fail)"
114 su ${qa_user} -c "chgrp root test.root"
116 echo "user: chgrp qa_user owned file to root (should fail)"
117 su ${qa_user} -c "chgrp root test.${qa_user}"
119 echo "user: chgrp root owned file to qa_user (should fail)"
120 su ${qa_user} -c "chgrp ${qa_user} test.root"
122 echo "user: chgrp qa_user owned file to qa_user (should succeed)"
123 su ${qa_user} -c "chgrp ${qa_user} test.${qa_user}"
125 #echo "user: chgrp qa_user owned file to secondary group (should succeed)"
126 #su ${qa_user} -c "chgrp ${group2} test.${qa_user}"
132 # Test the ATTR_MODE case
135 echo "testing ATTR_MODE"
140 echo "user: chmod a+r on qa_user owned file (should succeed)"
141 su ${qa_user} -c "chmod a+r test.${qa_user}"
143 echo "user: chmod a+r on root owned file (should fail)"
144 su ${qa_user} -c "chmod a+r test.root"
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
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()."
158 # reg file + file's gid not in process' group set + no approp. privileges -> clear sgid
160 echo "check that the sgid bit is cleared"
161 chown ${qa_user}:root test.${qa_user}
162 chmod g+s test.${qa_user}
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}
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.
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}
181 # Now test out the clear of suid/sgid for chown
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."
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
201 echo "check that suid/sgid bits are cleared after successful chown..."
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}
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}
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}
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}
235 # Test ATTR_*TIMES_SET
238 echo "testing ATTR_*TIMES_SET"
243 echo "user: touch qa_user file (should succeed)"
244 su ${qa_user} -c "touch test.${qa_user}"
246 echo "user: touch root file (should fail)"
247 su ${qa_user} -c "touch test.root"