| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef SANDBOX_SRC_RESTRICTED_TOKEN_H_ | 5 #ifndef SANDBOX_SRC_RESTRICTED_TOKEN_H_ |
| 6 #define SANDBOX_SRC_RESTRICTED_TOKEN_H_ | 6 #define SANDBOX_SRC_RESTRICTED_TOKEN_H_ |
| 7 | 7 |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 // HANDLE token_handle; | 38 // HANDLE token_handle; |
| 39 // err_code = restricted_token.GetRestrictedTokenHandle(&token_handle); | 39 // err_code = restricted_token.GetRestrictedTokenHandle(&token_handle); |
| 40 // if (ERROR_SUCCESS != err_code) { | 40 // if (ERROR_SUCCESS != err_code) { |
| 41 // // handle error. | 41 // // handle error. |
| 42 // } | 42 // } |
| 43 // [...] | 43 // [...] |
| 44 // CloseHandle(token_handle); | 44 // CloseHandle(token_handle); |
| 45 class RestrictedToken { | 45 class RestrictedToken { |
| 46 public: | 46 public: |
| 47 // Init() has to be called before calling any other method in the class. | 47 // Init() has to be called before calling any other method in the class. |
| 48 RestrictedToken() | 48 RestrictedToken(); |
| 49 : init_(false), effective_token_(NULL), | 49 ~RestrictedToken(); |
| 50 integrity_level_(INTEGRITY_LEVEL_LAST) { } | |
| 51 | |
| 52 ~RestrictedToken() { | |
| 53 if (effective_token_) | |
| 54 CloseHandle(effective_token_); | |
| 55 } | |
| 56 | 50 |
| 57 // Initializes the RestrictedToken object with effective_token. | 51 // Initializes the RestrictedToken object with effective_token. |
| 58 // If effective_token is NULL, it initializes the RestrictedToken object with | 52 // If effective_token is NULL, it initializes the RestrictedToken object with |
| 59 // the effective token of the current process. | 53 // the effective token of the current process. |
| 60 unsigned Init(HANDLE effective_token); | 54 unsigned Init(HANDLE effective_token); |
| 61 | 55 |
| 62 // Creates a restricted token and returns its handle using the token_handle | 56 // Creates a restricted token and returns its handle using the token_handle |
| 63 // output parameter. This handle has to be closed by the caller. | 57 // output parameter. This handle has to be closed by the caller. |
| 64 // If the function succeeds, the return value is ERROR_SUCCESS. If the | 58 // If the function succeeds, the return value is ERROR_SUCCESS. If the |
| 65 // function fails, the return value is the win32 error code corresponding to | 59 // function fails, the return value is the win32 error code corresponding to |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 IntegrityLevel integrity_level_; | 184 IntegrityLevel integrity_level_; |
| 191 // Tells if the object is initialized or not (if Init() has been called) | 185 // Tells if the object is initialized or not (if Init() has been called) |
| 192 bool init_; | 186 bool init_; |
| 193 | 187 |
| 194 DISALLOW_COPY_AND_ASSIGN(RestrictedToken); | 188 DISALLOW_COPY_AND_ASSIGN(RestrictedToken); |
| 195 }; | 189 }; |
| 196 | 190 |
| 197 } // namespace sandbox | 191 } // namespace sandbox |
| 198 | 192 |
| 199 #endif // SANDBOX_SRC_RESTRICTED_TOKEN_H_ | 193 #endif // SANDBOX_SRC_RESTRICTED_TOKEN_H_ |
| OLD | NEW |