1.\" $OpenBSD: issetugid.2,v 1.21 2015/09/10 17:55:21 schwarze Exp $ 2.\" 3.\" Copyright (c) 1980, 1991, 1993 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.Dd $Mdocdate: September 10 2015 $ 31.Dt ISSETUGID 2 32.Os 33.Sh NAME 34.Nm issetugid 35.Nd is current executable running setuid or setgid 36.Sh SYNOPSIS 37.In unistd.h 38.Ft int 39.Fn issetugid void 40.Sh DESCRIPTION 41The 42.Fn issetugid 43function returns 1 if the process was made setuid or setgid as 44the result of the last or other previous 45.Fn execve 46system calls. 47Otherwise it returns 0. 48.Pp 49This system call exists so that library routines (inside libtermlib, libc, 50or other libraries) can guarantee safe behavior when used inside 51setuid or setgid programs. 52Some library routines may be passed insufficient information and hence 53not know whether the current program was started setuid or setgid 54because higher level calling code may have made changes to the uid, euid, 55gid, or egid. 56Hence these low-level library routines are unable to determine if they 57are being run with elevated or normal privileges. 58.Pp 59In particular, it is wise to use this call to determine if a 60pathname returned from a 61.Fn getenv 62call may safely be used to 63.Fn open 64the specified file. 65Quite often this is not wise because the status of the effective uid 66is not known. 67.Pp 68The 69.Fn issetugid 70system call's result is unaffected by calls to 71.Fn setuid , 72.Fn setgid , 73or other such calls. 74In case of a 75.Fn fork , 76the child process inherits the same status. 77.Pp 78The status of 79.Fn issetugid 80is only affected by 81.Fn execve . 82If a child process executes a new executable file, a new issetugid 83status will be determined. 84This status is based on the existing process's uid, euid, gid, 85and egid permissions and on the modes of the executable file. 86If the new executable file modes are setuid or setgid, or if 87the existing process is executing the new image with 88uid != euid or gid != egid, the new process will be considered 89issetugid. 90.Sh ERRORS 91The 92.Fn issetugid 93function is always successful, and no return value is reserved to 94indicate an error. 95.Sh SEE ALSO 96.Xr execve 2 , 97.Xr setegid 2 , 98.Xr seteuid 2 , 99.Xr setgid 2 , 100.Xr setuid 2 , 101.Xr getenv 3 102.Sh HISTORY 103The 104.Fn issetugid 105function call first appeared in 106.Ox 2.0 . 107