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> | 13 #include <utility> |
14 | 14 |
15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
16 #include "base/files/file.h" | 16 #include "base/files/file.h" |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "base/rand_util.h" | 18 #include "base/rand_util.h" |
19 #include "base/single_thread_task_runner.h" | 19 #include "base/single_thread_task_runner.h" |
20 #include "base/strings/string16.h" | 20 #include "base/strings/string16.h" |
21 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
22 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
23 #include "base/synchronization/lock.h" | 23 #include "base/synchronization/lock.h" |
24 #include "base/win/scoped_handle.h" | 24 #include "base/win/scoped_handle.h" |
25 #include "base/win/windows_version.h" | 25 #include "base/win/windows_version.h" |
26 #include "ipc/attachment_broker.h" | |
26 #include "ipc/ipc_channel.h" | 27 #include "ipc/ipc_channel.h" |
27 #include "ipc/ipc_channel_proxy.h" | 28 #include "ipc/ipc_channel_proxy.h" |
28 #include "ipc/ipc_message.h" | 29 #include "ipc/ipc_message.h" |
29 #include "remoting/base/typed_buffer.h" | 30 #include "remoting/base/typed_buffer.h" |
30 #include "remoting/host/ipc_util.h" | 31 #include "remoting/host/ipc_util.h" |
31 #include "remoting/host/switches.h" | 32 #include "remoting/host/switches.h" |
32 #include "remoting/host/win/launch_process_with_token.h" | 33 #include "remoting/host/win/launch_process_with_token.h" |
33 #include "remoting/host/win/security_descriptor.h" | 34 #include "remoting/host/win/security_descriptor.h" |
34 #include "remoting/host/win/window_station_and_desktop.h" | 35 #include "remoting/host/win/window_station_and_desktop.h" |
35 #include "sandbox/win/src/restricted_token.h" | 36 #include "sandbox/win/src/restricted_token.h" |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
329 if (!LaunchProcessWithToken( | 330 if (!LaunchProcessWithToken( |
330 command_line.GetProgram(), command_line.GetCommandLineString(), | 331 command_line.GetProgram(), command_line.GetCommandLineString(), |
331 token.Get(), &process_attributes, &thread_attributes, true, 0, | 332 token.Get(), &process_attributes, &thread_attributes, true, 0, |
332 nullptr, &worker_process, &worker_thread)) { | 333 nullptr, &worker_process, &worker_thread)) { |
333 ReportFatalError(); | 334 ReportFatalError(); |
334 return; | 335 return; |
335 } | 336 } |
336 } | 337 } |
337 | 338 |
338 channel_ = std::move(server); | 339 channel_ = std::move(server); |
340 IPC::AttachmentBroker::GetGlobal()->RegisterCommunicationChannel( | |
341 channel_.get()); | |
342 | |
339 ReportProcessLaunched(std::move(worker_process)); | 343 ReportProcessLaunched(std::move(worker_process)); |
340 } | 344 } |
341 | 345 |
342 void UnprivilegedProcessDelegate::Send(IPC::Message* message) { | 346 void UnprivilegedProcessDelegate::Send(IPC::Message* message) { |
343 DCHECK(CalledOnValidThread()); | 347 DCHECK(CalledOnValidThread()); |
344 | 348 |
345 if (channel_) { | 349 if (channel_) { |
346 channel_->Send(message); | 350 channel_->Send(message); |
347 } else { | 351 } else { |
348 delete message; | 352 delete message; |
349 } | 353 } |
350 } | 354 } |
351 | 355 |
352 void UnprivilegedProcessDelegate::CloseChannel() { | 356 void UnprivilegedProcessDelegate::CloseChannel() { |
353 DCHECK(CalledOnValidThread()); | 357 DCHECK(CalledOnValidThread()); |
354 | 358 |
359 if (!channel_) | |
360 return; | |
361 | |
362 IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel( | |
363 channel_.get()); | |
355 channel_.reset(); | 364 channel_.reset(); |
356 } | 365 } |
357 | 366 |
358 void UnprivilegedProcessDelegate::KillProcess() { | 367 void UnprivilegedProcessDelegate::KillProcess() { |
359 DCHECK(CalledOnValidThread()); | 368 DCHECK(CalledOnValidThread()); |
360 | 369 |
361 channel_.reset(); | 370 CloseChannel(); |
362 event_handler_ = nullptr; | 371 event_handler_ = nullptr; |
363 | 372 |
364 if (worker_process_.IsValid()) { | 373 if (worker_process_.IsValid()) { |
365 TerminateProcess(worker_process_.Get(), CONTROL_C_EXIT); | 374 TerminateProcess(worker_process_.Get(), CONTROL_C_EXIT); |
366 worker_process_.Close(); | 375 worker_process_.Close(); |
367 } | 376 } |
368 } | 377 } |
369 | 378 |
370 bool UnprivilegedProcessDelegate::OnMessageReceived( | 379 bool UnprivilegedProcessDelegate::OnMessageReceived( |
371 const IPC::Message& message) { | 380 const IPC::Message& message) { |
(...skipping 19 matching lines...) Expand all Loading... | |
391 | 400 |
392 void UnprivilegedProcessDelegate::OnChannelError() { | 401 void UnprivilegedProcessDelegate::OnChannelError() { |
393 DCHECK(CalledOnValidThread()); | 402 DCHECK(CalledOnValidThread()); |
394 | 403 |
395 event_handler_->OnChannelError(); | 404 event_handler_->OnChannelError(); |
396 } | 405 } |
397 | 406 |
398 void UnprivilegedProcessDelegate::ReportFatalError() { | 407 void UnprivilegedProcessDelegate::ReportFatalError() { |
399 DCHECK(CalledOnValidThread()); | 408 DCHECK(CalledOnValidThread()); |
400 | 409 |
401 channel_.reset(); | 410 channel_.reset(); |
erikchen
2016/01/26 21:40:36
Should this go through CloseChannel()?
Sergey Ulanov
2016/01/27 01:38:39
Yes, thanks for catching this.
| |
402 | 411 |
403 WorkerProcessLauncher* event_handler = event_handler_; | 412 WorkerProcessLauncher* event_handler = event_handler_; |
404 event_handler_ = nullptr; | 413 event_handler_ = nullptr; |
405 event_handler->OnFatalError(); | 414 event_handler->OnFatalError(); |
406 } | 415 } |
407 | 416 |
408 void UnprivilegedProcessDelegate::ReportProcessLaunched( | 417 void UnprivilegedProcessDelegate::ReportProcessLaunched( |
409 base::win::ScopedHandle worker_process) { | 418 base::win::ScopedHandle worker_process) { |
410 DCHECK(CalledOnValidThread()); | 419 DCHECK(CalledOnValidThread()); |
411 DCHECK(!worker_process_.IsValid()); | 420 DCHECK(!worker_process_.IsValid()); |
(...skipping 11 matching lines...) Expand all Loading... | |
423 PLOG(ERROR) << "Failed to duplicate a handle"; | 432 PLOG(ERROR) << "Failed to duplicate a handle"; |
424 ReportFatalError(); | 433 ReportFatalError(); |
425 return; | 434 return; |
426 } | 435 } |
427 ScopedHandle limited_handle(temp_handle); | 436 ScopedHandle limited_handle(temp_handle); |
428 | 437 |
429 event_handler_->OnProcessLaunched(std::move(limited_handle)); | 438 event_handler_->OnProcessLaunched(std::move(limited_handle)); |
430 } | 439 } |
431 | 440 |
432 } // namespace remoting | 441 } // namespace remoting |
OLD | NEW |