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 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
| 13 #include "base/win/scoped_handle.h" |
13 #include "sandbox/win/src/restricted_token_utils.h" | 14 #include "sandbox/win/src/restricted_token_utils.h" |
14 #include "sandbox/win/src/security_level.h" | 15 #include "sandbox/win/src/security_level.h" |
15 #include "sandbox/win/src/sid.h" | 16 #include "sandbox/win/src/sid.h" |
16 | 17 |
17 // Flags present in the Group SID list. These 2 flags are new in Windows Vista | 18 // Flags present in the Group SID list. These 2 flags are new in Windows Vista |
18 #ifndef SE_GROUP_INTEGRITY | 19 #ifndef SE_GROUP_INTEGRITY |
19 #define SE_GROUP_INTEGRITY (0x00000020L) | 20 #define SE_GROUP_INTEGRITY (0x00000020L) |
20 #endif | 21 #endif |
21 #ifndef SE_GROUP_INTEGRITY_ENABLED | 22 #ifndef SE_GROUP_INTEGRITY_ENABLED |
22 #define SE_GROUP_INTEGRITY_ENABLED (0x00000040L) | 23 #define SE_GROUP_INTEGRITY_ENABLED (0x00000040L) |
23 #endif | 24 #endif |
24 | 25 |
25 namespace sandbox { | 26 namespace sandbox { |
26 | 27 |
27 // Handles the creation of a restricted token using the effective token or | 28 // Handles the creation of a restricted token using the effective token or |
28 // any token handle. | 29 // any token handle. |
29 // Sample usage: | 30 // Sample usage: |
30 // RestrictedToken restricted_token; | 31 // RestrictedToken restricted_token; |
31 // unsigned err_code = restricted_token.Init(NULL); // Use the current | 32 // unsigned err_code = restricted_token.Init(NULL); // Use the current |
32 // // effective token | 33 // // effective token |
33 // if (ERROR_SUCCESS != err_code) { | 34 // if (ERROR_SUCCESS != err_code) { |
34 // // handle error. | 35 // // handle error. |
35 // } | 36 // } |
36 // | 37 // |
37 // restricted_token.AddRestrictingSid(ATL::Sids::Users().GetPSID()); | 38 // restricted_token.AddRestrictingSid(ATL::Sids::Users().GetPSID()); |
38 // HANDLE token_handle; | 39 // base::win::ScopedHandle token_handle; |
39 // err_code = restricted_token.GetRestrictedTokenHandle(&token_handle); | 40 // err_code = restricted_token.GetRestrictedToken(&token_handle); |
40 // if (ERROR_SUCCESS != err_code) { | 41 // if (ERROR_SUCCESS != err_code) { |
41 // // handle error. | 42 // // handle error. |
42 // } | 43 // } |
43 // [...] | 44 // [...] |
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 ~RestrictedToken(); | 49 ~RestrictedToken(); |
50 | 50 |
51 // Initializes the RestrictedToken object with effective_token. | 51 // Initializes the RestrictedToken object with effective_token. |
52 // If effective_token is NULL, it initializes the RestrictedToken object with | 52 // If effective_token is NULL, it initializes the RestrictedToken object with |
53 // the effective token of the current process. | 53 // the effective token of the current process. |
54 unsigned Init(HANDLE effective_token); | 54 unsigned Init(HANDLE effective_token); |
55 | 55 |
56 // Creates a restricted token and returns its handle using the token_handle | 56 // Creates a restricted token. |
57 // output parameter. This handle has to be closed by the caller. | |
58 // If the function succeeds, the return value is ERROR_SUCCESS. If the | 57 // If the function succeeds, the return value is ERROR_SUCCESS. If the |
59 // function fails, the return value is the win32 error code corresponding to | 58 // function fails, the return value is the win32 error code corresponding to |
60 // the error. | 59 // the error. |
61 unsigned GetRestrictedTokenHandle(HANDLE *token_handle) const; | 60 unsigned GetRestrictedToken(base::win::ScopedHandle* token) const; |
62 | 61 |
63 // Creates a restricted token and uses this new token to create a new token | 62 // Creates a restricted token and uses this new token to create a new token |
64 // for impersonation. Returns the handle of this impersonation token using | 63 // for impersonation. Returns this impersonation token. |
65 // the token_handle output parameter. This handle has to be closed by | |
66 // the caller. | |
67 // | 64 // |
68 // If the function succeeds, the return value is ERROR_SUCCESS. If the | 65 // If the function succeeds, the return value is ERROR_SUCCESS. If the |
69 // function fails, the return value is the win32 error code corresponding to | 66 // function fails, the return value is the win32 error code corresponding to |
70 // the error. | 67 // the error. |
71 // | 68 // |
72 // The sample usage is the same as the GetRestrictedTokenHandle function. | 69 // The sample usage is the same as the GetRestrictedToken function. |
73 unsigned GetRestrictedTokenHandleForImpersonation(HANDLE *token_handle) const; | 70 unsigned GetRestrictedTokenForImpersonation( |
| 71 base::win::ScopedHandle* token) const; |
74 | 72 |
75 // Lists all sids in the token and mark them as Deny Only except for those | 73 // Lists all sids in the token and mark them as Deny Only except for those |
76 // present in the exceptions parameter. If there is no exception needed, | 74 // present in the exceptions parameter. If there is no exception needed, |
77 // the caller can pass an empty list or NULL for the exceptions | 75 // the caller can pass an empty list or NULL for the exceptions |
78 // parameter. | 76 // parameter. |
79 // | 77 // |
80 // If the function succeeds, the return value is ERROR_SUCCESS. If the | 78 // If the function succeeds, the return value is ERROR_SUCCESS. If the |
81 // function fails, the return value is the win32 error code corresponding to | 79 // function fails, the return value is the win32 error code corresponding to |
82 // the error. | 80 // the error. |
83 // | 81 // |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 IntegrityLevel integrity_level_; | 182 IntegrityLevel integrity_level_; |
185 // Tells if the object is initialized or not (if Init() has been called) | 183 // Tells if the object is initialized or not (if Init() has been called) |
186 bool init_; | 184 bool init_; |
187 | 185 |
188 DISALLOW_COPY_AND_ASSIGN(RestrictedToken); | 186 DISALLOW_COPY_AND_ASSIGN(RestrictedToken); |
189 }; | 187 }; |
190 | 188 |
191 } // namespace sandbox | 189 } // namespace sandbox |
192 | 190 |
193 #endif // SANDBOX_SRC_RESTRICTED_TOKEN_H_ | 191 #endif // SANDBOX_SRC_RESTRICTED_TOKEN_H_ |
OLD | NEW |