Set the real, effective and saved user IDs
#include <unistd.h> int setuid( uid_t uid );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The setuid() function lets the calling process set its real and effective user IDs and its saved set-user ID to its real or effective user ID, its saved set-user ID, or any user ID identified by the PROCMGR_AID_SETUID ability (see procmgr_ability()).
QNX recommends that you use seteuid() or setreuid() instead of setuid().
0 for success, or -1 if an error occurs (errno is set).
/* * This process sets its userid to 0 (root) */ #include <stdio.h> #include <sys/types.h> #include <unistd.h> #include <stdlib.h> int main( void ) { uid_t ouid; ouid = getuid(); if( setuid( 0 ) == -1 ) { perror( "setuid" ); return EXIT_FAILURE; } printf( "userid %d switched to 0\n", ouid ); return EXIT_SUCCESS; }
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |