| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "sandbox/win/src/restricted_token.h" | 5 #include "sandbox/win/src/restricted_token.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 *error = ERROR_SUCCESS; | 38 *error = ERROR_SUCCESS; |
| 39 return buffer; | 39 return buffer; |
| 40 } | 40 } |
| 41 | 41 |
| 42 } // namespace | 42 } // namespace |
| 43 | 43 |
| 44 namespace sandbox { | 44 namespace sandbox { |
| 45 | 45 |
| 46 RestrictedToken::RestrictedToken() | 46 RestrictedToken::RestrictedToken() |
| 47 : integrity_level_(INTEGRITY_LEVEL_LAST), | 47 : integrity_level_(INTEGRITY_LEVEL_LAST), |
| 48 init_(false) { | 48 init_(false), |
| 49 } | 49 lockdown_default_dacl_(false) {} |
| 50 | 50 |
| 51 RestrictedToken::~RestrictedToken() { | 51 RestrictedToken::~RestrictedToken() { |
| 52 } | 52 } |
| 53 | 53 |
| 54 DWORD RestrictedToken::Init(const HANDLE effective_token) { | 54 DWORD RestrictedToken::Init(const HANDLE effective_token) { |
| 55 if (init_) | 55 if (init_) |
| 56 return ERROR_ALREADY_INITIALIZED; | 56 return ERROR_ALREADY_INITIALIZED; |
| 57 | 57 |
| 58 HANDLE temp_token; | 58 HANDLE temp_token; |
| 59 if (effective_token) { | 59 if (effective_token) { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 delete[] sids_to_restrict_array; | 151 delete[] sids_to_restrict_array; |
| 152 | 152 |
| 153 if (privileges_to_disable_array) | 153 if (privileges_to_disable_array) |
| 154 delete[] privileges_to_disable_array; | 154 delete[] privileges_to_disable_array; |
| 155 | 155 |
| 156 if (!result) | 156 if (!result) |
| 157 return last_error; | 157 return last_error; |
| 158 | 158 |
| 159 base::win::ScopedHandle new_token(new_token_handle); | 159 base::win::ScopedHandle new_token(new_token_handle); |
| 160 | 160 |
| 161 // Modify the default dacl on the token to contain Restricted and the user. | 161 if (lockdown_default_dacl_) { |
| 162 if (!AddSidToDefaultDacl(new_token.Get(), WinRestrictedCodeSid, GENERIC_ALL)) | 162 // Don't add Restricted sid and also remove logon sid access. |
| 163 return ::GetLastError(); | 163 if (!RevokeLogonSidFromDefaultDacl(new_token.Get())) |
| 164 return ::GetLastError(); |
| 165 } else { |
| 166 // Modify the default dacl on the token to contain Restricted. |
| 167 if (!AddSidToDefaultDacl(new_token.Get(), WinRestrictedCodeSid, |
| 168 GRANT_ACCESS, GENERIC_ALL)) { |
| 169 return ::GetLastError(); |
| 170 } |
| 171 } |
| 164 | 172 |
| 173 // Add user to default dacl. |
| 165 if (!AddUserSidToDefaultDacl(new_token.Get(), GENERIC_ALL)) | 174 if (!AddUserSidToDefaultDacl(new_token.Get(), GENERIC_ALL)) |
| 166 return ::GetLastError(); | 175 return ::GetLastError(); |
| 167 | 176 |
| 168 DWORD error = SetTokenIntegrityLevel(new_token.Get(), integrity_level_); | 177 DWORD error = SetTokenIntegrityLevel(new_token.Get(), integrity_level_); |
| 169 if (ERROR_SUCCESS != error) | 178 if (ERROR_SUCCESS != error) |
| 170 return error; | 179 return error; |
| 171 | 180 |
| 172 HANDLE token_handle; | 181 HANDLE token_handle; |
| 173 if (!::DuplicateHandle(::GetCurrentProcess(), new_token.Get(), | 182 if (!::DuplicateHandle(::GetCurrentProcess(), new_token.Get(), |
| 174 ::GetCurrentProcess(), &token_handle, | 183 ::GetCurrentProcess(), &token_handle, |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 } | 424 } |
| 416 | 425 |
| 417 return ERROR_SUCCESS; | 426 return ERROR_SUCCESS; |
| 418 } | 427 } |
| 419 | 428 |
| 420 DWORD RestrictedToken::SetIntegrityLevel(IntegrityLevel integrity_level) { | 429 DWORD RestrictedToken::SetIntegrityLevel(IntegrityLevel integrity_level) { |
| 421 integrity_level_ = integrity_level; | 430 integrity_level_ = integrity_level; |
| 422 return ERROR_SUCCESS; | 431 return ERROR_SUCCESS; |
| 423 } | 432 } |
| 424 | 433 |
| 434 void RestrictedToken::SetLockdownDefaultDacl() { |
| 435 lockdown_default_dacl_ = true; |
| 436 } |
| 437 |
| 425 } // namespace sandbox | 438 } // namespace sandbox |
| OLD | NEW |