Hi I have problem with understanding setgid on a binary executable. I know that when sgid bit is set on a binary executable file it will run with the group permission of the binary file, instead of the one who runs it.
There are lot of examples available on the internet demonstrating suid permissions, but not sgid permissions.
I was able to demonstrate suid permissions by calling a bash script from a compiled c program with suid bit set.
I have a file /tmp/1.txt which have the following permissions.
ls -l /tmp/1.txt
-rwxr----- 1 root root 5 May 31 11.50 /tmp/1.txt
As you can see, only owner & group users can read this file. I wrote a bash script '/tmp/read'
chmod u+x /tmp/read
ls -l /tmp/read
-rwxr--r-- 1 root root 28 May 31 11.50 /tmp/read
setuid( 0 );
system( "/tmp/read" );
make call call.c
chmod u+s call
ls -l call
-rwsr-xr-x 1 root root 4828 May 30 05.55 call
Now normal users can execute './tmp/call' with elevated privileges & read 1.txt.
But I am unable to do the same with sgid bit set. Can any one provide me, an example like the above script to demonstrate sgid permissions ???
Please help ...