1SETREGID(3P) POSIX Programmer's Manual SETREGID(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
12 setregid — set real and effective group IDs
13
15 #include <unistd.h>
16
17 int setregid(gid_t rgid, gid_t egid);
18
20 The setregid() function shall set the real and effective group IDs of
21 the calling process.
22
23 If rgid is -1, the real group ID shall not be changed; if egid is -1,
24 the effective group ID shall not be changed.
25
26 The real and effective group IDs may be set to different values in the
27 same call.
28
29 Only a process with appropriate privileges can set the real group ID
30 and the effective group ID to any valid value.
31
32 A non-privileged process can set either the real group ID to the saved
33 set-group-ID from one of the exec family of functions, or the effective
34 group ID to the saved set-group-ID or the real group ID.
35
36 If the real group ID is being set (rgid is not -1), or the effective
37 group ID is being set to a value not equal to the real group ID, then
38 the saved set-group-ID of the current process shall be set equal to the
39 new effective group ID.
40
41 Any supplementary group IDs of the calling process remain unchanged.
42
44 Upon successful completion, 0 shall be returned. Otherwise, -1 shall be
45 returned and errno set to indicate the error, and neither of the group
46 IDs are changed.
47
49 The setregid() function shall fail if:
50
51 EINVAL The value of the rgid or egid argument is invalid or out-of-
52 range.
53
54 EPERM The process does not have appropriate privileges and a change
55 other than changing the real group ID to the saved set-group-ID,
56 or changing the effective group ID to the real group ID or the
57 saved set-group-ID, was requested.
58
59 The following sections are informative.
60
62 None.
63
65 If a non-privileged set-group-ID process sets its effective group ID to
66 its real group ID, it can only set its effective group ID back to the
67 previous value if rgid was -1 in the setregid() call, since the saved-
68 group-ID is not changed in that case. If rgid was equal to the real
69 group ID in the setregid() call, then the saved set-group-ID will also
70 have been changed to the real user ID.
71
73 Earlier versions of this standard did not specify whether the saved
74 set-group-ID was affected by setregid() calls. This version specifies
75 common existing practice that constitutes an important security fea‐
76 ture. The ability to set both the effective group ID and saved set-
77 group-ID to be the same as the real group ID means that any security
78 weakness in code that is executed after that point cannot result in
79 malicious code being executed with the previous effective group ID.
80 Privileged applications could already do this using just setgid(), but
81 for non-privileged applications the only standard method available is
82 to use this feature of setregid().
83
85 None.
86
88 exec, getegid(), geteuid(), getgid(), getuid(), setegid(), seteuid(),
89 setgid(), setreuid(), setuid()
90
91 The Base Definitions volume of POSIX.1‐2017, <unistd.h>
92
94 Portions of this text are reprinted and reproduced in electronic form
95 from IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
96 table Operating System Interface (POSIX), The Open Group Base Specifi‐
97 cations Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of
98 Electrical and Electronics Engineers, Inc and The Open Group. In the
99 event of any discrepancy between this version and the original IEEE and
100 The Open Group Standard, the original IEEE and The Open Group Standard
101 is the referee document. The original Standard can be obtained online
102 at http://www.opengroup.org/unix/online.html .
103
104 Any typographical or formatting errors that appear in this page are
105 most likely to have been introduced during the conversion of the source
106 files to man page format. To report such errors, see https://www.ker‐
107 nel.org/doc/man-pages/reporting_bugs.html .
108
109
110
111IEEE/The Open Group 2017 SETREGID(3P)