[xbuild] Log build errors and raise events even if a build fails.
[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 #ifdef HAVE_PWD_H
14 #include <pwd.h>
15 #endif
16
17 #include <string.h>
18 #include <sys/types.h>
19 #include <sys/stat.h>
20 #include <unistd.h>
21
22
23 /* Disclaimers */
24
25 #if defined(__GNUC__)
26 #ifndef HAVE_GETRESUID
27         #warning getresuid not supported. WindowsImpersonationContext wont work
28 #endif
29 #ifndef HAVE_SETRESUID
30         #warning setresuid not supported. WindowsImpersonationContext wont work
31 #endif
32 #endif
33
34
35 gboolean 
36 ImpersonateLoggedOnUser (gpointer handle)
37 {
38         uid_t token = (uid_t) GPOINTER_TO_INT (handle);
39 #ifdef HAVE_SETRESUID
40         if (setresuid (-1, token, getuid ()) < 0)
41                 return FALSE;
42 #endif
43         return (geteuid () == token);
44 }
45
46
47 gboolean RevertToSelf (void)
48 {
49 #ifdef HAVE_GETRESUID
50         uid_t ruid, euid;
51 #endif
52         uid_t suid = -1;
53
54 #ifdef HAVE_GETRESUID
55         if (getresuid (&ruid, &euid, &suid) < 0)
56                 return FALSE;
57 #endif
58 #ifdef HAVE_SETRESUID
59         if (setresuid (-1, suid, -1) < 0)
60                 return FALSE;
61 #else
62         return TRUE;
63 #endif
64         return (geteuid () == suid);
65 }
66