aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--src/main.cpp16
-rw-r--r--src/token.hpp15
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;