SETUID(2)
NAME
setuid, setgid − set user and group IDs
SYNOPSIS
#include <sys/types.h>
int setuid (uid)
uid_t uid;
int setgid (gid)
gid_t gid;
DESCRIPTION
Setuid sets the real-user-ID (ruid), effective-user-ID (euid), and/or saved-user-ID (suid) of the calling process. The super-user’s euid is zero. The following conditions govern setuid’s behavior:
If the euid is zero, setuid sets the ruid, euid, and suid to uid.
If the euid is not zero, but the argument uid is equal to the ruid or the suid, setuid sets the euid to uid; the ruid and suid remain unchanged. (If a set-user-ID program is not running as super-user, it can change its euid to match its ruid and reset itself to the previous euid value.)
If the euid is not zero, but the argument uid is equal to the euid, and the calling process is a member of a group that has the PRIV_SETRUGID privilege (see privgrp(4)), setuid sets the ruid to uid; the euid and suid remain unchanged.
Setgid sets the real-group-ID (rgid), effective-group-ID (egid), and/or saved-group-ID (sgid) of the calling process. The following conditions govern setgid’s behavior:
If the euid is zero, setgid sets the rgid and egid to gid.
If the euid is not zero, but the rgid or sgid is equal to gid, and the calling process is a member of a group that has the PRIV_SETRUGID privilege (see privgrp(4)), setgid sets the egid to gid; the rgid and sgid remain unchanged.
If the euid is not zero, but the gid is equal to the egid, setgid sets the rgid to gid; the egid and sgid remain unchanged.
RETURN VALUE
Upon successful completion, a value of 0 is returned. Otherwise, a value of −1 is returned and errno is set to indicate the error.
ERRORS
Setuid and setgid fail and return −1 if either of the following is true:
[EPERM] None of the conditions above are met.
[EINVAL] Uid (gid) is not a valid user (group) ID.
WARNINGS
It is recommended that the PRIV_SETRUGID capability be avoided, as it is provided for backward compatibility. This feature may be modified or dropped from future HP-UX releases. When changing the real user ID and real group ID, use of setresuid(2) and setresgid(2) are recommended instead.
AUTHOR
Setuid was developed by AT&T, the University of California, Berkeley and HP.
Setgid was developed by AT&T.
SEE ALSO
exec(2), getprivgrp(2), getuid(2), setresuid(2) privgrp(4).
STANDARDS CONFORMANCE
setuid: SVID2, XPG2, XPG3, POSIX.1, FIPS 151-1
setgid: SVID2, XPG2, XPG3, POSIX.1, FIPS 151-1
Hewlett-Packard Company — HP-UX Release 7.0: Sept 1989