Standards / Extensions | C or C++ | Dependencies |
---|---|---|
POSIX.1a |
both |
#define _POSIX1_SOURCE 2
#include <unistd.h>
int seteuid(uid_t uid);
Sets the effective user ID (UID) to uid if uid is equal to the real UID or the saved set user ID of the calling process, or if the process has appropriate privileges. The real UID and the saved set UID are not changed.
The seteuid() function is not supported from an address space running multiple processes, since it would cause all processes in the address space to have their security environment changed unexpectedly.
seteuid() can be used by daemon processes to change the identity of a process in order for the process to be used to run work on behalf of a user. In z/OS® UNIX, changing the identify of a process is done by changing the real and effective UIDs and the auxiliary groups. In order to change the identity of the process on MVS™ completely, it is necessary to also change the MVS security environment. The identity change will only occur if the EUID value is specified, changing just the real UID will have no effect on the MVS environment.
When the MVS identity is changed, the auxiliary list of groups is also set to the list of groups for the new user ID.
If the seteuid() function is issued from multiple tasks within one address space, use synchronization to ensure that the seteuid() functions are not performed concurrently. The execution of seteuid() function concurrently within one address space can yield unpredictable results.
If successful, seteuid() returns 0.
⁄* CELEBS05
This example changes the effective UID.
*⁄
#define _POSIX1_SOURCE 2
#include <unistd.h>
#include <stdio.h>
main() {
printf("your effective user id is %d\n", (int) geteuid());
if (seteuid(25) != 0)
perror("seteuid() error");
else
printf("your effective user id was changed to %d\n",
(int) geteuid());
}
your effective user id is 0
your effective user id was changed to 25