chmod not returning right exit code on SGID directory failure
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
coreutils (Ubuntu) |
Triaged
|
Low
|
Unassigned |
Bug Description
chmod is not setting the correct exit code upon SGID directory failure. For example, follow along below. This not only affects Ubuntu, but I assume Linux in general, as I've duplicated the bug on Debian and Red Hat, the two largest forked distros.
aaron@kratos:~$ mkdir ~/tmp
aaron@kratos:~$ ls -ld ~/tmp
drwxr-xr-x 2 aaron aaron 4096 2008-01-30 07:24 /home/aaron/tmp
aaron@kratos:~$ sudo chown .root ~/tmp
Password or swipe finger:
aaron@kratos:~$ ls -ld ~/tmp
drwxr-xr-x 2 aaron root 4096 2008-01-30 07:24 /home/aaron/tmp
aaron@kratos:~$ chmod g+s ~/tmp
aaron@kratos:~$ ls -ld ~/tmp
drwxr-xr-x 2 aaron root 4096 2008-01-30 07:24 /home/aaron/tmp
aaron@kratos:~$ chmod g+s ~/tmp
aaron@kratos:~$ echo $?
0
Obviously, it's not setting the SGID (drwxr-sr-x), as I am not a member of the 'root' group. This is expected behavior. However, it's also not sending a permission denied error to STDERR as I would expect. As we can see from the exit status, it is telling me, by returning a zero, that it has succeeded, which of course it hasn't.
description: | updated |
As described in info page, that behaviour could be expected somehow:
" A successful use of `chmod' clears the set-group-ID bit of a regular
file if the file's group ID does not match the user's effective group
ID or one of the user's supplementary group IDs, unless the user has
appropriate privileges. Additional restrictions may cause the
set-user-ID and set-group-ID bits of MODE or REF_FILE to be ignored.
This behavior depends on the policy and functionality of the underlying
`chmod' system call. When in doubt, check the underlying system
behavior."
Anyway, I agree that this behaviour is confusing and user should be informed, that chmod used different mode than requested. I proposed that change to upstream at http:// lists.gnu. org/archive/ html/bug- coreutils/ 2008-10/ msg00273. html (hopefully is the link correct, message was not reachable from archive list at the moment of the post).