diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2016-09-16 05:06:40 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2016-09-16 05:06:40 +0300 |
commit | 2b3f7138f02cd89dfb4f79a75b816e3a52f03aff (patch) | |
tree | f9f9bdd4ec14b9df814a2a8ff3a13bdc609e25a4 | |
parent | refactoring (diff) | |
download | privilege-check-2b3f7138f02cd89dfb4f79a75b816e3a52f03aff.tar.gz privilege-check-2b3f7138f02cd89dfb4f79a75b816e3a52f03aff.zip |
refactoring
Diffstat (limited to '')
-rw-r--r-- | src/main.cpp | 16 | ||||
-rw-r--r-- | src/token.hpp | 15 |
2 files changed, 16 insertions, 15 deletions
diff --git a/src/main.cpp b/src/main.cpp index 8731047..4e31e9f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,21 +24,22 @@ HWND get_dialog_item(HWND wnd, int id) bool is_administrator() { - const auto token = token::impersonate( - token::get_linked( - token::open_for_current_process(token::permissions::query() | token::permissions::duplicate()))); + auto token = token::open_for_current_process( + token::permissions::query() | token::permissions::duplicate()); + if (!token::get_linked(token)) + token = token::get_for_identification(token); - return token::belongs(token, sid::builtin_administrators()); + return token::check_belongs(token, sid::builtin_administrators()); } bool is_run_as_administrator() { - return token::belongs(token::dumb(), sid::builtin_administrators()); + return token::check_belongs(token::dumb(), sid::builtin_administrators()); } bool is_elevated() { - return token::is_elevated(token::open_for_current_process()); + return token::query_elevation(token::open_for_current_process()); } void decorate_elevate_button(HWND wnd, bool decorate) @@ -49,8 +50,7 @@ void decorate_elevate_button(HWND wnd, bool decorate) DWORD get_integrity_level() { - return token::query_integrity_level( - token::open_for_current_process()); + return token::query_integrity_level(token::open_for_current_process()); } std::wstring get_integrity_level_as_string() diff --git a/src/token.hpp b/src/token.hpp index 5669970..bc5083f 100644 --- a/src/token.hpp +++ b/src/token.hpp @@ -44,10 +44,10 @@ namespace token return open_for_process(Handle{GetCurrentProcess()}, permissions); } - Handle get_linked(Handle&& token) + bool get_linked(Handle& token) { if (!os::is_vista_or_later()) - return std::move(token); + return false; auto type = TokenElevationTypeDefault; DWORD cb = 0; @@ -56,17 +56,18 @@ namespace token error::raise("GetTokenInformation"); if (type != TokenElevationTypeLimited) - return std::move(token); + return false; HANDLE raw; if (!GetTokenInformation(token, TokenLinkedToken, &raw, sizeof(raw), &cb)) error::raise("GetTokenInformation"); - return Handle{raw}; + token = Handle{raw}; + return true; } - Handle impersonate(const Handle& token) + Handle get_for_identification(const Handle& token) { HANDLE raw; @@ -152,7 +153,7 @@ namespace token return it->second; } - bool belongs(const Handle& token, const SidBuffer& sid) + bool check_belongs(const Handle& token, const SidBuffer& sid) { BOOL b = FALSE; @@ -162,7 +163,7 @@ namespace token return b != FALSE; } - bool is_elevated(const Handle& token) + bool query_elevation(const Handle& token) { TOKEN_ELEVATION elevation; DWORD cb = 0; |