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 <winternl.h> | 8 #include <winternl.h> |
9 | 9 |
10 #include <limits> | 10 #include <limits> |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 if (!WaitNamedPipe(pipe_name.c_str(), kPipeBusyWaitTimeoutMs)) { | 109 if (!WaitNamedPipe(pipe_name.c_str(), kPipeBusyWaitTimeoutMs)) { |
110 break; | 110 break; |
111 } | 111 } |
112 } | 112 } |
113 | 113 |
114 if (!pipe.IsValid()) { | 114 if (!pipe.IsValid()) { |
115 PLOG(ERROR) << "Failed to connect to '" << pipe_name << "'"; | 115 PLOG(ERROR) << "Failed to connect to '" << pipe_name << "'"; |
116 return false; | 116 return false; |
117 } | 117 } |
118 | 118 |
119 *pipe_out = pipe.Pass(); | 119 *pipe_out = std::move(pipe); |
120 return true; | 120 return true; |
121 } | 121 } |
122 | 122 |
123 // Copies the process token making it a primary impersonation token. | 123 // Copies the process token making it a primary impersonation token. |
124 // The returned handle will have |desired_access| rights. | 124 // The returned handle will have |desired_access| rights. |
125 bool CopyProcessToken(DWORD desired_access, ScopedHandle* token_out) { | 125 bool CopyProcessToken(DWORD desired_access, ScopedHandle* token_out) { |
126 HANDLE temp_handle; | 126 HANDLE temp_handle; |
127 if (!OpenProcessToken(GetCurrentProcess(), | 127 if (!OpenProcessToken(GetCurrentProcess(), |
128 TOKEN_DUPLICATE | desired_access, | 128 TOKEN_DUPLICATE | desired_access, |
129 &temp_handle)) { | 129 &temp_handle)) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 return false; | 164 return false; |
165 } | 165 } |
166 | 166 |
167 // Enable the SE_TCB_NAME privilege. | 167 // Enable the SE_TCB_NAME privilege. |
168 if (!AdjustTokenPrivileges(privileged_token.Get(), FALSE, &state, 0, nullptr, | 168 if (!AdjustTokenPrivileges(privileged_token.Get(), FALSE, &state, 0, nullptr, |
169 0)) { | 169 0)) { |
170 PLOG(ERROR) << "Failed to enable SE_TCB_NAME privilege in a token"; | 170 PLOG(ERROR) << "Failed to enable SE_TCB_NAME privilege in a token"; |
171 return false; | 171 return false; |
172 } | 172 } |
173 | 173 |
174 *token_out = privileged_token.Pass(); | 174 *token_out = std::move(privileged_token); |
175 return true; | 175 return true; |
176 } | 176 } |
177 | 177 |
178 // Fills the process and thread handles in the passed |process_information| | 178 // Fills the process and thread handles in the passed |process_information| |
179 // structure and resume the process if the caller didn't want to suspend it. | 179 // structure and resume the process if the caller didn't want to suspend it. |
180 bool ProcessCreateProcessResponse(DWORD creation_flags, | 180 bool ProcessCreateProcessResponse(DWORD creation_flags, |
181 PROCESS_INFORMATION* process_information) { | 181 PROCESS_INFORMATION* process_information) { |
182 // The execution server does not return handles to the created process and | 182 // The execution server does not return handles to the created process and |
183 // thread. | 183 // thread. |
184 if (!process_information->hProcess) { | 184 if (!process_information->hProcess) { |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 PLOG(ERROR) << "Failed to change session ID of a token"; | 436 PLOG(ERROR) << "Failed to change session ID of a token"; |
437 | 437 |
438 // Revert to the default token. | 438 // Revert to the default token. |
439 CHECK(RevertToSelf()); | 439 CHECK(RevertToSelf()); |
440 return false; | 440 return false; |
441 } | 441 } |
442 | 442 |
443 // Revert to the default token. | 443 // Revert to the default token. |
444 CHECK(RevertToSelf()); | 444 CHECK(RevertToSelf()); |
445 | 445 |
446 *token_out = session_token.Pass(); | 446 *token_out = std::move(session_token); |
447 return true; | 447 return true; |
448 } | 448 } |
449 | 449 |
450 bool LaunchProcessWithToken(const base::FilePath& binary, | 450 bool LaunchProcessWithToken(const base::FilePath& binary, |
451 const base::CommandLine::StringType& command_line, | 451 const base::CommandLine::StringType& command_line, |
452 HANDLE user_token, | 452 HANDLE user_token, |
453 SECURITY_ATTRIBUTES* process_attributes, | 453 SECURITY_ATTRIBUTES* process_attributes, |
454 SECURITY_ATTRIBUTES* thread_attributes, | 454 SECURITY_ATTRIBUTES* thread_attributes, |
455 bool inherit_handles, | 455 bool inherit_handles, |
456 DWORD creation_flags, | 456 DWORD creation_flags, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 | 515 |
516 base::win::ScopedProcessInformation process_info(temp_process_info); | 516 base::win::ScopedProcessInformation process_info(temp_process_info); |
517 | 517 |
518 CHECK(process_info.IsValid()); | 518 CHECK(process_info.IsValid()); |
519 process_out->Set(process_info.TakeProcessHandle()); | 519 process_out->Set(process_info.TakeProcessHandle()); |
520 thread_out->Set(process_info.TakeThreadHandle()); | 520 thread_out->Set(process_info.TakeThreadHandle()); |
521 return true; | 521 return true; |
522 } | 522 } |
523 | 523 |
524 } // namespace remoting | 524 } // namespace remoting |
OLD | NEW |