Mercurial > trustbridge
comparison common/util.c @ 1307:2bacaec6e101
(perf) Use cached values to deterimine elevation.
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Mon, 13 Oct 2014 12:32:13 +0200 |
parents | 845048d4a69f |
children | 8362e30f7b55 |
comparison
equal
deleted
inserted
replaced
1306:845048d4a69f | 1307:2bacaec6e101 |
---|---|
451 | 451 |
452 return integrity_level >= SECURITY_MANDATORY_HIGH_RID; | 452 return integrity_level >= SECURITY_MANDATORY_HIGH_RID; |
453 } | 453 } |
454 #endif | 454 #endif |
455 | 455 |
456 static bool g_is_elevated = false; | |
457 static bool g_elevated_initalized = false; | |
458 | |
456 bool | 459 bool |
457 is_elevated() | 460 is_elevated() |
458 { | 461 { |
459 bool ret = false; | 462 bool ret = false; |
463 if (g_elevated_initalized) | |
464 { | |
465 return g_is_elevated; | |
466 } | |
460 #ifndef _WIN32 | 467 #ifndef _WIN32 |
461 ret = (geteuid() == 0); | 468 ret = (geteuid() == 0); |
462 #else | 469 #else |
463 HANDLE hToken = NULL; | 470 HANDLE hToken = NULL; |
464 if (OpenProcessToken (GetCurrentProcess(), TOKEN_QUERY, &hToken)) | 471 if (OpenProcessToken (GetCurrentProcess(), TOKEN_QUERY, &hToken)) |
479 ret = ret && has_high_integrity (hToken); | 486 ret = ret && has_high_integrity (hToken); |
480 | 487 |
481 if (hToken) | 488 if (hToken) |
482 CloseHandle (hToken); | 489 CloseHandle (hToken); |
483 #endif | 490 #endif |
491 g_is_elevated = ret; | |
492 g_elevated_initalized = true; | |
484 return ret; | 493 return ret; |
485 } | 494 } |
486 | 495 |
487 #ifdef _WIN32 | 496 #ifdef _WIN32 |
488 char * | 497 char * |