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
3 // found in the LICENSE file.
5 #include "remoting/host/win/wts_console_session_process_driver.h"
7 #include "base/base_switches.h"
8 #include "base/file_path.h"
9 #include "base/logging.h"
10 #include "base/single_thread_task_runner.h"
11 #include "ipc/ipc_message.h"
12 #include "ipc/ipc_message_macros.h"
13 #include "remoting/host/chromoting_messages.h"
14 #include "remoting/host/ipc_constants.h"
15 #include "remoting/host/sas_injector.h"
16 #include "remoting/host/win/worker_process_launcher.h"
17 #include "remoting/host/win/wts_console_monitor.h"
18 #include "remoting/host/win/wts_session_process_delegate.h"
20 // The security descriptor of the named pipe the process running in the console
21 // session connects to. It gives full access to LocalSystem and denies access by
23 const char kDaemonIpcSecurityDescriptor
[] = "O:SYG:SYD:(A;;GA;;;SY)";
27 WtsConsoleSessionProcessDriver::WtsConsoleSessionProcessDriver(
28 const base::Closure
& stopped_callback
,
29 WtsConsoleMonitor
* monitor
,
30 scoped_refptr
<base::SingleThreadTaskRunner
> caller_task_runner
,
31 scoped_refptr
<base::SingleThreadTaskRunner
> io_task_runner
)
32 : Stoppable(caller_task_runner
, stopped_callback
),
33 caller_task_runner_(caller_task_runner
),
34 io_task_runner_(io_task_runner
),
36 monitor_
->AddWtsConsoleObserver(this);
39 WtsConsoleSessionProcessDriver::~WtsConsoleSessionProcessDriver() {
40 DCHECK(caller_task_runner_
->BelongsToCurrentThread());
42 // Make sure that the object is completely stopped. The same check exists
43 // in Stoppable::~Stoppable() but this one helps us to fail early and
45 CHECK_EQ(stoppable_state(), Stoppable::kStopped
);
47 monitor_
->RemoveWtsConsoleObserver(this);
49 CHECK(launcher_
.get() == NULL
);
52 void WtsConsoleSessionProcessDriver::OnChannelConnected(int32 peer_pid
) {
53 DCHECK(caller_task_runner_
->BelongsToCurrentThread());
56 bool WtsConsoleSessionProcessDriver::OnMessageReceived(
57 const IPC::Message
& message
) {
58 DCHECK(caller_task_runner_
->BelongsToCurrentThread());
61 IPC_BEGIN_MESSAGE_MAP(WtsConsoleSessionProcessDriver
, message
)
62 IPC_MESSAGE_HANDLER(ChromotingNetworkDaemonMsg_SendSasToConsole
,
64 IPC_MESSAGE_UNHANDLED(handled
= false)
69 void WtsConsoleSessionProcessDriver::OnPermanentError() {
70 DCHECK(caller_task_runner_
->BelongsToCurrentThread());
75 void WtsConsoleSessionProcessDriver::OnSessionAttached(uint32 session_id
) {
76 DCHECK(caller_task_runner_
->BelongsToCurrentThread());
78 if (stoppable_state() != Stoppable::kRunning
) {
82 DCHECK(launcher_
.get() == NULL
);
84 // Construct the host binary name.
86 if (!GetInstalledBinaryPath(kHostBinaryName
, &host_binary
)) {
91 // Create a Delegate capable of launching an elevated process in the session.
92 scoped_ptr
<WtsSessionProcessDelegate
> delegate(
93 new WtsSessionProcessDelegate(caller_task_runner_
,
98 kDaemonIpcSecurityDescriptor
));
100 // Use the Delegate to launch the host process.
101 launcher_
.reset(new WorkerProcessLauncher(
102 caller_task_runner_
, delegate
.Pass(), this));
105 void WtsConsoleSessionProcessDriver::OnSessionDetached() {
106 DCHECK(caller_task_runner_
->BelongsToCurrentThread());
107 DCHECK(launcher_
.get() != NULL
);
112 void WtsConsoleSessionProcessDriver::DoStop() {
113 DCHECK(caller_task_runner_
->BelongsToCurrentThread());
119 void WtsConsoleSessionProcessDriver::OnSendSasToConsole() {
120 DCHECK(caller_task_runner_
->BelongsToCurrentThread());
126 sas_injector_
= SasInjector::Create();
127 if (!sas_injector_
->InjectSas())
128 LOG(ERROR
) << "Failed to inject Secure Attention Sequence.";
131 } // namespace remoting