1.\" $OpenBSD: setregid.2,v 1.3 2004/01/25 14:48:32 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 January 29, 2003 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. 45If the real group ID is changed, the saved group ID is changed to the 46new value of the effective group ID. 47.Pp 48Unprivileged users may change either group ID to the current value 49of the real, effective, or saved group ID. 50Only the superuser may make other changes. 51.Pp 52Supplying a value of -1 for either the real or effective 53group ID forces the system to substitute the current 54ID in place of the -1 parameter. 55.Pp 56The 57.Fn setregid 58function was intended to allow swapping the real and 59effective group IDs in set-group-ID programs to temporarily relinquish 60the set-group-ID value. 61This purpose is now better served by the use of the 62.Fn setegid 63function (see 64.Xr setuid 2 ) . 65.Pp 66When setting the real and effective group IDs to the same value, the 67.Fn setgid 68function is preferred. 69.Sh RETURN VALUES 70Upon successful completion, a value of 0 is returned. 71Otherwise, a value of -1 is returned and 72.Va errno 73is set to indicate the error. 74.Sh ERRORS 75.Bl -tag -width Er 76.It Bq Er EPERM 77The current process is not the superuser and a change 78other than changing the effective group ID to the real group ID 79was specified. 80.El 81.Sh SEE ALSO 82.Xr getgid 2 , 83.Xr setegid 2 , 84.Xr setgid 2 , 85.Xr setresgid 2 , 86.Xr setuid 2 87.Sh STANDARDS 88The 89.Fn setregid 90function conforms to the 91.St -p1003.1-2001 92and 93.St -xpg4.3 . 94specifications. 95.Pp 96Note, however, that prior to 97.St -p1003.1-2001 , 98the 99.Fn setregid 100function was not a part of the 101.St -p1003.1 102specification. 103As a result, it may not be implemented on all systems. 104.Sh HISTORY 105The 106.Fn setregid 107function call appeared in 108.Bx 4.2 . 109A semantically different version appeared in 110.Bx 4.4 . 111The current version, with the original semantics restored, appeared in 112.Ox 3.3 . 113.Sh CAVEATS 114The 115.Fn setregid 116function predates 117.Tn POSIX 118saved group IDs. 119This implementation changes the saved group ID to the new value of 120the effective group ID if the real group ID is changed. 121Other implementations may behave differently. 122