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

Side by Side Diff: remoting/host/win/unprivileged_process_delegate.cc

Issue 71013004: Base: Remove Receive() from ScopedHandle. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add constructor Created 7 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 1
2 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be 3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file. 4 // found in the LICENSE file.
5 // 5 //
6 // This file implements the Windows service controlling Me2Me host processes 6 // This file implements the Windows service controlling Me2Me host processes
7 // running within user sessions. 7 // running within user sessions.
8 8
9 #include "remoting/host/win/unprivileged_process_delegate.h" 9 #include "remoting/host/win/unprivileged_process_delegate.h"
10 10
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 // Security descriptor of the worker process threads. It gives access SYSTEM 67 // Security descriptor of the worker process threads. It gives access SYSTEM
68 // full access to the threads. It gives READ_CONTROL, SYNCHRONIZE, 68 // full access to the threads. It gives READ_CONTROL, SYNCHRONIZE,
69 // THREAD_QUERY_INFORMATION and THREAD_TERMINATE rights to the built-in 69 // THREAD_QUERY_INFORMATION and THREAD_TERMINATE rights to the built-in
70 // administrators group. 70 // administrators group.
71 const char kWorkerThreadSd[] = "O:SYG:SYD:(A;;GA;;;SY)(A;;0x120801;;;BA)"; 71 const char kWorkerThreadSd[] = "O:SYG:SYD:(A;;GA;;;SY)(A;;0x120801;;;BA)";
72 72
73 // Creates a token with limited access that will be used to run the worker 73 // Creates a token with limited access that will be used to run the worker
74 // process. 74 // process.
75 bool CreateRestrictedToken(ScopedHandle* token_out) { 75 bool CreateRestrictedToken(ScopedHandle* token_out) {
76 // Create a token representing LocalService account. 76 // Create a token representing LocalService account.
77 ScopedHandle token; 77 HANDLE temp_handle;
78 if (!LogonUser(L"LocalService", L"NT AUTHORITY", NULL, LOGON32_LOGON_SERVICE, 78 if (!LogonUser(L"LocalService", L"NT AUTHORITY", NULL, LOGON32_LOGON_SERVICE,
79 LOGON32_PROVIDER_DEFAULT, token.Receive())) { 79 LOGON32_PROVIDER_DEFAULT, &temp_handle)) {
80 return false; 80 return false;
81 } 81 }
82 ScopedHandle token;
83 token.Set(temp_handle);
82 84
83 sandbox::RestrictedToken restricted_token; 85 sandbox::RestrictedToken restricted_token;
84 if (restricted_token.Init(token) != ERROR_SUCCESS) 86 if (restricted_token.Init(token) != ERROR_SUCCESS)
85 return false; 87 return false;
86 88
87 // Remove all privileges in the token. 89 // Remove all privileges in the token.
88 if (restricted_token.DeleteAllPrivileges(NULL) != ERROR_SUCCESS) 90 if (restricted_token.DeleteAllPrivileges(NULL) != ERROR_SUCCESS)
89 return false; 91 return false;
90 92
91 // Set low integrity level if supported by the OS. 93 // Set low integrity level if supported by the OS.
92 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { 94 if (base::win::GetVersion() >= base::win::VERSION_VISTA) {
93 if (restricted_token.SetIntegrityLevel(sandbox::INTEGRITY_LEVEL_LOW) 95 if (restricted_token.SetIntegrityLevel(sandbox::INTEGRITY_LEVEL_LOW)
94 != ERROR_SUCCESS) { 96 != ERROR_SUCCESS) {
95 return false; 97 return false;
96 } 98 }
97 } 99 }
98 100
99 // Return the resulting token. 101 // Return the resulting token.
100 return restricted_token.GetRestrictedTokenHandle(token_out->Receive()) == 102 if (restricted_token.GetRestrictedTokenHandle(&temp_handle) ==
101 ERROR_SUCCESS; 103 ERROR_SUCCESS) {
104 token_out->Set(temp_handle);
105 return true;
106 }
107 return false;
102 } 108 }
103 109
104 // Creates a window station with a given name and the default desktop giving 110 // Creates a window station with a given name and the default desktop giving
105 // the complete access to |logon_sid|. 111 // the complete access to |logon_sid|.
106 bool CreateWindowStationAndDesktop(ScopedSid logon_sid, 112 bool CreateWindowStationAndDesktop(ScopedSid logon_sid,
107 WindowStationAndDesktop* handles_out) { 113 WindowStationAndDesktop* handles_out) {
108 // Convert the logon SID into a string. 114 // Convert the logon SID into a string.
109 std::string logon_sid_string = ConvertSidToString(logon_sid.get()); 115 std::string logon_sid_string = ConvertSidToString(logon_sid.get());
110 if (logon_sid_string.empty()) { 116 if (logon_sid_string.empty()) {
111 LOG_GETLASTERROR(ERROR) << "Failed to convert a SID to string"; 117 LOG_GETLASTERROR(ERROR) << "Failed to convert a SID to string";
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 thread_attributes.lpSecurityDescriptor = thread_sd.get(); 272 thread_attributes.lpSecurityDescriptor = thread_sd.get();
267 thread_attributes.bInheritHandle = FALSE; 273 thread_attributes.bInheritHandle = FALSE;
268 274
269 ScopedHandle worker_process; 275 ScopedHandle worker_process;
270 { 276 {
271 // Take a lock why any inheritable handles are open to make sure that only 277 // Take a lock why any inheritable handles are open to make sure that only
272 // one process inherits them. 278 // one process inherits them.
273 base::AutoLock lock(g_inherit_handles_lock.Get()); 279 base::AutoLock lock(g_inherit_handles_lock.Get());
274 280
275 // Create a connected IPC channel. 281 // Create a connected IPC channel.
276 ScopedHandle client; 282 HANDLE temp_handle;
277 if (!CreateConnectedIpcChannel(io_task_runner_, this, client.Receive(), 283 if (!CreateConnectedIpcChannel(io_task_runner_, this, &temp_handle,
278 &server)) { 284 &server)) {
279 ReportFatalError(); 285 ReportFatalError();
280 return; 286 return;
281 } 287 }
288 ScopedHandle client;
289 client.Set(temp_handle);
282 290
283 // Convert the handle value into a decimal integer. Handle values are 32bit 291 // Convert the handle value into a decimal integer. Handle values are 32bit
284 // even on 64bit platforms. 292 // even on 64bit platforms.
285 std::string pipe_handle = base::StringPrintf( 293 std::string pipe_handle = base::StringPrintf(
286 "%d", reinterpret_cast<ULONG_PTR>(client.Get())); 294 "%d", reinterpret_cast<ULONG_PTR>(client.Get()));
287 295
288 // Pass the IPC channel via the command line. 296 // Pass the IPC channel via the command line.
289 CommandLine command_line(target_command_->argv()); 297 CommandLine command_line(target_command_->argv());
290 command_line.AppendSwitchASCII(kDaemonPipeSwitchName, pipe_handle); 298 command_line.AppendSwitchASCII(kDaemonPipeSwitchName, pipe_handle);
291 299
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 base::win::ScopedHandle worker_process) { 398 base::win::ScopedHandle worker_process) {
391 DCHECK(CalledOnValidThread()); 399 DCHECK(CalledOnValidThread());
392 DCHECK(!worker_process_.IsValid()); 400 DCHECK(!worker_process_.IsValid());
393 401
394 worker_process_ = worker_process.Pass(); 402 worker_process_ = worker_process.Pass();
395 403
396 // Report a handle that can be used to wait for the worker process completion, 404 // Report a handle that can be used to wait for the worker process completion,
397 // query information about the process and duplicate handles. 405 // query information about the process and duplicate handles.
398 DWORD desired_access = 406 DWORD desired_access =
399 SYNCHRONIZE | PROCESS_DUP_HANDLE | PROCESS_QUERY_INFORMATION; 407 SYNCHRONIZE | PROCESS_DUP_HANDLE | PROCESS_QUERY_INFORMATION;
400 ScopedHandle limited_handle; 408 HANDLE temp_handle;
401 if (!DuplicateHandle(GetCurrentProcess(), 409 if (!DuplicateHandle(GetCurrentProcess(),
402 worker_process_, 410 worker_process_,
403 GetCurrentProcess(), 411 GetCurrentProcess(),
404 limited_handle.Receive(), 412 &temp_handle,
405 desired_access, 413 desired_access,
406 FALSE, 414 FALSE,
407 0)) { 415 0)) {
408 LOG_GETLASTERROR(ERROR) << "Failed to duplicate a handle"; 416 LOG_GETLASTERROR(ERROR) << "Failed to duplicate a handle";
409 ReportFatalError(); 417 ReportFatalError();
410 return; 418 return;
411 } 419 }
420 ScopedHandle limited_handle;
421 limited_handle.Set(temp_handle);
412 422
413 event_handler_->OnProcessLaunched(limited_handle.Pass()); 423 event_handler_->OnProcessLaunched(limited_handle.Pass());
414 } 424 }
415 425
416 } // namespace remoting 426 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698