Setting User ID

The real and effective user IDs can be changed under the correct conditions. These UNIX functions are strictly controlled because they change the accountability and the access of the calling process involved.

The setuid(2) function permits the real user ID to be changed. seteuid(2) allows the effective user ID to be altered. The function synopsis for both is as follows:

#include <sys/types.h>
#include <unistd.h>

int setuid(uid_t uid);

int seteuid(uid_t euid);

These functions return 0 when successful and -1 if they fail. The value of errno will be set when the call fails (errors EPERM or EINVAL can be returned).

Note

EPERM—Operation Not Permitted This Operation Not Permitted error> Operation Not Permitted error> error states ...

Get Advanced UNIX Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.