DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

setuid(S-osr5)


setuid, setgid, seteuid, setegid, setreuid, setregid -- set user and groupIDs

Syntax

cc . . . -lc
#include <unistd.h>

int setuid(uid_t uid);

int setgid(gid_t gid);

int seteuid(uid_t euid);

int setegid(gid_t egid);

int setreuid(uid_t ruid, uid_t euid);

int setregid(gid_t rgid, uid_t egid);

Description

setuid- set user IDs

setgid- set group IDs

seteuid- set effective user IDs

setegid- set effective group IDs

setreuid- set real and effective user IDs

setregid- set real and effective group IDs

The setuid function is used to set the real user ID and effective user ID of the calling process to the same value. If the effective user ID of the calling process is root, the real user ID and effective user ID are set to uid. If the effective user ID of the calling process is not root, but its real user ID is equal to uid, the effective user ID is set to uid. If the effective user ID of the calling process is not root, but the saved set-user ID from exec(S-osr5) is equal to uid, the effective user ID is set to uid, except when the saved set-user ID from exec is root.

The setgid function precisely parallels the setuid function except that it sets group IDs rather than user IDs.

The seteuid and setegid functions precisely parallel setuid and setgid respectively, except that they set only the effective user and group IDs.

The setreuid function is used to set the real and effective user IDs of the calling process. If ruid is -1, the real user ID is not changed; if euid is -1, the effective user ID is not changed. The real and effective user IDs may be set to different values in the same call.

If the effective user ID of the calling process is root, the real user ID and the effective user ID can be set to any legal value.

If the effective user ID of the calling process is not root, the real user ID can be set to the effective user ID, or the effective user ID can be set to either the saved set-user ID from execve(S-osr5) or the real user ID. 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-user ID.

If the real user ID is changed (ruid is not -1), the saved set-user ID is changed to that same value.

The setregid function precisely parallels setreuid, except that it sets the real and effective group IDs instead of user IDs.


NOTE: These functions are also included in the current release of libsocket.

Return values

Upon successful completion, setuid, setgid, seteuid, setegid, setreuid and setregid return a value of 0. If these functions fail, the IDs are not changed, -1 is returned, and errno is set to indicate the appropriate error.

Diagnostics

If one of the following conditions occurs, the setuid, setgid, seteuid, setegid, setreuid and setregid functions fail and errno is set to the corresponding value:

[EINVAL]
The ID argument is out of range.

[EPERM]
The effective user ID is not root, and the appropriate ID of the calling process is not equal to the ID being set.

See also

exec(S-osr5), getuid(S-osr5), seteuid(SLIB)

Standards conformance

setuid, setgid, seteuid, setegid, setreuid and setregid are conformant with:

AT&T SVID Issue 2 ;
X/Open Portability Guide, Issue 3, 1989 ;
X/Open Portability Guide Issue 4, Version 2 (Spec-1170) ;
IEEE POSIX Std 1003.1-1990 System Application Program Interface (API) [C Language] (ISO/IEC 9945-1) ;
and NIST FIPS 151-1 .


© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005