chiark / gitweb /
Commit 2.4.5-5 as unpacked
[inn-innduct.git] / lib / seteuid.c
1 /*  $Id: seteuid.c 3839 2000-08-29 04:50:18Z rra $
2 **
3 **  Replacement for a missing seteuid.
4 **
5 **  Written by Russ Allbery <rra@stanford.edu>
6 **  This work is hereby placed in the public domain by its author.
7 **
8 **  Some systems don't have seteuid but do have setreuid.  setreuid with
9 **  -1 given for the real UID is equivalent to seteuid on systems with
10 **  POSIX saved UIDs.  On systems without POSIX saved UIDs, we'd lose our
11 **  ability to regain privileges if we just set the effective UID, so
12 **  instead fake a saved UID by setting the real UID to the current
13 **  effective UID, using the real UID as the saved UID.
14 **
15 **  Note that swapping UIDs doesn't work on AIX, but AIX has saved UIDs.
16 **  Note also that systems without setreuid lose, and that we assume that
17 **  any system with seteuid has saved UIDs.
18 */
19
20 #include "config.h"
21 #include "clibrary.h"
22
23 int
24 seteuid(uid_t euid)
25 {
26     int ruid;
27
28 #ifdef _POSIX_SAVED_IDS
29     ruid = -1;
30 #else
31     ruid = geteuid();
32 #endif
33     return setreuid(ruid, euid);
34 }