Set the effective user ID
Synopsis:
#include <unistd.h>
int seteuid( uid_t uid );
Arguments:
- uid
- The effective user ID that you want to use for the process.
Library:
libc
Use the -l c option to
qcc
to link against this library.
This library is usually included automatically.
Description:
The seteuid() function lets the calling process set the
effective user ID, based on the following:
- If the process has the PROCMGR_AID_SETUID ability
enabled (see
procmgr_ability()),
the seteuid() function
sets the effective user ID to uid.
- If the process doesn't have the PROCMGR_AID_SETUID ability
enabled, but
uid is equal
to the real user ID or saved set-user ID, seteuid() sets
the effective user ID to uid.
The real and saved user IDs aren't changed.
Note:
If a set-UID process sets its effective user ID to its real user ID,
it can still set its effective user ID back to the saved set-UID.
Returns:
- 0
- Success.
- -1
- An error occurred
(errno
is set).
Errors:
- EINVAL
- The value of uid is out of range.
- EPERM
- The process doesn't have the PROCMGR_AID_SETUID ability
enabled, and uid doesn't
match the real user ID or the saved set-user ID.
Examples:
/*
* This process sets its effective userid to 0 (root).
*/
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
int main( void )
{
uid_t oeuid;
oeuid = geteuid();
if( seteuid( 0 ) == -1 ) {
perror( "seteuid" );
return EXIT_FAILURE;
}
printf( "effective userid now 0, was %d\n",
oeuid );
return EXIT_SUCCESS;
}
Classification:
POSIX 1003.1
Safety: |
|
Cancellation point |
No |
Interrupt handler |
No |
Signal handler |
Yes |
Thread |
Yes |