New test.
[mono.git] / mono / io-layer / security.c
1 /*
2  * security.c:  Security
3  *
4  * Author:
5  *      Sebastien Pouliot  <sebastien@ximian.com>
6  *
7  * (C) 2004 Novell (http://www.novell.com)
8  */
9
10 #include <config.h>
11 #include <mono/io-layer/io-layer.h>
12
13 #include <pwd.h>
14 #include <string.h>
15 #include <sys/types.h>
16 #include <unistd.h>
17
18
19 /* Disclaimers */
20
21 #if defined(__GNUC__)
22 #ifndef HAVE_GETRESUID
23         #warning getresuid not supported. WindowsImpersonationContext wont work
24 #endif
25 #ifndef HAVE_SETRESUID
26         #warning setresuid not supported. WindowsImpersonationContext wont work
27 #endif
28 #endif
29
30
31 gboolean 
32 ImpersonateLoggedOnUser (gpointer handle)
33 {
34         uid_t token = (uid_t) handle;
35 #ifdef HAVE_SETRESUID
36         if (setresuid (-1, token, getuid ()) < 0)
37                 return FALSE;
38 #endif
39         return (geteuid () == token);
40 }
41
42
43 gboolean RevertToSelf (void)
44 {
45 #ifdef HAVE_GETRESUID
46         uid_t ruid, euid;
47 #endif
48         uid_t suid = -1;
49
50 #ifdef HAVE_GETRESUID
51         if (getresuid (&ruid, &euid, &suid) < 0)
52                 return FALSE;
53 #endif
54 #ifdef HAVE_SETRESUID
55         if (setresuid (-1, suid, -1) < 0)
56                 return FALSE;
57 #endif
58         return (geteuid () == suid);
59 }
60