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 <optional> 10 11 #include "base/logging.h" 12 #include "base/notreached.h" 13 #include "base/win/access_token.h" 14 15 namespace base { 16 GetCurrentProcessIntegrityLevel()17IntegrityLevel GetCurrentProcessIntegrityLevel() { 18 std::optional<base::win::AccessToken> token = 19 base::win::AccessToken::FromCurrentProcess(); 20 if (!token) { 21 PLOG(ERROR) << "AccessToken::FromCurrentProcess() failed"; 22 return INTEGRITY_UNKNOWN; 23 } 24 DWORD integrity_level = token->IntegrityLevel(); 25 26 if (integrity_level < SECURITY_MANDATORY_LOW_RID) 27 return UNTRUSTED_INTEGRITY; 28 29 if (integrity_level < SECURITY_MANDATORY_MEDIUM_RID) 30 return LOW_INTEGRITY; 31 32 if (integrity_level < SECURITY_MANDATORY_HIGH_RID) 33 return MEDIUM_INTEGRITY; 34 35 if (integrity_level >= SECURITY_MANDATORY_HIGH_RID) 36 return HIGH_INTEGRITY; 37 38 NOTREACHED(); 39 return INTEGRITY_UNKNOWN; 40 } 41 IsCurrentProcessElevated()42bool IsCurrentProcessElevated() { 43 std::optional<base::win::AccessToken> token = 44 base::win::AccessToken::FromCurrentProcess(); 45 if (!token) { 46 PLOG(ERROR) << "AccessToken::FromCurrentProcess() failed"; 47 return false; 48 } 49 return token->IsElevated(); 50 } 51 IsCurrentProcessInAppContainer()52bool IsCurrentProcessInAppContainer() { 53 std::optional<base::win::AccessToken> token = 54 base::win::AccessToken::FromCurrentProcess(); 55 if (!token) { 56 PLOG(ERROR) << "AccessToken::FromCurrentProcess() failed"; 57 return false; 58 } 59 return token->IsAppContainer(); 60 } 61 62 } // namespace base 63