xref: /freebsd/contrib/pam-krb5/portable/issetugid.c (revision bf6873c5786e333d679a7838d28812febf479a8a)
1*bf6873c5SCy Schubert /*
2*bf6873c5SCy Schubert  * Replacement for a missing issetugid.
3*bf6873c5SCy Schubert  *
4*bf6873c5SCy Schubert  * Simulates the functionality as the Solaris function issetugid, which
5*bf6873c5SCy Schubert  * returns true if the running program was setuid or setgid.  The replacement
6*bf6873c5SCy Schubert  * test is not quite as comprehensive as what the Solaris function does, but
7*bf6873c5SCy Schubert  * it should be good enough.
8*bf6873c5SCy Schubert  *
9*bf6873c5SCy Schubert  * The canonical version of this file is maintained in the rra-c-util package,
10*bf6873c5SCy Schubert  * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
11*bf6873c5SCy Schubert  *
12*bf6873c5SCy Schubert  * Written by Russ Allbery <eagle@eyrie.org>
13*bf6873c5SCy Schubert  * Copyright 2010-2011
14*bf6873c5SCy Schubert  *     The Board of Trustees of the Leland Stanford Junior University
15*bf6873c5SCy Schubert  *
16*bf6873c5SCy Schubert  * Copying and distribution of this file, with or without modification, are
17*bf6873c5SCy Schubert  * permitted in any medium without royalty provided the copyright notice and
18*bf6873c5SCy Schubert  * this notice are preserved.  This file is offered as-is, without any
19*bf6873c5SCy Schubert  * warranty.
20*bf6873c5SCy Schubert  *
21*bf6873c5SCy Schubert  * SPDX-License-Identifier: FSFAP
22*bf6873c5SCy Schubert  */
23*bf6873c5SCy Schubert 
24*bf6873c5SCy Schubert #include <config.h>
25*bf6873c5SCy Schubert #include <portable/system.h>
26*bf6873c5SCy Schubert 
27*bf6873c5SCy Schubert int
issetugid(void)28*bf6873c5SCy Schubert issetugid(void)
29*bf6873c5SCy Schubert {
30*bf6873c5SCy Schubert     if (getuid() != geteuid())
31*bf6873c5SCy Schubert         return 1;
32*bf6873c5SCy Schubert     if (getgid() != getegid())
33*bf6873c5SCy Schubert         return 1;
34*bf6873c5SCy Schubert     return 0;
35*bf6873c5SCy Schubert }
36