![]() |
![]() |
![]() |
set the real, effective and saved user IDs
#include <unistd.h> int setuid( uid_t uid );
The setuid() function allows the calling process to set the real, effective and saved user IDs based on the following:
If you wish to change only the effective user ID, even if you have appropriate privileges, you should consider using the seteuid() function.
/* * this process sets its userid to 0 (root) */ #include <stdio.h> #include <sys/types.h> #include <unistd.h> #include <stdlib.h> void main() { uid_t ouid; ouid = getuid(); if( setuid( 0 ) == -1 ) { perror( "setuid" ); exit( EXIT_FAILURE ); } printf( "userid %d switched to 0\n", ouid ); exit( EXIT_SUCCESS ); }
POSIX 1003.1
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | Yes, but modifies errno |
Thread | Yes |
errno, setegid(), seteuid(), setgid()
![]() |
![]() |
![]() |