OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 |
| 5 #ifndef CHROME_INSTALLER_UTIL_SCOPED_TOKEN_PRIVILEGE_H_ |
| 6 #define CHROME_INSTALLER_UTIL_SCOPED_TOKEN_PRIVILEGE_H_ |
| 7 |
| 8 #include <windows.h> |
| 9 |
| 10 #include "base/macros.h" |
| 11 #include "base/win/scoped_handle.h" |
| 12 |
| 13 namespace installer { |
| 14 |
| 15 // This class is available for Windows only and will enable the privilege |
| 16 // defined by |privilege_name| on the current process' token. The privilege will |
| 17 // be disabled upon the ScopedTokenPrivilege's destruction (unless it was |
| 18 // already enabled when the ScopedTokenPrivilege object was constructed). |
| 19 // Some privileges might require admin rights to be enabled (check is_enabled() |
| 20 // to know whether |privilege_name| was successfully enabled). |
| 21 class ScopedTokenPrivilege { |
| 22 public: |
| 23 explicit ScopedTokenPrivilege(const wchar_t* privilege_name); |
| 24 ~ScopedTokenPrivilege(); |
| 25 |
| 26 // Always returns true unless the privilege could not be enabled. |
| 27 bool is_enabled() const { return is_enabled_; } |
| 28 |
| 29 private: |
| 30 // Always true unless the privilege could not be enabled. |
| 31 bool is_enabled_; |
| 32 |
| 33 // A scoped handle to the current process' token. This will be closed |
| 34 // preemptively should enabling the privilege fail in the constructor. |
| 35 base::win::ScopedHandle token_; |
| 36 |
| 37 // The previous state of the privilege this object is responsible for. As set |
| 38 // by AdjustTokenPrivileges() upon construction. |
| 39 TOKEN_PRIVILEGES previous_privileges_; |
| 40 |
| 41 DISALLOW_IMPLICIT_CONSTRUCTORS(ScopedTokenPrivilege); |
| 42 }; |
| 43 |
| 44 } // namespace installer |
| 45 |
| 46 #endif // CHROME_INSTALLER_UTIL_SCOPED_TOKEN_PRIVILEGE_H_ |
OLD | NEW |