I am trying to look at the source code of the passwd and gpasswd programs. These tools check the effective UID set to zero to complete execution successfully. But I am a noob to C and couldn't find the line of code that checks if the process is being run by UID == 0. I would appreciate any hints or solutions.
If you’re referring to the “shadow-utils” implementations of
passwd, you’ll find the test here:
/* * The program behaves differently when executed by root than when * executed by a normal user. */ amroot = (getuid () == 0);
gpasswd, the test is defined in two phases; first the UID is stored:
/* * Make a note of whether or not this command was invoked by root. * This will be used to bypass certain checks later on. Also, set * the real user ID to match the effective user ID. This will * prevent the invoker from issuing signals which would interfere * with this command. */ bywho = getuid ();
then that’s used in the
/* Indicate if gpasswd was called by root */ #define amroot (0 == bywho)