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

Side by Side Diff: remoting/host/desktop_session_win.cc

Issue 1935003003: Fixing curtain mode using non-default RDP port for Windows host. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing CR feedback Created 4 years, 7 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 | « no previous file | remoting/host/win/chromoting_lib_idl.templ » ('j') | 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 #include "remoting/host/desktop_session_win.h" 5 #include "remoting/host/desktop_session_win.h"
6 6
7 #include <sddl.h> 7 #include <sddl.h>
8 8
9 #include <limits> 9 #include <limits>
10 #include <memory> 10 #include <memory>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/base_switches.h" 13 #include "base/base_switches.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
16 #include "base/guid.h" 16 #include "base/guid.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/memory/ptr_util.h" 18 #include "base/memory/ptr_util.h"
19 #include "base/memory/ref_counted.h" 19 #include "base/memory/ref_counted.h"
20 #include "base/memory/weak_ptr.h" 20 #include "base/memory/weak_ptr.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/threading/thread_checker.h" 23 #include "base/threading/thread_checker.h"
24 #include "base/timer/timer.h" 24 #include "base/timer/timer.h"
25 #include "base/win/registry.h"
25 #include "base/win/scoped_bstr.h" 26 #include "base/win/scoped_bstr.h"
26 #include "base/win/scoped_comptr.h" 27 #include "base/win/scoped_comptr.h"
27 #include "base/win/scoped_handle.h" 28 #include "base/win/scoped_handle.h"
28 #include "base/win/windows_version.h" 29 #include "base/win/windows_version.h"
29 #include "ipc/ipc_message_macros.h" 30 #include "ipc/ipc_message_macros.h"
30 #include "ipc/ipc_platform_file.h" 31 #include "ipc/ipc_platform_file.h"
31 #include "remoting/base/auto_thread_task_runner.h" 32 #include "remoting/base/auto_thread_task_runner.h"
32 // MIDL-generated declarations and definitions. 33 // MIDL-generated declarations and definitions.
33 #include "remoting/host/chromoting_lib.h" 34 #include "remoting/host/chromoting_lib.h"
34 #include "remoting/host/chromoting_messages.h" 35 #include "remoting/host/chromoting_messages.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 // The minimum effective screen dimensions supported by Windows are 800x600. 76 // The minimum effective screen dimensions supported by Windows are 800x600.
76 const int kMinRdpScreenWidth = 800; 77 const int kMinRdpScreenWidth = 800;
77 const int kMinRdpScreenHeight = 600; 78 const int kMinRdpScreenHeight = 600;
78 79
79 // Default dots per inch used by RDP is 96 DPI. 80 // Default dots per inch used by RDP is 96 DPI.
80 const int kDefaultRdpDpi = 96; 81 const int kDefaultRdpDpi = 96;
81 82
82 // The session attach notification should arrive within 30 seconds. 83 // The session attach notification should arrive within 30 seconds.
83 const int kSessionAttachTimeoutSeconds = 30; 84 const int kSessionAttachTimeoutSeconds = 30;
84 85
86 // The default port number used for establishing an RDP session.
87 const int kDefaultRdpPort = 3389;
88
89 // The values used to establish RDP connections are stored in the registry.
90 const wchar_t kRdpTcpSettingsKeyName[] = L"SYSTEM\\CurrentControlSet\\"
91 L"Control\\Terminal Server\\WinStations\\RDP-Tcp";
92 const wchar_t kRdpPortValueName[] = L"PortNumber";
93
85 // DesktopSession implementation which attaches to the host's physical console. 94 // DesktopSession implementation which attaches to the host's physical console.
86 // Receives IPC messages from the desktop process, running in the console 95 // Receives IPC messages from the desktop process, running in the console
87 // session, via |WorkerProcessIpcDelegate|, and monitors console session 96 // session, via |WorkerProcessIpcDelegate|, and monitors console session
88 // attach/detach events via |WtsConsoleObserer|. 97 // attach/detach events via |WtsConsoleObserver|.
89 class ConsoleSession : public DesktopSessionWin { 98 class ConsoleSession : public DesktopSessionWin {
90 public: 99 public:
91 // Same as DesktopSessionWin(). 100 // Same as DesktopSessionWin().
92 ConsoleSession( 101 ConsoleSession(
93 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, 102 scoped_refptr<AutoThreadTaskRunner> caller_task_runner,
94 scoped_refptr<AutoThreadTaskRunner> io_task_runner, 103 scoped_refptr<AutoThreadTaskRunner> io_task_runner,
95 DaemonProcess* daemon_process, 104 DaemonProcess* daemon_process,
96 int id, 105 int id,
97 WtsTerminalMonitor* monitor); 106 WtsTerminalMonitor* monitor);
98 ~ConsoleSession() override; 107 ~ConsoleSession() override;
99 108
100 protected: 109 protected:
101 // DesktopSession overrides. 110 // DesktopSession overrides.
102 void SetScreenResolution(const ScreenResolution& resolution) override; 111 void SetScreenResolution(const ScreenResolution& resolution) override;
103 112
104 // DesktopSessionWin overrides. 113 // DesktopSessionWin overrides.
105 void InjectSas() override; 114 void InjectSas() override;
106 115
107 private: 116 private:
108 std::unique_ptr<SasInjector> sas_injector_; 117 std::unique_ptr<SasInjector> sas_injector_;
109 118
110 DISALLOW_COPY_AND_ASSIGN(ConsoleSession); 119 DISALLOW_COPY_AND_ASSIGN(ConsoleSession);
111 }; 120 };
112 121
113 // DesktopSession implementation which attaches to virtual RDP console. 122 // DesktopSession implementation which attaches to virtual RDP console.
114 // Receives IPC messages from the desktop process, running in the console 123 // Receives IPC messages from the desktop process, running in the console
115 // session, via |WorkerProcessIpcDelegate|, and monitors console session 124 // session, via |WorkerProcessIpcDelegate|, and monitors console session
116 // attach/detach events via |WtsConsoleObserer|. 125 // attach/detach events via |WtsConsoleObserver|.
117 class RdpSession : public DesktopSessionWin { 126 class RdpSession : public DesktopSessionWin {
118 public: 127 public:
119 // Same as DesktopSessionWin(). 128 // Same as DesktopSessionWin().
120 RdpSession( 129 RdpSession(
121 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, 130 scoped_refptr<AutoThreadTaskRunner> caller_task_runner,
122 scoped_refptr<AutoThreadTaskRunner> io_task_runner, 131 scoped_refptr<AutoThreadTaskRunner> io_task_runner,
123 DaemonProcess* daemon_process, 132 DaemonProcess* daemon_process,
124 int id, 133 int id,
125 WtsTerminalMonitor* monitor); 134 WtsTerminalMonitor* monitor);
126 ~RdpSession() override; 135 ~RdpSession() override;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 170
162 // Points to the desktop session object receiving OnRdpXxx() notifications. 171 // Points to the desktop session object receiving OnRdpXxx() notifications.
163 base::WeakPtr<RdpSession> desktop_session_; 172 base::WeakPtr<RdpSession> desktop_session_;
164 173
165 // This class must be used on a single thread. 174 // This class must be used on a single thread.
166 base::ThreadChecker thread_checker_; 175 base::ThreadChecker thread_checker_;
167 176
168 DISALLOW_COPY_AND_ASSIGN(EventHandler); 177 DISALLOW_COPY_AND_ASSIGN(EventHandler);
169 }; 178 };
170 179
180 // Retrieves a DWORD value from the registry. Returns true on success.
181 bool RetrieveDwordRegistryValue(const wchar_t* key_name,
182 const wchar_t* value_name,
183 DWORD* value);
184
171 // Used to create an RDP desktop session. 185 // Used to create an RDP desktop session.
172 base::win::ScopedComPtr<IRdpDesktopSession> rdp_desktop_session_; 186 base::win::ScopedComPtr<IRdpDesktopSession> rdp_desktop_session_;
173 187
174 // Used to match |rdp_desktop_session_| with the session it is attached to. 188 // Used to match |rdp_desktop_session_| with the session it is attached to.
175 std::string terminal_id_; 189 std::string terminal_id_;
176 190
177 base::WeakPtrFactory<RdpSession> weak_factory_; 191 base::WeakPtrFactory<RdpSession> weak_factory_;
178 192
179 DISALLOW_COPY_AND_ASSIGN(RdpSession); 193 DISALLOW_COPY_AND_ASSIGN(RdpSession);
180 }; 194 };
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 webrtc::DesktopSize host_size = local_resolution.ScaleDimensionsToDpi( 262 webrtc::DesktopSize host_size = local_resolution.ScaleDimensionsToDpi(
249 webrtc::DesktopVector(kDefaultRdpDpi, kDefaultRdpDpi)); 263 webrtc::DesktopVector(kDefaultRdpDpi, kDefaultRdpDpi));
250 264
251 // Make sure that the host resolution is within the limits supported by RDP. 265 // Make sure that the host resolution is within the limits supported by RDP.
252 host_size = webrtc::DesktopSize( 266 host_size = webrtc::DesktopSize(
253 std::min(kMaxRdpScreenWidth, 267 std::min(kMaxRdpScreenWidth,
254 std::max(kMinRdpScreenWidth, host_size.width())), 268 std::max(kMinRdpScreenWidth, host_size.width())),
255 std::min(kMaxRdpScreenHeight, 269 std::min(kMaxRdpScreenHeight,
256 std::max(kMinRdpScreenHeight, host_size.height()))); 270 std::max(kMinRdpScreenHeight, host_size.height())));
257 271
272 // Read the port number used by RDP.
273 DWORD server_port = kDefaultRdpPort;
274 if (RetrieveDwordRegistryValue(kRdpTcpSettingsKeyName, kRdpPortValueName,
275 &server_port) &&
276 server_port > 65535) {
277 LOG(ERROR) << "Invalid RDP port specified: " << server_port;
278 return false;
279 }
280
258 // Create an RDP session. 281 // Create an RDP session.
259 base::win::ScopedComPtr<IRdpDesktopSessionEventHandler> event_handler( 282 base::win::ScopedComPtr<IRdpDesktopSessionEventHandler> event_handler(
260 new EventHandler(weak_factory_.GetWeakPtr())); 283 new EventHandler(weak_factory_.GetWeakPtr()));
261 terminal_id_ = base::GenerateGUID(); 284 terminal_id_ = base::GenerateGUID();
262 base::win::ScopedBstr terminal_id(base::UTF8ToUTF16(terminal_id_).c_str()); 285 base::win::ScopedBstr terminal_id(base::UTF8ToUTF16(terminal_id_).c_str());
263 result = rdp_desktop_session_->Connect(host_size.width(), host_size.height(), 286 result = rdp_desktop_session_->Connect(host_size.width(), host_size.height(),
264 terminal_id, event_handler.get()); 287 terminal_id, server_port,
288 event_handler.get());
265 if (FAILED(result)) { 289 if (FAILED(result)) {
266 LOG(ERROR) << "RdpSession::Create() failed, 0x" 290 LOG(ERROR) << "RdpSession::Create() failed, 0x"
267 << std::hex << result << std::dec << "."; 291 << std::hex << result << std::dec << ".";
268 return false; 292 return false;
269 } 293 }
270 294
271 return true; 295 return true;
272 } 296 }
273 297
274 void RdpSession::OnRdpConnected() { 298 void RdpSession::OnRdpConnected() {
(...skipping 16 matching lines...) Expand all
291 // See http://crbug.com/137696. 315 // See http://crbug.com/137696.
292 NOTIMPLEMENTED(); 316 NOTIMPLEMENTED();
293 } 317 }
294 318
295 void RdpSession::InjectSas() { 319 void RdpSession::InjectSas() {
296 DCHECK(caller_task_runner()->BelongsToCurrentThread()); 320 DCHECK(caller_task_runner()->BelongsToCurrentThread());
297 321
298 rdp_desktop_session_->InjectSas(); 322 rdp_desktop_session_->InjectSas();
299 } 323 }
300 324
325 bool RdpSession::RetrieveDwordRegistryValue(const wchar_t* key_name,
326 const wchar_t* value_name,
327 DWORD* value) {
328 DCHECK(key_name);
329 DCHECK(value_name);
330 DCHECK(value);
331
332 base::win::RegKey key(HKEY_LOCAL_MACHINE, key_name, KEY_READ);
333 if (!key.Valid()) {
334 LOG(WARNING) << "Failed to open key: " << key_name;
335 return false;
336 }
337
338 if (key.ReadValueDW(value_name, value) != ERROR_SUCCESS) {
339 LOG(WARNING) << "Failed to read registry value: " << value_name;
340 return false;
341 }
342
343 return true;
344 }
345
301 RdpSession::EventHandler::EventHandler( 346 RdpSession::EventHandler::EventHandler(
302 base::WeakPtr<RdpSession> desktop_session) 347 base::WeakPtr<RdpSession> desktop_session)
303 : ref_count_(0), 348 : ref_count_(0),
304 desktop_session_(desktop_session) { 349 desktop_session_(desktop_session) {
305 } 350 }
306 351
307 RdpSession::EventHandler::~EventHandler() { 352 RdpSession::EventHandler::~EventHandler() {
308 DCHECK(thread_checker_.CalledOnValidThread()); 353 DCHECK(thread_checker_.CalledOnValidThread());
309 354
310 if (desktop_session_) 355 if (desktop_session_)
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 exploded.hour, 644 exploded.hour,
600 exploded.minute, 645 exploded.minute,
601 exploded.second, 646 exploded.second,
602 exploded.millisecond, 647 exploded.millisecond,
603 passed.c_str()); 648 passed.c_str());
604 649
605 last_timestamp_ = now; 650 last_timestamp_ = now;
606 } 651 }
607 652
608 } // namespace remoting 653 } // namespace remoting
OLDNEW
« no previous file with comments | « no previous file | remoting/host/win/chromoting_lib_idl.templ » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698