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

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

Issue 2085393002: Add ability to query desktop process for its session ID by the network process (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing the default DACL for the Desktop Process Created 4 years, 6 months 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
« no previous file with comments | « remoting/host/win/wts_session_process_delegate.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // This file implements the Windows service controlling Me2Me host processes 5 // This file implements the Windows service controlling Me2Me host processes
6 // running within user sessions. 6 // running within user sessions.
7 7
8 #include "remoting/host/win/wts_session_process_delegate.h" 8 #include "remoting/host/win/wts_session_process_delegate.h"
9 9
10 #include <utility> 10 #include <utility>
(...skipping 11 matching lines...) Expand all
22 #include "ipc/attachment_broker.h" 22 #include "ipc/attachment_broker.h"
23 #include "ipc/ipc_channel.h" 23 #include "ipc/ipc_channel.h"
24 #include "ipc/ipc_channel_proxy.h" 24 #include "ipc/ipc_channel_proxy.h"
25 #include "ipc/ipc_listener.h" 25 #include "ipc/ipc_listener.h"
26 #include "ipc/ipc_message.h" 26 #include "ipc/ipc_message.h"
27 #include "remoting/host/host_main.h" 27 #include "remoting/host/host_main.h"
28 #include "remoting/host/ipc_constants.h" 28 #include "remoting/host/ipc_constants.h"
29 #include "remoting/host/ipc_util.h" 29 #include "remoting/host/ipc_util.h"
30 #include "remoting/host/switches.h" 30 #include "remoting/host/switches.h"
31 #include "remoting/host/win/launch_process_with_token.h" 31 #include "remoting/host/win/launch_process_with_token.h"
32 #include "remoting/host/win/security_descriptor.h"
32 #include "remoting/host/win/worker_process_launcher.h" 33 #include "remoting/host/win/worker_process_launcher.h"
33 #include "remoting/host/win/wts_terminal_monitor.h" 34 #include "remoting/host/win/wts_terminal_monitor.h"
34 #include "remoting/host/worker_process_ipc_delegate.h" 35 #include "remoting/host/worker_process_ipc_delegate.h"
35 36
36 using base::win::ScopedHandle; 37 using base::win::ScopedHandle;
37 38
38 // Name of the default session desktop. 39 // Name of the default session desktop.
39 const char kDefaultDesktopName[] = "winsta0\\default"; 40 const char kDefaultDesktopName[] = "winsta0\\default";
40 41
41 namespace remoting { 42 namespace remoting {
42 43
43 // A private class actually implementing the functionality provided by 44 // A private class actually implementing the functionality provided by
44 // |WtsSessionProcessDelegate|. This class is ref-counted and implements 45 // |WtsSessionProcessDelegate|. This class is ref-counted and implements
45 // asynchronous fire-and-forget shutdown. 46 // asynchronous fire-and-forget shutdown.
46 class WtsSessionProcessDelegate::Core 47 class WtsSessionProcessDelegate::Core
47 : public base::RefCountedThreadSafe<Core>, 48 : public base::RefCountedThreadSafe<Core>,
48 public base::MessagePumpForIO::IOHandler, 49 public base::MessagePumpForIO::IOHandler,
49 public IPC::Listener { 50 public IPC::Listener {
50 public: 51 public:
51 Core(scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, 52 Core(scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
52 std::unique_ptr<base::CommandLine> target, 53 std::unique_ptr<base::CommandLine> target,
53 bool launch_elevated, 54 bool launch_elevated,
54 const std::string& channel_security); 55 const std::string& channel_security,
56 const std::string& new_process_security);
55 57
56 // Initializes the object returning true on success. 58 // Initializes the object returning true on success.
57 bool Initialize(uint32_t session_id); 59 bool Initialize(uint32_t session_id);
58 60
59 // Stops the object asynchronously. 61 // Stops the object asynchronously.
60 void Stop(); 62 void Stop();
61 63
62 // Mirrors WorkerProcessLauncher::Delegate. 64 // Mirrors WorkerProcessLauncher::Delegate.
63 void LaunchProcess(WorkerProcessLauncher* event_handler); 65 void LaunchProcess(WorkerProcessLauncher* event_handler);
64 void Send(IPC::Message* message); 66 void Send(IPC::Message* message);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 // The task runner serving job object notifications. 110 // The task runner serving job object notifications.
109 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; 111 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
110 112
111 // The server end of the IPC channel used to communicate to the worker 113 // The server end of the IPC channel used to communicate to the worker
112 // process. 114 // process.
113 std::unique_ptr<IPC::ChannelProxy> channel_; 115 std::unique_ptr<IPC::ChannelProxy> channel_;
114 116
115 // Security descriptor (as SDDL) to be applied to |channel_|. 117 // Security descriptor (as SDDL) to be applied to |channel_|.
116 std::string channel_security_; 118 std::string channel_security_;
117 119
120 // Security descriptor (as SDDL) to be applied to the newly created process.
121 std::string new_process_security_;
122
118 WorkerProcessLauncher* event_handler_; 123 WorkerProcessLauncher* event_handler_;
119 124
120 // Pointer to GetNamedPipeClientProcessId() API if it is available. 125 // Pointer to GetNamedPipeClientProcessId() API if it is available.
121 typedef BOOL (WINAPI * GetNamedPipeClientProcessIdFn)(HANDLE, DWORD*); 126 typedef BOOL (WINAPI * GetNamedPipeClientProcessIdFn)(HANDLE, DWORD*);
122 GetNamedPipeClientProcessIdFn get_named_pipe_client_pid_; 127 GetNamedPipeClientProcessIdFn get_named_pipe_client_pid_;
123 128
124 // The job object used to control the lifetime of child processes. 129 // The job object used to control the lifetime of child processes.
125 base::win::ScopedHandle job_; 130 base::win::ScopedHandle job_;
126 131
127 // True if the worker process should be launched elevated. 132 // True if the worker process should be launched elevated.
(...skipping 14 matching lines...) Expand all
142 // The handle of the worker process, if launched. 147 // The handle of the worker process, if launched.
143 base::win::ScopedHandle worker_process_; 148 base::win::ScopedHandle worker_process_;
144 149
145 DISALLOW_COPY_AND_ASSIGN(Core); 150 DISALLOW_COPY_AND_ASSIGN(Core);
146 }; 151 };
147 152
148 WtsSessionProcessDelegate::Core::Core( 153 WtsSessionProcessDelegate::Core::Core(
149 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, 154 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
150 std::unique_ptr<base::CommandLine> target_command, 155 std::unique_ptr<base::CommandLine> target_command,
151 bool launch_elevated, 156 bool launch_elevated,
152 const std::string& channel_security) 157 const std::string& channel_security,
158 const std::string& new_process_security)
153 : caller_task_runner_(base::ThreadTaskRunnerHandle::Get()), 159 : caller_task_runner_(base::ThreadTaskRunnerHandle::Get()),
154 io_task_runner_(io_task_runner), 160 io_task_runner_(io_task_runner),
155 channel_security_(channel_security), 161 channel_security_(channel_security),
162 new_process_security_(new_process_security),
156 event_handler_(nullptr), 163 event_handler_(nullptr),
157 get_named_pipe_client_pid_(nullptr), 164 get_named_pipe_client_pid_(nullptr),
158 launch_elevated_(launch_elevated), 165 launch_elevated_(launch_elevated),
159 launch_pending_(false), 166 launch_pending_(false),
160 target_command_(std::move(target_command)) {} 167 target_command_(std::move(target_command)) {}
161 168
162 bool WtsSessionProcessDelegate::Core::Initialize(uint32_t session_id) { 169 bool WtsSessionProcessDelegate::Core::Initialize(uint32_t session_id) {
163 DCHECK(caller_task_runner_->BelongsToCurrentThread()); 170 DCHECK(caller_task_runner_->BelongsToCurrentThread());
164 171
165 if (launch_elevated_) { 172 if (launch_elevated_) {
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 new IPC::ChannelProxy(this, io_task_runner_)); 388 new IPC::ChannelProxy(this, io_task_runner_));
382 IPC::AttachmentBroker::GetGlobal()->RegisterCommunicationChannel( 389 IPC::AttachmentBroker::GetGlobal()->RegisterCommunicationChannel(
383 channel.get(), io_task_runner_); 390 channel.get(), io_task_runner_);
384 channel->Init(IPC::ChannelHandle(pipe.Get()), IPC::Channel::MODE_SERVER, 391 channel->Init(IPC::ChannelHandle(pipe.Get()), IPC::Channel::MODE_SERVER,
385 /*create_pipe_now=*/true); 392 /*create_pipe_now=*/true);
386 393
387 // Pass the name of the IPC channel to use. 394 // Pass the name of the IPC channel to use.
388 command_line.AppendSwitchNative(kDaemonPipeSwitchName, 395 command_line.AppendSwitchNative(kDaemonPipeSwitchName,
389 base::UTF8ToWide(channel_name)); 396 base::UTF8ToWide(channel_name));
390 397
398 ScopedSd security_descriptor;
399 std::unique_ptr<SECURITY_ATTRIBUTES> security_attributes;
400 if (!new_process_security_.empty()) {
401 security_descriptor = ConvertSddlToSd(new_process_security_);
402 if (!security_descriptor) {
403 PLOG(ERROR) << "ConvertSddlToSd() failed.";
404 ReportFatalError();
405 return;
406 }
407
408 security_attributes.reset(new SECURITY_ATTRIBUTES());
409 security_attributes->nLength = sizeof(SECURITY_ATTRIBUTES);
410 security_attributes->lpSecurityDescriptor = security_descriptor.get();
411 security_attributes->bInheritHandle = FALSE;
412 }
413
391 // Try to launch the process. 414 // Try to launch the process.
392 ScopedHandle worker_process; 415 ScopedHandle worker_process;
393 ScopedHandle worker_thread; 416 ScopedHandle worker_thread;
394 if (!LaunchProcessWithToken(command_line.GetProgram(), 417 if (!LaunchProcessWithToken(command_line.GetProgram(),
395 command_line.GetCommandLineString(), 418 command_line.GetCommandLineString(),
396 session_token_.Get(), 419 session_token_.Get(),
397 nullptr, 420 security_attributes.get(),
398 nullptr, 421 nullptr,
399 false, 422 false,
400 CREATE_SUSPENDED | CREATE_BREAKAWAY_FROM_JOB, 423 CREATE_SUSPENDED | CREATE_BREAKAWAY_FROM_JOB,
401 base::UTF8ToUTF16(kDefaultDesktopName).c_str(), 424 base::UTF8ToUTF16(kDefaultDesktopName).c_str(),
402 &worker_process, 425 &worker_process,
403 &worker_thread)) { 426 &worker_thread)) {
404 ReportFatalError(); 427 ReportFatalError();
405 return; 428 return;
406 } 429 }
407 430
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 } 540 }
518 ScopedHandle limited_handle(temp_handle); 541 ScopedHandle limited_handle(temp_handle);
519 542
520 event_handler_->OnProcessLaunched(std::move(limited_handle)); 543 event_handler_->OnProcessLaunched(std::move(limited_handle));
521 } 544 }
522 545
523 WtsSessionProcessDelegate::WtsSessionProcessDelegate( 546 WtsSessionProcessDelegate::WtsSessionProcessDelegate(
524 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, 547 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
525 std::unique_ptr<base::CommandLine> target_command, 548 std::unique_ptr<base::CommandLine> target_command,
526 bool launch_elevated, 549 bool launch_elevated,
527 const std::string& channel_security) { 550 const std::string& channel_security,
551 const std::string& new_process_security_descriptor) {
528 core_ = new Core(io_task_runner, std::move(target_command), launch_elevated, 552 core_ = new Core(io_task_runner, std::move(target_command), launch_elevated,
529 channel_security); 553 channel_security, new_process_security_descriptor);
530 } 554 }
531 555
532 WtsSessionProcessDelegate::~WtsSessionProcessDelegate() { 556 WtsSessionProcessDelegate::~WtsSessionProcessDelegate() {
533 core_->Stop(); 557 core_->Stop();
534 } 558 }
535 559
536 bool WtsSessionProcessDelegate::Initialize(uint32_t session_id) { 560 bool WtsSessionProcessDelegate::Initialize(uint32_t session_id) {
537 return core_->Initialize(session_id); 561 return core_->Initialize(session_id);
538 } 562 }
539 563
540 void WtsSessionProcessDelegate::LaunchProcess( 564 void WtsSessionProcessDelegate::LaunchProcess(
541 WorkerProcessLauncher* event_handler) { 565 WorkerProcessLauncher* event_handler) {
542 core_->LaunchProcess(event_handler); 566 core_->LaunchProcess(event_handler);
543 } 567 }
544 568
545 void WtsSessionProcessDelegate::Send(IPC::Message* message) { 569 void WtsSessionProcessDelegate::Send(IPC::Message* message) {
546 core_->Send(message); 570 core_->Send(message);
547 } 571 }
548 572
549 void WtsSessionProcessDelegate::CloseChannel() { 573 void WtsSessionProcessDelegate::CloseChannel() {
550 core_->CloseChannel(); 574 core_->CloseChannel();
551 } 575 }
552 576
553 void WtsSessionProcessDelegate::KillProcess() { 577 void WtsSessionProcessDelegate::KillProcess() {
554 core_->KillProcess(); 578 core_->KillProcess();
555 } 579 }
556 580
557 } // namespace remoting 581 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/win/wts_session_process_delegate.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698