| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/security_key/remote_security_key_main.h" | 5 #include "remoting/host/security_key/remote_security_key_main.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/at_exit.h" | 11 #include "base/at_exit.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 15 #include "remoting/host/host_exit_codes.h" | 15 #include "remoting/host/host_exit_codes.h" |
| 16 #include "remoting/host/logging.h" | 16 #include "remoting/host/logging.h" |
| 17 #include "remoting/host/security_key/security_key_ipc_client.h" | 17 #include "remoting/host/security_key/remote_security_key_ipc_client.h" |
| 18 #include "remoting/host/security_key/security_key_message_handler.h" | 18 #include "remoting/host/security_key/remote_security_key_message_handler.h" |
| 19 | 19 |
| 20 #if defined(OS_WIN) | 20 #if defined(OS_WIN) |
| 21 #include <aclapi.h> | 21 #include <aclapi.h> |
| 22 #include <windows.h> | 22 #include <windows.h> |
| 23 | 23 |
| 24 #include "base/win/scoped_handle.h" | 24 #include "base/win/scoped_handle.h" |
| 25 #endif // defined(OS_WIN) | 25 #endif // defined(OS_WIN) |
| 26 | 26 |
| 27 #if defined(OS_WIN) | 27 #if defined(OS_WIN) |
| 28 namespace { | 28 namespace { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 return kInitializationFailed; | 112 return kInitializationFailed; |
| 113 } | 113 } |
| 114 | 114 |
| 115 // GetStdHandle() returns pseudo-handles for stdin and stdout even if | 115 // GetStdHandle() returns pseudo-handles for stdin and stdout even if |
| 116 // the hosting executable specifies "Windows" subsystem. However the returned | 116 // the hosting executable specifies "Windows" subsystem. However the returned |
| 117 // handles are invalid in that case unless standard input and output are | 117 // handles are invalid in that case unless standard input and output are |
| 118 // redirected to a pipe or file. | 118 // redirected to a pipe or file. |
| 119 base::File read_file(GetStdHandle(STD_INPUT_HANDLE)); | 119 base::File read_file(GetStdHandle(STD_INPUT_HANDLE)); |
| 120 base::File write_file(GetStdHandle(STD_OUTPUT_HANDLE)); | 120 base::File write_file(GetStdHandle(STD_OUTPUT_HANDLE)); |
| 121 | 121 |
| 122 // After the message handler starts, the security key message reader | 122 // After the message handler starts, the remote security key message reader |
| 123 // will keep doing blocking read operations on the input named pipe. | 123 // will keep doing blocking read operations on the input named pipe. |
| 124 // If any other thread tries to perform any operation on STDIN, it will also | 124 // If any other thread tries to perform any operation on STDIN, it will also |
| 125 // block because the input named pipe is synchronous (non-overlapped). | 125 // block because the input named pipe is synchronous (non-overlapped). |
| 126 // It is pretty common for a DLL to query the device info (GetFileType) of | 126 // It is pretty common for a DLL to query the device info (GetFileType) of |
| 127 // the STD* handles at startup. So any LoadLibrary request can potentially | 127 // the STD* handles at startup. So any LoadLibrary request can potentially |
| 128 // be blocked. To prevent that from happening we close STDIN and STDOUT | 128 // be blocked. To prevent that from happening we close STDIN and STDOUT |
| 129 // handles as soon as we retrieve the corresponding file handles. | 129 // handles as soon as we retrieve the corresponding file handles. |
| 130 SetStdHandle(STD_INPUT_HANDLE, nullptr); | 130 SetStdHandle(STD_INPUT_HANDLE, nullptr); |
| 131 SetStdHandle(STD_OUTPUT_HANDLE, nullptr); | 131 SetStdHandle(STD_OUTPUT_HANDLE, nullptr); |
| 132 #elif defined(OS_POSIX) | 132 #elif defined(OS_POSIX) |
| 133 // The files are automatically closed. | 133 // The files are automatically closed. |
| 134 base::File read_file(STDIN_FILENO); | 134 base::File read_file(STDIN_FILENO); |
| 135 base::File write_file(STDOUT_FILENO); | 135 base::File write_file(STDOUT_FILENO); |
| 136 #else | 136 #else |
| 137 #error Not implemented. | 137 #error Not implemented. |
| 138 #endif | 138 #endif |
| 139 | 139 |
| 140 base::RunLoop run_loop; | 140 base::RunLoop run_loop; |
| 141 | 141 |
| 142 std::unique_ptr<SecurityKeyIpcClient> ipc_client(new SecurityKeyIpcClient()); | 142 std::unique_ptr<RemoteSecurityKeyIpcClient> ipc_client( |
| 143 new RemoteSecurityKeyIpcClient()); |
| 143 | 144 |
| 144 SecurityKeyMessageHandler message_handler; | 145 RemoteSecurityKeyMessageHandler message_handler; |
| 145 message_handler.Start(std::move(read_file), std::move(write_file), | 146 message_handler.Start(std::move(read_file), std::move(write_file), |
| 146 std::move(ipc_client), run_loop.QuitClosure()); | 147 std::move(ipc_client), run_loop.QuitClosure()); |
| 147 | 148 |
| 148 run_loop.Run(); | 149 run_loop.Run(); |
| 149 | 150 |
| 150 return kSuccessExitCode; | 151 return kSuccessExitCode; |
| 151 } | 152 } |
| 152 | 153 |
| 153 int RemoteSecurityKeyMain(int argc, char** argv) { | 154 int RemoteSecurityKeyMain(int argc, char** argv) { |
| 154 // This object instance is required by Chrome classes (such as MessageLoop). | 155 // This object instance is required by Chrome classes (such as MessageLoop). |
| 155 base::AtExitManager exit_manager; | 156 base::AtExitManager exit_manager; |
| 156 base::MessageLoopForIO message_loop; | 157 base::MessageLoopForIO message_loop; |
| 157 | 158 |
| 158 base::CommandLine::Init(argc, argv); | 159 base::CommandLine::Init(argc, argv); |
| 159 remoting::InitHostLogging(); | 160 remoting::InitHostLogging(); |
| 160 | 161 |
| 161 return StartRemoteSecurityKey(); | 162 return StartRemoteSecurityKey(); |
| 162 } | 163 } |
| 163 | 164 |
| 164 } // namespace remoting | 165 } // namespace remoting |
| OLD | NEW |