File: seteuid.c

package info (click to toggle)
inn2 2.4.5-5
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 8,912 kB
  • ctags: 7,860
  • sloc: ansic: 85,104; perl: 11,427; sh: 9,863; makefile: 2,498; yacc: 1,563; python: 298; lex: 252; tcl: 7
file content (34 lines) | stat: -rw-r--r-- 1,016 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*  $Id: seteuid.c 3839 2000-08-29 04:50:18Z rra $
**
**  Replacement for a missing seteuid.
**
**  Written by Russ Allbery <rra@stanford.edu>
**  This work is hereby placed in the public domain by its author.
**
**  Some systems don't have seteuid but do have setreuid.  setreuid with
**  -1 given for the real UID is equivalent to seteuid on systems with
**  POSIX saved UIDs.  On systems without POSIX saved UIDs, we'd lose our
**  ability to regain privileges if we just set the effective UID, so
**  instead fake a saved UID by setting the real UID to the current
**  effective UID, using the real UID as the saved UID.
**
**  Note that swapping UIDs doesn't work on AIX, but AIX has saved UIDs.
**  Note also that systems without setreuid lose, and that we assume that
**  any system with seteuid has saved UIDs.
*/

#include "config.h"
#include "clibrary.h"

int
seteuid(uid_t euid)
{
    int ruid;

#ifdef _POSIX_SAVED_IDS
    ruid = -1;
#else
    ruid = geteuid();
#endif
    return setreuid(ruid, euid);
}