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

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

Issue 9700038: ScopedProcessInformation protects against process/thread handle leaks from CreateProcess calls. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add tests for new functions. 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
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/logging.h" 14 #include "base/logging.h"
15 #include "base/process_util.h" 15 #include "base/process_util.h"
16 #include "base/rand_util.h" 16 #include "base/rand_util.h"
17 #include "base/string16.h" 17 #include "base/string16.h"
18 #include "base/stringprintf.h" 18 #include "base/stringprintf.h"
19 #include "base/threading/thread.h" 19 #include "base/threading/thread.h"
20 #include "base/utf_string_conversions.h" 20 #include "base/utf_string_conversions.h"
21 #include "base/win/scoped_handle.h" 21 #include "base/win/scoped_handle.h"
22 #include "base/win/scoped_process_information.h"
22 #include "ipc/ipc_channel_proxy.h" 23 #include "ipc/ipc_channel_proxy.h"
23 #include "ipc/ipc_message.h" 24 #include "ipc/ipc_message.h"
24 #include "ipc/ipc_message_macros.h" 25 #include "ipc/ipc_message_macros.h"
25 26
26 #include "remoting/host/chromoting_messages.h" 27 #include "remoting/host/chromoting_messages.h"
27 #include "remoting/host/sas_injector.h" 28 #include "remoting/host/sas_injector.h"
28 #include "remoting/host/wts_console_monitor_win.h" 29 #include "remoting/host/wts_console_monitor_win.h"
29 30
30 using base::win::ScopedHandle; 31 using base::win::ScopedHandle;
31 using base::TimeDelta; 32 using base::TimeDelta;
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 } 201 }
201 202
202 // Launches |binary| in the security context of the supplied |user_token|. 203 // Launches |binary| in the security context of the supplied |user_token|.
203 bool LaunchProcessAsUser(const FilePath& binary, 204 bool LaunchProcessAsUser(const FilePath& binary,
204 const string16& command_line, 205 const string16& command_line,
205 HANDLE user_token, 206 HANDLE user_token,
206 base::Process* process_out) { 207 base::Process* process_out) {
207 string16 application_name = binary.value(); 208 string16 application_name = binary.value();
208 string16 desktop = ASCIIToUTF16(kDefaultDesktopName); 209 string16 desktop = ASCIIToUTF16(kDefaultDesktopName);
209 210
210 PROCESS_INFORMATION process_info; 211 base::win::ScopedProcessInformation process_info;
211 STARTUPINFOW startup_info; 212 STARTUPINFOW startup_info;
212 213
213 memset(&startup_info, 0, sizeof(startup_info)); 214 memset(&startup_info, 0, sizeof(startup_info));
214 startup_info.cb = sizeof(startup_info); 215 startup_info.cb = sizeof(startup_info);
215 startup_info.lpDesktop = const_cast<LPWSTR>(desktop.c_str()); 216 startup_info.lpDesktop = const_cast<LPWSTR>(desktop.c_str());
216 217
217 if (!CreateProcessAsUserW(user_token, 218 if (!CreateProcessAsUserW(user_token,
218 application_name.c_str(), 219 application_name.c_str(),
219 const_cast<LPWSTR>(command_line.c_str()), 220 const_cast<LPWSTR>(command_line.c_str()),
220 NULL, 221 NULL,
221 NULL, 222 NULL,
222 FALSE, 223 FALSE,
223 0, 224 0,
224 NULL, 225 NULL,
225 NULL, 226 NULL,
226 &startup_info, 227 &startup_info,
227 &process_info)) { 228 process_info.Receive())) {
228 LOG_GETLASTERROR(ERROR) << 229 LOG_GETLASTERROR(ERROR) <<
229 "Failed to launch a process with a user token"; 230 "Failed to launch a process with a user token";
230 return false; 231 return false;
231 } 232 }
232 233
233 CloseHandle(process_info.hThread); 234 process_out->set_handle(process_info.TakeProcessHandle());
234 process_out->set_handle(process_info.hProcess);
235 return true; 235 return true;
236 } 236 }
237 237
238 } // namespace 238 } // namespace
239 239
240 namespace remoting { 240 namespace remoting {
241 241
242 WtsSessionProcessLauncher::WtsSessionProcessLauncher( 242 WtsSessionProcessLauncher::WtsSessionProcessLauncher(
243 WtsConsoleMonitor* monitor, 243 WtsConsoleMonitor* monitor,
244 const FilePath& host_binary, 244 const FilePath& host_binary,
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 process_watcher_.StopWatching(); 434 process_watcher_.StopWatching();
435 process_.Terminate(0); 435 process_.Terminate(0);
436 process_.Close(); 436 process_.Close();
437 chromoting_channel_.reset(); 437 chromoting_channel_.reset();
438 state_ = StateDetached; 438 state_ = StateDetached;
439 break; 439 break;
440 } 440 }
441 } 441 }
442 442
443 } // namespace remoting 443 } // namespace remoting
OLDNEW
« base/win/scoped_process_information.cc ('K') | « base/win/scoped_process_information_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698