There's something really weird happening with permissions on a directory in linux. I have the directory /dir
Code:
ls -ld /dir
drwxrwxrwx. 2 root root 4096 Jan 8 00:06 dir
chmod 2777 /dir [this sets the setgid bit on]
ls -ld /dir
drwxrwsrwx. 2 root root 4096 Jan 8 00:06 /dir
And this is what I expect it to do.
However, when I change it to setid (WITHOUT setgid), it simply doesn't work. Instead of overwriting, it cumulates:
Code:
chmod 4777 /dir [for setting setuid bit on]
drwsrwsrwx. 2 root root 4096 Jan 8 00:06 /dir
As you can see, the setgid bit is still on together with the setuid! However, if I run:
Code:
chmod -s /dir
then the file has a 0777 permission.
And then again, if I change its permission to 4777 (so setuid):
Code:
chmod 4777 /dir
drwsrwxrwx. 2 root root 4096 Jan 8 00:06 /dir
it acts normally. So the same chmod 4777 acts differently in two different contexts.
I really can't understand it. Basically, I cannot get rid of the setuid/setgid through binary permissions. The sticky bit works fine. Changing from 1777 to 0777 adds and removes "t" respectively. What am I to make of all this? This behaviour makes no sense to make especially given that we can change the permissions to 6777 (setuid + setgid).