Commit | Line | Data |
---|---|---|
15715acc KB |
1 | .\" Copyright (c) 1983, 1991, 1993 |
2 | .\" The Regents of the University of California. All rights reserved. | |
1d70186a | 3 | .\" |
ae59e04c | 4 | .\" %sccs.include.redist.man% |
1d70186a | 5 | .\" |
15715acc | 6 | .\" @(#)setuid.2 8.1 (Berkeley) %G% |
ae59e04c CL |
7 | .\" |
8 | .Dd | |
d715e838 | 9 | .Dt SETUID 2 |
ae59e04c CL |
10 | .Os BSD 4.2 |
11 | .Sh NAME | |
12 | .Nm setuid , | |
13 | .Nm seteuid , | |
ae59e04c CL |
14 | .Nm setgid , |
15 | .Nm setegid , | |
ae59e04c CL |
16 | .Nd set user and group ID |
17 | .Sh SYNOPSIS | |
18 | .Fd #include <sys/types.h> | |
ec343852 | 19 | .Fd #include <unistd.h> |
ae59e04c CL |
20 | .Ft int |
21 | .Fn setuid "uid_t uid" | |
22 | .Ft int | |
23 | .Fn seteuid "uid_t euid" | |
24 | .Ft int | |
ae59e04c CL |
25 | .Fn setgid "gid_t gid" |
26 | .Ft int | |
27 | .Fn setegid "gid_t egid" | |
ae59e04c CL |
28 | .Sh DESCRIPTION |
29 | The | |
30 | .Fn setuid | |
31 | function | |
1435cb8b KM |
32 | sets the real and effective |
33 | user IDs and the saved set-user-ID of the current process | |
34 | to the specified value. | |
35 | The | |
36 | .Fn setuid | |
37 | function is permitted if the specified ID is equal to the real user ID | |
38 | of the process, or if the effective user ID is that of the super user. | |
39 | .Pp | |
40 | The | |
41 | .Fn setgid | |
42 | function | |
43 | sets the real and effective | |
44 | group IDs and the saved set-group-ID of the current process | |
45 | to the specified value. | |
46 | The | |
47 | .Fn setgid | |
48 | function is permitted if the specified ID is equal to the real group ID | |
49 | of the process, or if the effective user ID is that of the super user. | |
ae59e04c CL |
50 | .Pp |
51 | The | |
52 | .Fn seteuid | |
53 | function | |
54 | .Pq Fn setegid | |
1d70186a KM |
55 | sets the effective user ID (group ID) of the |
56 | current process. | |
1435cb8b KM |
57 | The effective user ID may be set to the value |
58 | of the real user ID or the saved set-user-ID (see | |
59 | .Xr intro 2 | |
60 | and | |
61 | .Xr execve 2 ) ; | |
62 | in this way, the effective user ID of a set-user-ID executable | |
63 | may be toggled by switching to the real user ID, then re-enabled | |
64 | by reverting to the set-user-ID value. | |
65 | Similarly, the effective group ID may be set to the value | |
66 | of the real group ID or the saved set-user-ID. | |
ae59e04c | 67 | .Pp |
ae59e04c CL |
68 | .Sh RETURN VALUES |
69 | Upon success, these functions return 0; | |
70 | otherwise \-1 is returned. | |
71 | .Pp | |
72 | If the user is not the super user, or the uid | |
d715e838 KM |
73 | specified is not the real, effective ID, or saved ID, |
74 | these functions return \-1. | |
ae59e04c | 75 | .Sh SEE ALSO |
ae59e04c CL |
76 | .Xr getuid 2 , |
77 | .Xr getgid 2 | |
1435cb8b KM |
78 | .Sh STANDARDS |
79 | The | |
ae59e04c CL |
80 | .Fn setuid |
81 | and | |
82 | .Fn setgid | |
1435cb8b KM |
83 | functions are compliant with the |
84 | .St -p1003.1-88 | |
85 | specification with | |
86 | .Li _POSIX_SAVED_IDS | |
87 | not defined. | |
88 | The | |
89 | .Fn seteuid | |
90 | and | |
91 | .Fn setegid | |
92 | functions are extensions based on the | |
93 | .Tn POSIX | |
94 | concept of | |
95 | .Li _POSIX_SAVED_IDS , | |
96 | and have been proposed for a future revision of the standard. |