1 // Copyright 2012 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "base/process/process_info.h" 6 7 #include <windows.h> 8 9 #include "base/logging.h" 10 #include "base/notreached.h" 11 #include "base/win/access_token.h" 12 #include "third_party/abseil-cpp/absl/types/optional.h" 13 14 namespace base { 15 GetCurrentProcessIntegrityLevel()16IntegrityLevel GetCurrentProcessIntegrityLevel() { 17 absl::optional<base::win::AccessToken> token = 18 base::win::AccessToken::FromCurrentProcess(); 19 if (!token) { 20 PLOG(ERROR) << "AccessToken::FromCurrentProcess() failed"; 21 return INTEGRITY_UNKNOWN; 22 } 23 DWORD integrity_level = token->IntegrityLevel(); 24 25 if (integrity_level < SECURITY_MANDATORY_LOW_RID) 26 return UNTRUSTED_INTEGRITY; 27 28 if (integrity_level < SECURITY_MANDATORY_MEDIUM_RID) 29 return LOW_INTEGRITY; 30 31 if (integrity_level < SECURITY_MANDATORY_HIGH_RID) 32 return MEDIUM_INTEGRITY; 33 34 if (integrity_level >= SECURITY_MANDATORY_HIGH_RID) 35 return HIGH_INTEGRITY; 36 37 NOTREACHED(); 38 return INTEGRITY_UNKNOWN; 39 } 40 IsCurrentProcessElevated()41bool IsCurrentProcessElevated() { 42 absl::optional<base::win::AccessToken> token = 43 base::win::AccessToken::FromCurrentProcess(); 44 if (!token) { 45 PLOG(ERROR) << "AccessToken::FromCurrentProcess() failed"; 46 return false; 47 } 48 return token->IsElevated(); 49 } 50 IsCurrentProcessInAppContainer()51bool IsCurrentProcessInAppContainer() { 52 absl::optional<base::win::AccessToken> token = 53 base::win::AccessToken::FromCurrentProcess(); 54 if (!token) { 55 PLOG(ERROR) << "AccessToken::FromCurrentProcess() failed"; 56 return false; 57 } 58 return token->IsAppContainer(); 59 } 60 61 } // namespace base 62