gtpc2m6g | C/C++ Language Support User's Guide |
This function sets the real, effective, or saved set-user-IDs (UIDs) for the current process to uid.
Format
#include <unistd.h> int setuid(uid_t uid);
Normal Return
If successful, the setuid function returns 0 and sets the real, effective, or saved set-user-IDs for the current process to uid.
Error Return
If unsuccessful, the setuid function returns -1 and sets errno to one of the following:
Programming Considerations
The appropriate privileges are when the calling program has the key 0 macro option set on in the PAT or when the process is superuser.
Examples
The following example changes the real, effective, and saved-set-UIDs.
#include <unistd.h> #include <stdio.h> int main(void) { printf ( "prior to setuid(), uid = %d, effective uid = %d\n" (int) getuid(), (int) geteuid() ); if ( setuid(25) != 0 ) perror( "setuid() error" ); else printf ( "after setuid(), uid = %d, effective uid = %d\n", (int) getuid(), (int) geteuid() ); return 0; }
Related Information