I'm going to write a code which will extensively execute other programs. I don't want it to have root privileges if someone set a set-user-id bit(and root is an owner). So I'm going to drop privileges at startup.
My question is:
How can I understand from within the program whether it run in set-user-id
mode?
You can compare result of getuid()
and geteuid()
library calls.
If geteuid()
returns 0 (root), but getuid()
returns not 0, you can say that suid is active.