Mercurial > trustbridge
comparison common/util.c @ 323:31ba7ed4d50f
Made is_elevated portable.
author | Sascha Wilde <wilde@intevation.de> |
---|---|
date | Mon, 07 Apr 2014 13:20:34 +0200 |
parents | 824ef90a6721 |
children | 64e38886f903 |
comparison
equal
deleted
inserted
replaced
322:e30c9fee111a | 323:31ba7ed4d50f |
---|---|
1 #include "util.h" | 1 #include "util.h" |
2 #ifdef WIN32 | 2 #ifndef _WIN32 |
3 #include <unistd.h> | |
4 #include <sys/types.h> | |
5 #else | |
3 #include <windows.h> | 6 #include <windows.h> |
4 #endif | 7 #endif |
5 | 8 |
6 #ifdef WIN32 | |
7 bool | 9 bool |
8 is_elevated() { | 10 is_elevated() |
9 HANDLE hToken = NULL; | 11 { |
10 bool ret = false; | 12 bool ret = false; |
11 if (OpenProcessToken (GetCurrentProcess(), TOKEN_QUERY, &hToken)) | 13 #ifndef _WIN32 |
12 { | 14 ret = (geteuid() == 0); |
13 DWORD elevation; | 15 #else |
14 DWORD cbSize = sizeof (DWORD); | 16 HANDLE hToken = NULL; |
15 if (GetTokenInformation (hToken, TokenElevation, &elevation, | 17 if (OpenProcessToken (GetCurrentProcess(), TOKEN_QUERY, &hToken)) |
16 sizeof (TokenElevation), &cbSize)) | 18 { |
17 { | 19 DWORD elevation; |
18 ret = elevation; | 20 DWORD cbSize = sizeof (DWORD); |
19 } | 21 if (GetTokenInformation (hToken, TokenElevation, &elevation, |
20 } | 22 sizeof (TokenElevation), &cbSize)) |
21 if (hToken) | 23 { |
22 CloseHandle (hToken); | 24 ret = elevation; |
25 } | |
26 } | |
27 if (hToken) | |
28 CloseHandle (hToken); | |
29 #endif | |
30 return ret; | |
31 } | |
23 | 32 |
24 return ret; | |
25 } | |
26 #endif |