1SETUID(2)                  Linux Programmer's Manual                 SETUID(2)
2
3
4

NAME

6       setuid - set user identity
7

SYNOPSIS

9       #include <sys/types.h>
10       #include <unistd.h>
11
12       int setuid(uid_t uid);
13

DESCRIPTION

15       setuid()  sets  the  effective  user ID of the current process.  If the
16       effective UID of the caller is root, the real UID and saved set-user-ID
17       are also set.
18
19       Under  Linux,  setuid()  is implemented like the POSIX version with the
20       _POSIX_SAVED_IDS feature.  This allows a set-user-ID (other than  root)
21       program to drop all of its user privileges, do some un-privileged work,
22       and then re-engage the original effective user ID in a secure manner.
23
24       If the user is root or the program is  set-user-ID-root,  special  care
25       must  be  taken.  The setuid() function checks the effective user ID of
26       the caller and if it is the superuser, all process  related  user  ID's
27       are set to uid.  After this has occurred, it is impossible for the pro‐
28       gram to regain root privileges.
29
30       Thus, a set-user-ID-root program wishing to temporarily drop root priv‐
31       ileges,  assume  the  identity of a non-root user, and then regain root
32       privileges afterwards cannot use setuid().   You  can  accomplish  this
33       with the (non-POSIX, BSD) call seteuid().
34

RETURN VALUE

36       On  success,  zero is returned.  On error, -1 is returned, and errno is
37       set appropriately.
38

ERRORS

40       EAGAIN The uid does not match the current uid and  uid  brings  process
41              over it's NPROC rlimit.
42
43       EPERM  The  user is not privileged (Linux: does not have the CAP_SETUID
44              capability) and uid does not match the real UID  or  saved  set-
45              user-ID of the calling process.
46

CONFORMING TO

48       SVr4,  POSIX.1-2001.   Not quite compatible with the 4.4BSD call, which
49       sets all of the real, saved, and effective user IDs.
50

LINUX-SPECIFIC REMARKS

52       Linux has the concept of filesystem user  ID,  normally  equal  to  the
53       effective  user ID.  The setuid() call also sets the filesystem user ID
54       of the current process.  See setfsuid(2).
55
56       If uid is different from the old effective uid,  the  process  will  be
57       forbidden from leaving core dumps.
58

SEE ALSO

60       getuid(2), seteuid(2), setfsuid(2), setreuid(2), capabilities(7)
61
62
63
64Linux 2.6.6                       2004-05-27                         SETUID(2)
Impressum