Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Side by Side Diff: sandbox/win/src/restricted_token.h

Issue 1240793004: Revert of Sandbox: Make CreateRestrictedToken return a ScopedHandle. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | sandbox/win/src/restricted_token.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
14 #include "sandbox/win/src/restricted_token_utils.h" 13 #include "sandbox/win/src/restricted_token_utils.h"
15 #include "sandbox/win/src/security_level.h" 14 #include "sandbox/win/src/security_level.h"
16 #include "sandbox/win/src/sid.h" 15 #include "sandbox/win/src/sid.h"
17 16
18 // Flags present in the Group SID list. These 2 flags are new in Windows Vista 17 // Flags present in the Group SID list. These 2 flags are new in Windows Vista
19 #ifndef SE_GROUP_INTEGRITY 18 #ifndef SE_GROUP_INTEGRITY
20 #define SE_GROUP_INTEGRITY (0x00000020L) 19 #define SE_GROUP_INTEGRITY (0x00000020L)
21 #endif 20 #endif
22 #ifndef SE_GROUP_INTEGRITY_ENABLED 21 #ifndef SE_GROUP_INTEGRITY_ENABLED
23 #define SE_GROUP_INTEGRITY_ENABLED (0x00000040L) 22 #define SE_GROUP_INTEGRITY_ENABLED (0x00000040L)
24 #endif 23 #endif
25 24
26 namespace sandbox { 25 namespace sandbox {
27 26
28 // Handles the creation of a restricted token using the effective token or 27 // Handles the creation of a restricted token using the effective token or
29 // any token handle. 28 // any token handle.
30 // Sample usage: 29 // Sample usage:
31 // RestrictedToken restricted_token; 30 // RestrictedToken restricted_token;
32 // unsigned err_code = restricted_token.Init(NULL); // Use the current 31 // unsigned err_code = restricted_token.Init(NULL); // Use the current
33 // // effective token 32 // // effective token
34 // if (ERROR_SUCCESS != err_code) { 33 // if (ERROR_SUCCESS != err_code) {
35 // // handle error. 34 // // handle error.
36 // } 35 // }
37 // 36 //
38 // restricted_token.AddRestrictingSid(ATL::Sids::Users().GetPSID()); 37 // restricted_token.AddRestrictingSid(ATL::Sids::Users().GetPSID());
39 // base::win::ScopedHandle token_handle; 38 // HANDLE token_handle;
40 // err_code = restricted_token.GetRestrictedToken(&token_handle); 39 // err_code = restricted_token.GetRestrictedTokenHandle(&token_handle);
41 // if (ERROR_SUCCESS != err_code) { 40 // if (ERROR_SUCCESS != err_code) {
42 // // handle error. 41 // // handle error.
43 // } 42 // }
44 // [...] 43 // [...]
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. 56 // Creates a restricted token and returns its handle using the token_handle
57 // output parameter. This handle has to be closed by the caller.
57 // 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
58 // 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
59 // the error. 60 // the error.
60 unsigned GetRestrictedToken(base::win::ScopedHandle* token) const; 61 unsigned GetRestrictedTokenHandle(HANDLE *token_handle) const;
61 62
62 // Creates a restricted token and uses this new token to create a new token 63 // Creates a restricted token and uses this new token to create a new token
63 // for impersonation. Returns this impersonation token. 64 // for impersonation. Returns the handle of this impersonation token using
65 // the token_handle output parameter. This handle has to be closed by
66 // the caller.
64 // 67 //
65 // If the function succeeds, the return value is ERROR_SUCCESS. If the 68 // If the function succeeds, the return value is ERROR_SUCCESS. If the
66 // function fails, the return value is the win32 error code corresponding to 69 // function fails, the return value is the win32 error code corresponding to
67 // the error. 70 // the error.
68 // 71 //
69 // The sample usage is the same as the GetRestrictedToken function. 72 // The sample usage is the same as the GetRestrictedTokenHandle function.
70 unsigned GetRestrictedTokenForImpersonation( 73 unsigned GetRestrictedTokenHandleForImpersonation(HANDLE *token_handle) const;
71 base::win::ScopedHandle* token) const;
72 74
73 // Lists all sids in the token and mark them as Deny Only except for those 75 // Lists all sids in the token and mark them as Deny Only except for those
74 // present in the exceptions parameter. If there is no exception needed, 76 // present in the exceptions parameter. If there is no exception needed,
75 // the caller can pass an empty list or NULL for the exceptions 77 // the caller can pass an empty list or NULL for the exceptions
76 // parameter. 78 // parameter.
77 // 79 //
78 // If the function succeeds, the return value is ERROR_SUCCESS. If the 80 // If the function succeeds, the return value is ERROR_SUCCESS. If the
79 // function fails, the return value is the win32 error code corresponding to 81 // function fails, the return value is the win32 error code corresponding to
80 // the error. 82 // the error.
81 // 83 //
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 IntegrityLevel integrity_level_; 184 IntegrityLevel integrity_level_;
183 // 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)
184 bool init_; 186 bool init_;
185 187
186 DISALLOW_COPY_AND_ASSIGN(RestrictedToken); 188 DISALLOW_COPY_AND_ASSIGN(RestrictedToken);
187 }; 189 };
188 190
189 } // namespace sandbox 191 } // namespace sandbox
190 192
191 #endif // SANDBOX_SRC_RESTRICTED_TOKEN_H_ 193 #endif // SANDBOX_SRC_RESTRICTED_TOKEN_H_
OLDNEW
« no previous file with comments | « no previous file | sandbox/win/src/restricted_token.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698