| OLD | NEW |
| 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/win/launch_process_with_token.h" | 5 #include "remoting/host/win/launch_process_with_token.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <stddef.h> |
| 8 #include <winternl.h> | 9 #include <winternl.h> |
| 9 | 10 |
| 10 #include <limits> | 11 #include <limits> |
| 11 | 12 |
| 12 #include "base/logging.h" | 13 #include "base/logging.h" |
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/rand_util.h" | 15 #include "base/rand_util.h" |
| 15 #include "base/scoped_native_library.h" | 16 #include "base/scoped_native_library.h" |
| 16 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
| 17 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 45 } | 46 } |
| 46 | 47 |
| 47 if (process_information->hProcess) { | 48 if (process_information->hProcess) { |
| 48 TerminateProcess(process_information->hProcess, CONTROL_C_EXIT); | 49 TerminateProcess(process_information->hProcess, CONTROL_C_EXIT); |
| 49 CloseHandle(process_information->hProcess); | 50 CloseHandle(process_information->hProcess); |
| 50 process_information->hProcess = nullptr; | 51 process_information->hProcess = nullptr; |
| 51 } | 52 } |
| 52 } | 53 } |
| 53 | 54 |
| 54 // Connects to the executor server corresponding to |session_id|. | 55 // Connects to the executor server corresponding to |session_id|. |
| 55 bool ConnectToExecutionServer(uint32 session_id, | 56 bool ConnectToExecutionServer(uint32_t session_id, |
| 56 base::win::ScopedHandle* pipe_out) { | 57 base::win::ScopedHandle* pipe_out) { |
| 57 base::string16 pipe_name; | 58 base::string16 pipe_name; |
| 58 | 59 |
| 59 // Use winsta!WinStationQueryInformationW() to determine the process creation | 60 // Use winsta!WinStationQueryInformationW() to determine the process creation |
| 60 // pipe name for the session. | 61 // pipe name for the session. |
| 61 base::FilePath winsta_path( | 62 base::FilePath winsta_path( |
| 62 base::GetNativeLibraryName(base::UTF8ToUTF16("winsta"))); | 63 base::GetNativeLibraryName(base::UTF8ToUTF16("winsta"))); |
| 63 base::ScopedNativeLibrary winsta(winsta_path); | 64 base::ScopedNativeLibrary winsta(winsta_path); |
| 64 if (winsta.is_valid()) { | 65 if (winsta.is_valid()) { |
| 65 PWINSTATIONQUERYINFORMATIONW win_station_query_information = | 66 PWINSTATIONQUERYINFORMATIONW win_station_query_information = |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 return false; | 363 return false; |
| 363 } | 364 } |
| 364 | 365 |
| 365 return true; | 366 return true; |
| 366 } | 367 } |
| 367 | 368 |
| 368 // Requests the execution server to create a process in the specified session | 369 // Requests the execution server to create a process in the specified session |
| 369 // using the default (i.e. Winlogon) token. This routine relies on undocumented | 370 // using the default (i.e. Winlogon) token. This routine relies on undocumented |
| 370 // OS functionality and will likely not work on anything but XP or W2K3. | 371 // OS functionality and will likely not work on anything but XP or W2K3. |
| 371 bool CreateRemoteSessionProcess( | 372 bool CreateRemoteSessionProcess( |
| 372 uint32 session_id, | 373 uint32_t session_id, |
| 373 const base::FilePath::StringType& application_name, | 374 const base::FilePath::StringType& application_name, |
| 374 const base::CommandLine::StringType& command_line, | 375 const base::CommandLine::StringType& command_line, |
| 375 DWORD creation_flags, | 376 DWORD creation_flags, |
| 376 const base::char16* desktop_name, | 377 const base::char16* desktop_name, |
| 377 PROCESS_INFORMATION* process_information_out) { | 378 PROCESS_INFORMATION* process_information_out) { |
| 378 DCHECK_LT(base::win::GetVersion(), base::win::VERSION_VISTA); | 379 DCHECK_LT(base::win::GetVersion(), base::win::VERSION_VISTA); |
| 379 | 380 |
| 380 base::win::ScopedHandle pipe; | 381 base::win::ScopedHandle pipe; |
| 381 if (!ConnectToExecutionServer(session_id, &pipe)) | 382 if (!ConnectToExecutionServer(session_id, &pipe)) |
| 382 return false; | 383 return false; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 401 | 402 |
| 402 } // namespace | 403 } // namespace |
| 403 | 404 |
| 404 namespace remoting { | 405 namespace remoting { |
| 405 | 406 |
| 406 base::LazyInstance<base::Lock>::Leaky g_inherit_handles_lock = | 407 base::LazyInstance<base::Lock>::Leaky g_inherit_handles_lock = |
| 407 LAZY_INSTANCE_INITIALIZER; | 408 LAZY_INSTANCE_INITIALIZER; |
| 408 | 409 |
| 409 // Creates a copy of the current process token for the given |session_id| so | 410 // Creates a copy of the current process token for the given |session_id| so |
| 410 // it can be used to launch a process in that session. | 411 // it can be used to launch a process in that session. |
| 411 bool CreateSessionToken(uint32 session_id, ScopedHandle* token_out) { | 412 bool CreateSessionToken(uint32_t session_id, ScopedHandle* token_out) { |
| 412 ScopedHandle session_token; | 413 ScopedHandle session_token; |
| 413 DWORD desired_access = TOKEN_ADJUST_DEFAULT | TOKEN_ADJUST_SESSIONID | | 414 DWORD desired_access = TOKEN_ADJUST_DEFAULT | TOKEN_ADJUST_SESSIONID | |
| 414 TOKEN_ASSIGN_PRIMARY | TOKEN_DUPLICATE | TOKEN_QUERY; | 415 TOKEN_ASSIGN_PRIMARY | TOKEN_DUPLICATE | TOKEN_QUERY; |
| 415 if (!CopyProcessToken(desired_access, &session_token)) { | 416 if (!CopyProcessToken(desired_access, &session_token)) { |
| 416 return false; | 417 return false; |
| 417 } | 418 } |
| 418 | 419 |
| 419 // Temporarily enable the SE_TCB_NAME privilege as it is required by | 420 // Temporarily enable the SE_TCB_NAME privilege as it is required by |
| 420 // SetTokenInformation(TokenSessionId). | 421 // SetTokenInformation(TokenSessionId). |
| 421 ScopedHandle privileged_token; | 422 ScopedHandle privileged_token; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 | 516 |
| 516 base::win::ScopedProcessInformation process_info(temp_process_info); | 517 base::win::ScopedProcessInformation process_info(temp_process_info); |
| 517 | 518 |
| 518 CHECK(process_info.IsValid()); | 519 CHECK(process_info.IsValid()); |
| 519 process_out->Set(process_info.TakeProcessHandle()); | 520 process_out->Set(process_info.TakeProcessHandle()); |
| 520 thread_out->Set(process_info.TakeThreadHandle()); | 521 thread_out->Set(process_info.TakeThreadHandle()); |
| 521 return true; | 522 return true; |
| 522 } | 523 } |
| 523 | 524 |
| 524 } // namespace remoting | 525 } // namespace remoting |
| OLD | NEW |