1*4f1223e8SApple OSS Distributions.\" $NetBSD: setuid.2,v 1.3 1995/02/27 12:37:06 cgd Exp $ 2*4f1223e8SApple OSS Distributions.\" 3*4f1223e8SApple OSS Distributions.\" Copyright (c) 1983, 1991, 1993 4*4f1223e8SApple OSS Distributions.\" The Regents of the University of California. All rights reserved. 5*4f1223e8SApple OSS Distributions.\" 6*4f1223e8SApple OSS Distributions.\" Redistribution and use in source and binary forms, with or without 7*4f1223e8SApple OSS Distributions.\" modification, are permitted provided that the following conditions 8*4f1223e8SApple OSS Distributions.\" are met: 9*4f1223e8SApple OSS Distributions.\" 1. Redistributions of source code must retain the above copyright 10*4f1223e8SApple OSS Distributions.\" notice, this list of conditions and the following disclaimer. 11*4f1223e8SApple OSS Distributions.\" 2. Redistributions in binary form must reproduce the above copyright 12*4f1223e8SApple OSS Distributions.\" notice, this list of conditions and the following disclaimer in the 13*4f1223e8SApple OSS Distributions.\" documentation and/or other materials provided with the distribution. 14*4f1223e8SApple OSS Distributions.\" 3. All advertising materials mentioning features or use of this software 15*4f1223e8SApple OSS Distributions.\" must display the following acknowledgement: 16*4f1223e8SApple OSS Distributions.\" This product includes software developed by the University of 17*4f1223e8SApple OSS Distributions.\" California, Berkeley and its contributors. 18*4f1223e8SApple OSS Distributions.\" 4. Neither the name of the University nor the names of its contributors 19*4f1223e8SApple OSS Distributions.\" may be used to endorse or promote products derived from this software 20*4f1223e8SApple OSS Distributions.\" without specific prior written permission. 21*4f1223e8SApple OSS Distributions.\" 22*4f1223e8SApple OSS Distributions.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23*4f1223e8SApple OSS Distributions.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24*4f1223e8SApple OSS Distributions.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25*4f1223e8SApple OSS Distributions.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26*4f1223e8SApple OSS Distributions.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27*4f1223e8SApple OSS Distributions.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28*4f1223e8SApple OSS Distributions.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29*4f1223e8SApple OSS Distributions.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30*4f1223e8SApple OSS Distributions.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31*4f1223e8SApple OSS Distributions.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32*4f1223e8SApple OSS Distributions.\" SUCH DAMAGE. 33*4f1223e8SApple OSS Distributions.\" 34*4f1223e8SApple OSS Distributions.\" @(#)setuid.2 8.1 (Berkeley) 6/4/93 35*4f1223e8SApple OSS Distributions.\" 36*4f1223e8SApple OSS Distributions.Dd June 4, 1993 37*4f1223e8SApple OSS Distributions.Dt SETUID 2 38*4f1223e8SApple OSS Distributions.Os BSD 4.2 39*4f1223e8SApple OSS Distributions.Sh NAME 40*4f1223e8SApple OSS Distributions.Nm setegid , 41*4f1223e8SApple OSS Distributions.Nm seteuid , 42*4f1223e8SApple OSS Distributions.Nm setgid , 43*4f1223e8SApple OSS Distributions.Nm setuid 44*4f1223e8SApple OSS Distributions.Nd set user and group ID 45*4f1223e8SApple OSS Distributions.Sh SYNOPSIS 46*4f1223e8SApple OSS Distributions.Fd #include <unistd.h> 47*4f1223e8SApple OSS Distributions.Ft int 48*4f1223e8SApple OSS Distributions.Fo setegid 49*4f1223e8SApple OSS Distributions.Fa "gid_t egid" 50*4f1223e8SApple OSS Distributions.Fc 51*4f1223e8SApple OSS Distributions.Ft int 52*4f1223e8SApple OSS Distributions.Fo seteuid 53*4f1223e8SApple OSS Distributions.Fa "uid_t euid" 54*4f1223e8SApple OSS Distributions.Fc 55*4f1223e8SApple OSS Distributions.Ft int 56*4f1223e8SApple OSS Distributions.Fo setgid 57*4f1223e8SApple OSS Distributions.Fa "gid_t gid" 58*4f1223e8SApple OSS Distributions.Fc 59*4f1223e8SApple OSS Distributions.Ft int 60*4f1223e8SApple OSS Distributions.Fo setuid 61*4f1223e8SApple OSS Distributions.Fa "uid_t uid" 62*4f1223e8SApple OSS Distributions.Fc 63*4f1223e8SApple OSS Distributions.Sh DESCRIPTION 64*4f1223e8SApple OSS DistributionsThe 65*4f1223e8SApple OSS Distributions.Fn setuid 66*4f1223e8SApple OSS Distributionsfunction 67*4f1223e8SApple OSS Distributionssets the real and effective 68*4f1223e8SApple OSS Distributionsuser IDs and the saved set-user-ID of the current process 69*4f1223e8SApple OSS Distributionsto the specified value. 70*4f1223e8SApple OSS DistributionsThe 71*4f1223e8SApple OSS Distributions.Fn setuid 72*4f1223e8SApple OSS Distributionsfunction is permitted if the effective user ID is that of the super user, 73*4f1223e8SApple OSS Distributionsor if the specified user ID is the same as the effective user ID. If 74*4f1223e8SApple OSS Distributionsnot, but the specified user ID is the same as the real user ID, 75*4f1223e8SApple OSS Distributions.Fn setuid 76*4f1223e8SApple OSS Distributionswill set the effective user ID to the real user ID. 77*4f1223e8SApple OSS Distributions.Pp 78*4f1223e8SApple OSS DistributionsThe 79*4f1223e8SApple OSS Distributions.Fn setgid 80*4f1223e8SApple OSS Distributionsfunction 81*4f1223e8SApple OSS Distributionssets the real and effective 82*4f1223e8SApple OSS Distributionsgroup IDs and the saved set-group-ID of the current process 83*4f1223e8SApple OSS Distributionsto the specified value. 84*4f1223e8SApple OSS DistributionsThe 85*4f1223e8SApple OSS Distributions.Fn setgid 86*4f1223e8SApple OSS Distributionsfunction is permitted if the effective user ID is that of the super user, 87*4f1223e8SApple OSS Distributionsor if the specified group ID is the same as the effective group ID. If 88*4f1223e8SApple OSS Distributionsnot, but the specified group ID is the same as the real group ID, 89*4f1223e8SApple OSS Distributions.Fn setgid 90*4f1223e8SApple OSS Distributionswill set the effective group ID to the real group ID. 91*4f1223e8SApple OSS Distributions.Pp 92*4f1223e8SApple OSS DistributionsThe 93*4f1223e8SApple OSS Distributions.Fn seteuid 94*4f1223e8SApple OSS Distributionsfunction 95*4f1223e8SApple OSS Distributions.Pq Fn setegid 96*4f1223e8SApple OSS Distributionssets the effective user ID (group ID) of the 97*4f1223e8SApple OSS Distributionscurrent process. 98*4f1223e8SApple OSS DistributionsThe effective user ID may be set to the value 99*4f1223e8SApple OSS Distributionsof the real user ID or the saved set-user-ID (see 100*4f1223e8SApple OSS Distributions.Xr intro 2 101*4f1223e8SApple OSS Distributionsand 102*4f1223e8SApple OSS Distributions.Xr execve 2 ) ; 103*4f1223e8SApple OSS Distributionsin this way, the effective user ID of a set-user-ID executable 104*4f1223e8SApple OSS Distributionsmay be toggled by switching to the real user ID, then re-enabled 105*4f1223e8SApple OSS Distributionsby reverting to the set-user-ID value. 106*4f1223e8SApple OSS DistributionsSimilarly, the effective group ID may be set to the value 107*4f1223e8SApple OSS Distributionsof the real group ID or the saved set-group-ID. 108*4f1223e8SApple OSS Distributions.Pp 109*4f1223e8SApple OSS Distributions.Sh RETURN VALUES 110*4f1223e8SApple OSS DistributionsUpon success, these functions return 0; 111*4f1223e8SApple OSS Distributionsotherwise \-1 is returned. 112*4f1223e8SApple OSS Distributions.Pp 113*4f1223e8SApple OSS DistributionsIf the user is not the super user, or the uid 114*4f1223e8SApple OSS Distributionsspecified is not the real, effective ID, or saved ID, 115*4f1223e8SApple OSS Distributionsthese functions return \-1. 116*4f1223e8SApple OSS Distributions.Pp 117*4f1223e8SApple OSS Distributions.Sh ERRORS 118*4f1223e8SApple OSS DistributionsThe 119*4f1223e8SApple OSS Distributions.Fn setegid , 120*4f1223e8SApple OSS Distributions.Fn seteuid , 121*4f1223e8SApple OSS Distributions.Fn setgid , 122*4f1223e8SApple OSS Distributionsand 123*4f1223e8SApple OSS Distributions.Fn setuid 124*4f1223e8SApple OSS Distributionssystem calls will fail if: 125*4f1223e8SApple OSS Distributions.Bl -tag -width Er 126*4f1223e8SApple OSS Distributions.\" =========== 127*4f1223e8SApple OSS Distributions.It Bq Er EINVAL 128*4f1223e8SApple OSS DistributionsThe value of the {group,user} ID argument is invalid 129*4f1223e8SApple OSS Distributionsand is not supported by the implementation. 130*4f1223e8SApple OSS Distributions.\" =========== 131*4f1223e8SApple OSS Distributions.It Bq Er EPERM 132*4f1223e8SApple OSS DistributionsThe process does not have appropriate privileges and 133*4f1223e8SApple OSS Distributionsthe ID argument 134*4f1223e8SApple OSS Distributionsdoes not match the real ID 135*4f1223e8SApple OSS Distributionsor the saved set-{group,user}-ID. 136*4f1223e8SApple OSS Distributions.El 137*4f1223e8SApple OSS Distributions.Sh LEGACY SYNOPSIS 138*4f1223e8SApple OSS Distributions.Fd #include <sys/types.h> 139*4f1223e8SApple OSS Distributions.Fd #include <unistd.h> 140*4f1223e8SApple OSS Distributions.Pp 141*4f1223e8SApple OSS DistributionsThe include file 142*4f1223e8SApple OSS Distributions.In sys/types.h 143*4f1223e8SApple OSS Distributionsis necessary for all functions. 144*4f1223e8SApple OSS Distributions.Sh SEE ALSO 145*4f1223e8SApple OSS Distributions.Xr getgid 2 , 146*4f1223e8SApple OSS Distributions.Xr getuid 2 , 147*4f1223e8SApple OSS Distributions.Xr compat 5 148*4f1223e8SApple OSS Distributions.Sh STANDARDS 149*4f1223e8SApple OSS DistributionsThe 150*4f1223e8SApple OSS Distributions.Fn setuid 151*4f1223e8SApple OSS Distributionsand 152*4f1223e8SApple OSS Distributions.Fn setgid 153*4f1223e8SApple OSS Distributionsfunctions are compliant with the 154*4f1223e8SApple OSS Distributions.St -p1003.1-90 155*4f1223e8SApple OSS Distributionsspecification with 156*4f1223e8SApple OSS Distributions.Li _POSIX_SAVED_IDS 157*4f1223e8SApple OSS Distributionsdefined, with the extensions allowed in section B.4.2.2. 158*4f1223e8SApple OSS DistributionsThe 159*4f1223e8SApple OSS Distributions.Fn seteuid 160*4f1223e8SApple OSS Distributionsand 161*4f1223e8SApple OSS Distributions.Fn setegid 162*4f1223e8SApple OSS Distributionsfunctions are extensions based on the 163*4f1223e8SApple OSS Distributions.Tn POSIX 164*4f1223e8SApple OSS Distributionsconcept of 165*4f1223e8SApple OSS Distributions.Li _POSIX_SAVED_IDS , 166*4f1223e8SApple OSS Distributionsand have been proposed for a future revision of the standard. 167