process_info_win.cc 1.6 KB

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