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

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

Issue 10073028: Avoiding unnecessary conversion to UTF16 in runtime. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « remoting/host/sas_injector_win.cc ('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/wts_session_process_launcher_win.h" 8 #include "remoting/host/wts_session_process_launcher_win.h"
9 9
10 #include <windows.h> 10 #include <windows.h>
11 #include <sddl.h> 11 #include <sddl.h>
12 #include <limits> 12 #include <limits>
13 13
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/bind_helpers.h" 15 #include "base/bind_helpers.h"
16 #include "base/command_line.h" 16 #include "base/command_line.h"
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/message_loop_proxy.h" 18 #include "base/message_loop_proxy.h"
19 #include "base/process_util.h" 19 #include "base/process_util.h"
20 #include "base/rand_util.h" 20 #include "base/rand_util.h"
21 #include "base/string16.h" 21 #include "base/string16.h"
22 #include "base/stringize_macros.h"
22 #include "base/stringprintf.h" 23 #include "base/stringprintf.h"
23 #include "base/utf_string_conversions.h"
24 #include "base/win/scoped_handle.h" 24 #include "base/win/scoped_handle.h"
25 #include "base/win/scoped_process_information.h" 25 #include "base/win/scoped_process_information.h"
26 #include "ipc/ipc_channel_proxy.h" 26 #include "ipc/ipc_channel_proxy.h"
27 #include "ipc/ipc_message.h" 27 #include "ipc/ipc_message.h"
28 #include "ipc/ipc_message_macros.h" 28 #include "ipc/ipc_message_macros.h"
29 29
30 #include "remoting/host/chromoting_messages.h" 30 #include "remoting/host/chromoting_messages.h"
31 #include "remoting/host/sas_injector.h" 31 #include "remoting/host/sas_injector.h"
32 #include "remoting/host/wts_console_monitor_win.h" 32 #include "remoting/host/wts_console_monitor_win.h"
33 33
34 using base::win::ScopedHandle; 34 using base::win::ScopedHandle;
35 using base::TimeDelta; 35 using base::TimeDelta;
36 36
37 namespace { 37 namespace {
38 38
39 // The exit code returned by the host process when its configuration is not 39 // The exit code returned by the host process when its configuration is not
40 // valid. 40 // valid.
41 const int kInvalidHostConfigurationExitCode = 1; 41 const int kInvalidHostConfigurationExitCode = 1;
42 42
43 // The minimum and maximum delays between attempts to inject host process into 43 // The minimum and maximum delays between attempts to inject host process into
44 // a session. 44 // a session.
45 const int kMaxLaunchDelaySeconds = 60; 45 const int kMaxLaunchDelaySeconds = 60;
46 const int kMinLaunchDelaySeconds = 1; 46 const int kMinLaunchDelaySeconds = 1;
47 47
48 // Name of the default session desktop. 48 // Name of the default session desktop.
49 const char kDefaultDesktopName[] = "winsta0\\default"; 49 char16 kDefaultDesktopName[] = TO_L_STRING("winsta0\\default");
50 50
51 // Match the pipe name prefix used by Chrome IPC channels. 51 // Match the pipe name prefix used by Chrome IPC channels.
52 const char kChromePipeNamePrefix[] = "\\\\.\\pipe\\chrome."; 52 const char16 kChromePipeNamePrefix[] = TO_L_STRING("\\\\.\\pipe\\chrome.");
53 53
54 // The IPC channel name is passed to the host in the command line. 54 // The IPC channel name is passed to the host in the command line.
55 const char kChromotingIpcSwitchName[] = "chromoting-ipc"; 55 const char kChromotingIpcSwitchName[] = "chromoting-ipc";
56 56
57 // The command line parameters that should be copied from the service's command 57 // The command line parameters that should be copied from the service's command
58 // line to the host process. 58 // line to the host process.
59 const char* kCopiedSwitchNames[] = { "auth-config", "host-config" }; 59 const char* kCopiedSwitchNames[] = { "auth-config", "host-config" };
60 60
61 // The security descriptor of the Chromoting IPC channel. It gives full access 61 // The security descriptor of the Chromoting IPC channel. It gives full access
62 // to LocalSystem and denies access by anyone else. 62 // to LocalSystem and denies access by anyone else.
63 const char kChromotingChannelSecurityDescriptor[] = 63 const char16 kChromotingChannelSecurityDescriptor[] =
64 "O:SY" "G:SY" "D:(A;;GA;;;SY)"; 64 TO_L_STRING("O:SYG:SYD:(A;;GA;;;SY)");
65 65
66 // Takes the process token and makes a copy of it. The returned handle will have 66 // Takes the process token and makes a copy of it. The returned handle will have
67 // |desired_access| rights. 67 // |desired_access| rights.
68 bool CopyProcessToken(DWORD desired_access, 68 bool CopyProcessToken(DWORD desired_access,
69 ScopedHandle* token_out) { 69 ScopedHandle* token_out) {
70 70
71 HANDLE handle; 71 HANDLE handle;
72 if (!OpenProcessToken(GetCurrentProcess(), 72 if (!OpenProcessToken(GetCurrentProcess(),
73 TOKEN_DUPLICATE | desired_access, 73 TOKEN_DUPLICATE | desired_access,
74 &handle)) { 74 &handle)) {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 return false; 145 return false;
146 } 146 }
147 147
148 token_out->Set(session_token.Take()); 148 token_out->Set(session_token.Take());
149 return true; 149 return true;
150 } 150 }
151 151
152 // Generates random channel ID. 152 // Generates random channel ID.
153 // N.B. Stolen from src/content/common/child_process_host_impl.cc 153 // N.B. Stolen from src/content/common/child_process_host_impl.cc
154 string16 GenerateRandomChannelId(void* instance) { 154 string16 GenerateRandomChannelId(void* instance) {
155 return base::StringPrintf(ASCIIToUTF16("%d.%p.%d").c_str(), 155 return base::StringPrintf(TO_L_STRING("%d.%p.%d"),
156 base::GetCurrentProcId(), instance, 156 base::GetCurrentProcId(), instance,
157 base::RandInt(0, std::numeric_limits<int>::max())); 157 base::RandInt(0, std::numeric_limits<int>::max()));
158 } 158 }
159 159
160 // Creates the server end of the Chromoting IPC channel. 160 // Creates the server end of the Chromoting IPC channel.
161 // N.B. This code is based on IPC::Channel's implementation. 161 // N.B. This code is based on IPC::Channel's implementation.
162 bool CreatePipeForIpcChannel(void* instance, 162 bool CreatePipeForIpcChannel(void* instance,
163 string16* channel_name_out, 163 string16* channel_name_out,
164 ScopedHandle* pipe_out) { 164 ScopedHandle* pipe_out) {
165 // Create security descriptor for the channel. 165 // Create security descriptor for the channel.
166 SECURITY_ATTRIBUTES security_attributes; 166 SECURITY_ATTRIBUTES security_attributes;
167 security_attributes.nLength = sizeof(security_attributes); 167 security_attributes.nLength = sizeof(security_attributes);
168 security_attributes.bInheritHandle = FALSE; 168 security_attributes.bInheritHandle = FALSE;
169 169
170 ULONG security_descriptor_length = 0; 170 ULONG security_descriptor_length = 0;
171 if (!ConvertStringSecurityDescriptorToSecurityDescriptorA( 171 if (!ConvertStringSecurityDescriptorToSecurityDescriptorW(
172 kChromotingChannelSecurityDescriptor, 172 kChromotingChannelSecurityDescriptor,
173 SDDL_REVISION_1, 173 SDDL_REVISION_1,
174 reinterpret_cast<PSECURITY_DESCRIPTOR*>( 174 reinterpret_cast<PSECURITY_DESCRIPTOR*>(
175 &security_attributes.lpSecurityDescriptor), 175 &security_attributes.lpSecurityDescriptor),
176 &security_descriptor_length)) { 176 &security_descriptor_length)) {
177 LOG_GETLASTERROR(ERROR) << 177 LOG_GETLASTERROR(ERROR) <<
178 "Failed to create a security descriptor for the Chromoting IPC channel"; 178 "Failed to create a security descriptor for the Chromoting IPC channel";
179 return false; 179 return false;
180 } 180 }
181 181
182 // Generate a random channel name. 182 // Generate a random channel name.
183 string16 channel_name(GenerateRandomChannelId(instance)); 183 string16 channel_name(GenerateRandomChannelId(instance));
184 184
185 // Convert it to the pipe name. 185 // Convert it to the pipe name.
186 string16 pipe_name(ASCIIToUTF16(kChromePipeNamePrefix)); 186 string16 pipe_name(kChromePipeNamePrefix);
187 pipe_name.append(channel_name); 187 pipe_name.append(channel_name);
188 188
189 // Create the server end of the pipe. This code should match the code in 189 // Create the server end of the pipe. This code should match the code in
190 // IPC::Channel with exception of passing a non-default security descriptor. 190 // IPC::Channel with exception of passing a non-default security descriptor.
191 HANDLE pipe = CreateNamedPipeW(pipe_name.c_str(), 191 HANDLE pipe = CreateNamedPipeW(pipe_name.c_str(),
192 PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED | 192 PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED |
193 FILE_FLAG_FIRST_PIPE_INSTANCE, 193 FILE_FLAG_FIRST_PIPE_INSTANCE,
194 PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 194 PIPE_TYPE_BYTE | PIPE_READMODE_BYTE,
195 1, 195 1,
196 IPC::Channel::kReadBufferSize, 196 IPC::Channel::kReadBufferSize,
(...skipping 13 matching lines...) Expand all
210 pipe_out->Set(pipe); 210 pipe_out->Set(pipe);
211 return true; 211 return true;
212 } 212 }
213 213
214 // Launches |binary| in the security context of the supplied |user_token|. 214 // Launches |binary| in the security context of the supplied |user_token|.
215 bool LaunchProcessAsUser(const FilePath& binary, 215 bool LaunchProcessAsUser(const FilePath& binary,
216 const string16& command_line, 216 const string16& command_line,
217 HANDLE user_token, 217 HANDLE user_token,
218 base::Process* process_out) { 218 base::Process* process_out) {
219 string16 application_name = binary.value(); 219 string16 application_name = binary.value();
220 string16 desktop = ASCIIToUTF16(kDefaultDesktopName);
221 220
222 base::win::ScopedProcessInformation process_info; 221 base::win::ScopedProcessInformation process_info;
223 STARTUPINFOW startup_info; 222 STARTUPINFOW startup_info;
224 223
225 memset(&startup_info, 0, sizeof(startup_info)); 224 memset(&startup_info, 0, sizeof(startup_info));
226 startup_info.cb = sizeof(startup_info); 225 startup_info.cb = sizeof(startup_info);
227 startup_info.lpDesktop = const_cast<LPWSTR>(desktop.c_str()); 226 startup_info.lpDesktop = kDefaultDesktopName;
228 227
229 if (!CreateProcessAsUserW(user_token, 228 if (!CreateProcessAsUserW(user_token,
230 application_name.c_str(), 229 application_name.c_str(),
231 const_cast<LPWSTR>(command_line.c_str()), 230 const_cast<LPWSTR>(command_line.c_str()),
232 NULL, 231 NULL,
233 NULL, 232 NULL,
234 FALSE, 233 FALSE,
235 0, 234 0,
236 NULL, 235 NULL,
237 NULL, 236 NULL,
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 process_watcher_.StopWatching(); 488 process_watcher_.StopWatching();
490 process_.Terminate(0); 489 process_.Terminate(0);
491 process_.Close(); 490 process_.Close();
492 chromoting_channel_.reset(); 491 chromoting_channel_.reset();
493 state_ = StateDetached; 492 state_ = StateDetached;
494 break; 493 break;
495 } 494 }
496 } 495 }
497 496
498 } // namespace remoting 497 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/sas_injector_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698