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