Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1005)

Unified Diff: base/process/process_info_win.cc

Issue 2961333002: Fix field trials not working in utility processes. (Closed)
Patch Set: review comment Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/process/process_info_win.cc
diff --git a/base/process/process_info_win.cc b/base/process/process_info_win.cc
index 8c4b36cb19e7a39a18b5d86b46c85d64030ed75e..06780838fec2b36e3b81a00e77bb51cf0c68ce7c 100644
--- a/base/process/process_info_win.cc
+++ b/base/process/process_info_win.cc
@@ -13,6 +13,17 @@
namespace base {
+namespace {
+
+HANDLE GetCurrentProcessToken() {
(unused - use chromium) 2017/06/30 16:15:18 We should probably make ScopedHandle movable and r
jam 2017/06/30 16:16:49 yep agreed, i checked first to see if it's moveabl
+ HANDLE process_token;
+ OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &process_token);
+ DCHECK(process_token != NULL && process_token != INVALID_HANDLE_VALUE);
+ return process_token;
+}
+
+} // namespace
+
// static
const Time CurrentProcessInfo::CreationTime() {
FILETIME creation_time = {};
@@ -27,16 +38,11 @@ const Time CurrentProcessInfo::CreationTime() {
}
IntegrityLevel GetCurrentProcessIntegrityLevel() {
- HANDLE process_token;
- if (!::OpenProcessToken(::GetCurrentProcess(),
- TOKEN_QUERY | TOKEN_QUERY_SOURCE, &process_token)) {
- return INTEGRITY_UNKNOWN;
- }
- win::ScopedHandle scoped_process_token(process_token);
+ base::win::ScopedHandle scoped_process_token(GetCurrentProcessToken());
DWORD token_info_length = 0;
- if (::GetTokenInformation(process_token, TokenIntegrityLevel, nullptr, 0,
- &token_info_length) ||
+ if (::GetTokenInformation(scoped_process_token.Get(), TokenIntegrityLevel,
+ nullptr, 0, &token_info_length) ||
::GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
return INTEGRITY_UNKNOWN;
}
@@ -44,8 +50,9 @@ IntegrityLevel GetCurrentProcessIntegrityLevel() {
auto token_label_bytes = MakeUnique<char[]>(token_info_length);
TOKEN_MANDATORY_LABEL* token_label =
reinterpret_cast<TOKEN_MANDATORY_LABEL*>(token_label_bytes.get());
- if (!::GetTokenInformation(process_token, TokenIntegrityLevel, token_label,
- token_info_length, &token_info_length)) {
+ if (!::GetTokenInformation(scoped_process_token.Get(), TokenIntegrityLevel,
+ token_label, token_info_length,
+ &token_info_length)) {
return INTEGRITY_UNKNOWN;
}
@@ -69,4 +76,19 @@ IntegrityLevel GetCurrentProcessIntegrityLevel() {
return INTEGRITY_UNKNOWN;
}
+bool IsCurrentProcessElevated() {
+ base::win::ScopedHandle scoped_process_token(GetCurrentProcessToken());
+
+ // Unlike TOKEN_ELEVATION_TYPE which returns TokenElevationTypeDefault when
+ // UAC is turned off, TOKEN_ELEVATION returns whether the process is elevated.
+ DWORD size;
+ TOKEN_ELEVATION elevation;
+ if (!GetTokenInformation(scoped_process_token.Get(), TokenElevation,
+ &elevation, sizeof(elevation), &size)) {
+ PLOG(ERROR) << "GetTokenInformation() failed";
+ return false;
+ }
+ return !!elevation.TokenIsElevated;
+}
+
} // namespace base

Powered by Google App Engine
This is Rietveld 408576698