| OLD | NEW |
| 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 |
| 11 #include <sddl.h> | 11 #include <sddl.h> |
| 12 | 12 |
| 13 #include <utility> |
| 14 |
| 13 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 14 #include "base/files/file.h" | 16 #include "base/files/file.h" |
| 15 #include "base/logging.h" | 17 #include "base/logging.h" |
| 16 #include "base/rand_util.h" | 18 #include "base/rand_util.h" |
| 17 #include "base/single_thread_task_runner.h" | 19 #include "base/single_thread_task_runner.h" |
| 18 #include "base/strings/string16.h" | 20 #include "base/strings/string16.h" |
| 19 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
| 20 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 21 #include "base/synchronization/lock.h" | 23 #include "base/synchronization/lock.h" |
| 22 #include "base/win/scoped_handle.h" | 24 #include "base/win/scoped_handle.h" |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 handles.Swap(*handles_out); | 232 handles.Swap(*handles_out); |
| 231 return true; | 233 return true; |
| 232 } | 234 } |
| 233 | 235 |
| 234 } // namespace | 236 } // namespace |
| 235 | 237 |
| 236 UnprivilegedProcessDelegate::UnprivilegedProcessDelegate( | 238 UnprivilegedProcessDelegate::UnprivilegedProcessDelegate( |
| 237 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, | 239 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
| 238 scoped_ptr<base::CommandLine> target_command) | 240 scoped_ptr<base::CommandLine> target_command) |
| 239 : io_task_runner_(io_task_runner), | 241 : io_task_runner_(io_task_runner), |
| 240 target_command_(target_command.Pass()), | 242 target_command_(std::move(target_command)), |
| 241 event_handler_(nullptr) { | 243 event_handler_(nullptr) {} |
| 242 } | |
| 243 | 244 |
| 244 UnprivilegedProcessDelegate::~UnprivilegedProcessDelegate() { | 245 UnprivilegedProcessDelegate::~UnprivilegedProcessDelegate() { |
| 245 DCHECK(CalledOnValidThread()); | 246 DCHECK(CalledOnValidThread()); |
| 246 DCHECK(!channel_); | 247 DCHECK(!channel_); |
| 247 DCHECK(!worker_process_.IsValid()); | 248 DCHECK(!worker_process_.IsValid()); |
| 248 } | 249 } |
| 249 | 250 |
| 250 void UnprivilegedProcessDelegate::LaunchProcess( | 251 void UnprivilegedProcessDelegate::LaunchProcess( |
| 251 WorkerProcessLauncher* event_handler) { | 252 WorkerProcessLauncher* event_handler) { |
| 252 DCHECK(CalledOnValidThread()); | 253 DCHECK(CalledOnValidThread()); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 // even on 64bit platforms. | 310 // even on 64bit platforms. |
| 310 std::string pipe_handle = base::StringPrintf( | 311 std::string pipe_handle = base::StringPrintf( |
| 311 "%d", reinterpret_cast<ULONG_PTR>(client.GetPlatformFile())); | 312 "%d", reinterpret_cast<ULONG_PTR>(client.GetPlatformFile())); |
| 312 | 313 |
| 313 // Pass the IPC channel via the command line. | 314 // Pass the IPC channel via the command line. |
| 314 base::CommandLine command_line(target_command_->argv()); | 315 base::CommandLine command_line(target_command_->argv()); |
| 315 command_line.AppendSwitchASCII(kDaemonPipeSwitchName, pipe_handle); | 316 command_line.AppendSwitchASCII(kDaemonPipeSwitchName, pipe_handle); |
| 316 | 317 |
| 317 // Create our own window station and desktop accessible by |logon_sid|. | 318 // Create our own window station and desktop accessible by |logon_sid|. |
| 318 WindowStationAndDesktop handles; | 319 WindowStationAndDesktop handles; |
| 319 if (!CreateWindowStationAndDesktop(logon_sid.Pass(), &handles)) { | 320 if (!CreateWindowStationAndDesktop(std::move(logon_sid), &handles)) { |
| 320 PLOG(ERROR) << "Failed to create a window station and desktop"; | 321 PLOG(ERROR) << "Failed to create a window station and desktop"; |
| 321 ReportFatalError(); | 322 ReportFatalError(); |
| 322 return; | 323 return; |
| 323 } | 324 } |
| 324 | 325 |
| 325 // Try to launch the worker process. The launched process inherits | 326 // Try to launch the worker process. The launched process inherits |
| 326 // the window station, desktop and pipe handles, created above. | 327 // the window station, desktop and pipe handles, created above. |
| 327 ScopedHandle worker_thread; | 328 ScopedHandle worker_thread; |
| 328 if (!LaunchProcessWithToken(command_line.GetProgram(), | 329 if (!LaunchProcessWithToken( |
| 329 command_line.GetCommandLineString(), | 330 command_line.GetProgram(), command_line.GetCommandLineString(), |
| 330 token.Get(), | 331 token.Get(), &process_attributes, &thread_attributes, true, 0, |
| 331 &process_attributes, | 332 nullptr, &worker_process, &worker_thread)) { |
| 332 &thread_attributes, | |
| 333 true, | |
| 334 0, | |
| 335 nullptr, | |
| 336 &worker_process, | |
| 337 &worker_thread)) { | |
| 338 ReportFatalError(); | 333 ReportFatalError(); |
| 339 return; | 334 return; |
| 340 } | 335 } |
| 341 } | 336 } |
| 342 | 337 |
| 343 channel_ = server.Pass(); | 338 channel_ = std::move(server); |
| 344 ReportProcessLaunched(worker_process.Pass()); | 339 ReportProcessLaunched(std::move(worker_process)); |
| 345 } | 340 } |
| 346 | 341 |
| 347 void UnprivilegedProcessDelegate::Send(IPC::Message* message) { | 342 void UnprivilegedProcessDelegate::Send(IPC::Message* message) { |
| 348 DCHECK(CalledOnValidThread()); | 343 DCHECK(CalledOnValidThread()); |
| 349 | 344 |
| 350 if (channel_) { | 345 if (channel_) { |
| 351 channel_->Send(message); | 346 channel_->Send(message); |
| 352 } else { | 347 } else { |
| 353 delete message; | 348 delete message; |
| 354 } | 349 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 WorkerProcessLauncher* event_handler = event_handler_; | 403 WorkerProcessLauncher* event_handler = event_handler_; |
| 409 event_handler_ = nullptr; | 404 event_handler_ = nullptr; |
| 410 event_handler->OnFatalError(); | 405 event_handler->OnFatalError(); |
| 411 } | 406 } |
| 412 | 407 |
| 413 void UnprivilegedProcessDelegate::ReportProcessLaunched( | 408 void UnprivilegedProcessDelegate::ReportProcessLaunched( |
| 414 base::win::ScopedHandle worker_process) { | 409 base::win::ScopedHandle worker_process) { |
| 415 DCHECK(CalledOnValidThread()); | 410 DCHECK(CalledOnValidThread()); |
| 416 DCHECK(!worker_process_.IsValid()); | 411 DCHECK(!worker_process_.IsValid()); |
| 417 | 412 |
| 418 worker_process_ = worker_process.Pass(); | 413 worker_process_ = std::move(worker_process); |
| 419 | 414 |
| 420 // Report a handle that can be used to wait for the worker process completion, | 415 // Report a handle that can be used to wait for the worker process completion, |
| 421 // query information about the process and duplicate handles. | 416 // query information about the process and duplicate handles. |
| 422 DWORD desired_access = | 417 DWORD desired_access = |
| 423 SYNCHRONIZE | PROCESS_DUP_HANDLE | PROCESS_QUERY_INFORMATION; | 418 SYNCHRONIZE | PROCESS_DUP_HANDLE | PROCESS_QUERY_INFORMATION; |
| 424 HANDLE temp_handle; | 419 HANDLE temp_handle; |
| 425 if (!DuplicateHandle(GetCurrentProcess(), | 420 if (!DuplicateHandle(GetCurrentProcess(), worker_process_.Get(), |
| 426 worker_process_.Get(), | 421 GetCurrentProcess(), &temp_handle, desired_access, FALSE, |
| 427 GetCurrentProcess(), | |
| 428 &temp_handle, | |
| 429 desired_access, | |
| 430 FALSE, | |
| 431 0)) { | 422 0)) { |
| 432 PLOG(ERROR) << "Failed to duplicate a handle"; | 423 PLOG(ERROR) << "Failed to duplicate a handle"; |
| 433 ReportFatalError(); | 424 ReportFatalError(); |
| 434 return; | 425 return; |
| 435 } | 426 } |
| 436 ScopedHandle limited_handle(temp_handle); | 427 ScopedHandle limited_handle(temp_handle); |
| 437 | 428 |
| 438 event_handler_->OnProcessLaunched(limited_handle.Pass()); | 429 event_handler_->OnProcessLaunched(std::move(limited_handle)); |
| 439 } | 430 } |
| 440 | 431 |
| 441 } // namespace remoting | 432 } // namespace remoting |
| OLD | NEW |