setuid(S) 6 January 1993 setuid(S) Name setuid, setgid - set user and groupIDs Syntax cc . . . -lc int setuid (uid) uid_t uid; int setgid (gid) gid_t gid; Description The setuid routine is used to set the real user ID and effective user ID of the calling process. 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) 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 routine precisely parallels the setuid routine except that it sets group IDs rather than user IDs. The setgid routine is used to set the real group ID and effective group ID of the calling process. If the effective user ID of the calling pro- cess is root, the real group ID and effective group ID are set to gid. If the effective user ID of the calling process is not root, but its real group ID is equal to gid, the effective group ID is set to gid. If the effective user ID of the calling process is not root, but the saved set- group ID from exec(S) is equal to gid, the effective group ID is set to gid. Return value Upon successful completion, setuid and setgid return a value of 0. If these routines fail, they return a value of -1 and errno is set to indi- cate the appropriate error. Diagnostics If one of the following conditions occurs, the setuid (setgid) routine fails and errno is set to the corresponding value: [EINVAL] The uid (gid) is out of range. [EPERM] The real user (group) ID of the calling process is not equal to uid (gid) and its effective user ID is not root. See also getuid(S) Standards conformance setgid and setuid are conformant with: AT&T SVID Issue 2; X/Open Portability Guide, Issue 3, 1989; IEEE POSIX Std 1003.1-1990 System Application Program Interface (API) [C Language] (ISO/IEC 9945-1); and NIST FIPS 151-1.