xref: /openbsd/lib/libc/sys/setregid.2 (revision 17df1aa7)
1.\" $OpenBSD: setregid.2,v 1.6 2008/08/04 07:08:23 jmc Exp $
2.\"
3.\" Copyright (c) 1980, 1991, 1993, 1994
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. Neither the name of the University nor the names of its contributors
15.\"    may be used to endorse or promote products derived from this software
16.\"    without specific prior written permission.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE.
29.\"
30.\"     @(#)setregid.2	8.2 (Berkeley) 4/16/94
31.\"
32.Dd $Mdocdate: August 4 2008 $
33.Dt SETREGID 2
34.Os
35.Sh NAME
36.Nm setregid
37.Nd set real and effective group IDs
38.Sh SYNOPSIS
39.Fd #include <unistd.h>
40.Ft int
41.Fn setregid "gid_t rgid" "gid_t egid"
42.Sh DESCRIPTION
43The real and effective group IDs of the current process
44are set according to the arguments.
45The saved group ID will be set to the new value of the real group
46ID if a real group ID is specified and either
47the new real group ID value is different from the current value
48or the effective group ID is changed to a value other than the
49current saved group ID.
50.Pp
51Unprivileged users may change either group ID to the current value
52of the real, effective, or saved group ID.
53Only the superuser may make other changes.
54.Pp
55Supplying a value of -1 for either the real or effective
56group ID forces the system to substitute the current
57ID in place of the -1 parameter.
58.Pp
59The
60.Fn setregid
61function was intended to allow swapping the real and
62effective group IDs in set-group-ID programs to temporarily relinquish
63the set-group-ID value.
64This purpose is now better served by the use of the
65.Xr setegid 2
66function.
67.Pp
68When setting the real and effective group IDs to the same value, the
69.Xr setgid 2
70function is preferred.
71.Sh RETURN VALUES
72Upon successful completion, a value of 0 is returned.
73Otherwise, a value of -1 is returned and
74.Va errno
75is set to indicate the error.
76.Sh ERRORS
77.Bl -tag -width Er
78.It Bq Er EPERM
79The current process is not the superuser and a change
80other than changing the effective group ID to the real group ID
81was specified.
82.El
83.Sh SEE ALSO
84.Xr getgid 2 ,
85.Xr setegid 2 ,
86.Xr setgid 2 ,
87.Xr setresgid 2 ,
88.Xr setreuid 2
89.Sh STANDARDS
90The
91.Fn setregid
92function conforms to the
93.St -p1003.1-2001
94and
95.St -xpg4.3 .
96specifications.
97.Pp
98Note, however, that prior to
99.St -p1003.1-2001 ,
100the
101.Fn setregid
102function was not a part of the
103.St -p1003.1
104specification.
105As a result, it may not be implemented on all systems.
106.Sh HISTORY
107The
108.Fn setregid
109function call appeared in
110.Bx 4.2 .
111A semantically different version appeared in
112.Bx 4.4 .
113The current version, with the original semantics restored, appeared in
114.Ox 3.3 .
115.Sh CAVEATS
116The
117.Fn setregid
118function predates
119.Tn POSIX
120saved group IDs.
121This implementation changes the saved group ID to the new value of
122the real group ID only if the real group ID is specified and either
123changed
124or the effective group ID is changed to a value other than the current
125saved group ID.
126Other implementations may behave differently.
127