I have a Solaris 10 system:# uname -aSunOS edddev03 5.10 Generic_150400-04 sun4v sparc SUNW,SPARC-Enterprise-T5120I wrote a program printing the uid:# cat getuid.cint main (void) {  printf (%d\n, getuid());}It works as expected:# gcc -o /bin/getuid getuid.c# getuid0# su nobody -c /bin/getuid60001Now I changed it to be a setuid program:# chmod 4555 /bin/getuid# ls -la /bin/getuid-r-sr-xr-x   1 root     root        6424 May 18 13:04 /bin/getuidBut it is not working as expected:# su nobody -c /bin/getuid60001I expected a 0. Why is it not working?
How to run a setuid program on Solaris 10?
solaris;setuid
I found this Q still-unanswered; G-Man and Bratchley have pointed out the error; getuid() returns the real user ID of the calling process while geteuid() returns the effective user ID of the calling process.You can see the difference with this program:#include <stdio.h>#include <sys/types.h>#include <unistd.h>int main (void) {  printf (getuid=%d, geteuid=%d\n, getuid(), geteuid());  setuid(geteuid());  printf (getuid=%d, geteuid=%d\n, getuid(), geteuid());}$ gcc -o getuid getuid.c$ sudo chown root getuid$ sudo chmod u+s getuid$ su nobody -c ./getuidgetuid=60001, geteuid=0getuid=0, geteuid=0