OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ipc_util.h" | 5 #include "remoting/host/ipc_util.h" |
6 | 6 |
| 7 #include "base/files/file.h" |
7 #include "base/logging.h" | 8 #include "base/logging.h" |
8 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
9 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
11 #include "base/win/scoped_handle.h" | 12 #include "base/win/scoped_handle.h" |
12 #include "base/win/win_util.h" | 13 #include "base/win/win_util.h" |
13 #include "ipc/ipc_channel.h" | 14 #include "ipc/ipc_channel.h" |
14 #include "ipc/ipc_channel_proxy.h" | 15 #include "ipc/ipc_channel_proxy.h" |
15 #include "remoting/host/win/security_descriptor.h" | 16 #include "remoting/host/win/security_descriptor.h" |
16 | 17 |
17 using base::win::ScopedHandle; | 18 using base::win::ScopedHandle; |
18 | 19 |
19 namespace remoting { | 20 namespace remoting { |
20 | 21 |
21 // Pipe name prefix used by Chrome IPC channels to convert a channel name into | 22 // Pipe name prefix used by Chrome IPC channels to convert a channel name into |
22 // a pipe name. | 23 // a pipe name. |
23 const char kChromePipeNamePrefix[] = "\\\\.\\pipe\\chrome."; | 24 const char kChromePipeNamePrefix[] = "\\\\.\\pipe\\chrome."; |
24 | 25 |
25 bool CreateConnectedIpcChannel( | 26 bool CreateConnectedIpcChannel( |
26 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, | 27 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
27 IPC::Listener* listener, | 28 IPC::Listener* listener, |
28 IPC::PlatformFileForTransit* client_out, | 29 base::File* client_out, |
29 scoped_ptr<IPC::ChannelProxy>* server_out) { | 30 scoped_ptr<IPC::ChannelProxy>* server_out) { |
30 // presubmit: allow wstring | 31 // presubmit: allow wstring |
31 std::wstring user_sid; | 32 std::wstring user_sid; |
32 if (!base::win::GetUserSidString(&user_sid)) { | 33 if (!base::win::GetUserSidString(&user_sid)) { |
33 LOG(ERROR) << "Failed to query the current user SID."; | 34 LOG(ERROR) << "Failed to query the current user SID."; |
34 return false; | 35 return false; |
35 } | 36 } |
36 | 37 |
37 // Create a security descriptor that will be used to protect the named pipe in | 38 // Create a security descriptor that will be used to protect the named pipe in |
38 // between CreateNamedPipe() and CreateFile() calls before it will be passed | 39 // between CreateNamedPipe() and CreateFile() calls before it will be passed |
(...skipping 22 matching lines...) Expand all Loading... |
61 std::string pipe_name(kChromePipeNamePrefix); | 62 std::string pipe_name(kChromePipeNamePrefix); |
62 pipe_name.append(channel_name); | 63 pipe_name.append(channel_name); |
63 | 64 |
64 SECURITY_ATTRIBUTES security_attributes = {0}; | 65 SECURITY_ATTRIBUTES security_attributes = {0}; |
65 security_attributes.nLength = sizeof(security_attributes); | 66 security_attributes.nLength = sizeof(security_attributes); |
66 security_attributes.lpSecurityDescriptor = NULL; | 67 security_attributes.lpSecurityDescriptor = NULL; |
67 security_attributes.bInheritHandle = TRUE; | 68 security_attributes.bInheritHandle = TRUE; |
68 | 69 |
69 // Create the client end of the channel. This code should match the code in | 70 // Create the client end of the channel. This code should match the code in |
70 // IPC::Channel. | 71 // IPC::Channel. |
71 ScopedHandle client; | 72 base::File client(CreateFile(base::UTF8ToUTF16(pipe_name).c_str(), |
72 client.Set(CreateFile(base::UTF8ToUTF16(pipe_name).c_str(), | 73 GENERIC_READ | GENERIC_WRITE, |
73 GENERIC_READ | GENERIC_WRITE, | 74 0, |
74 0, | 75 &security_attributes, |
75 &security_attributes, | 76 OPEN_EXISTING, |
76 OPEN_EXISTING, | 77 SECURITY_SQOS_PRESENT | SECURITY_IDENTIFICATION | |
77 SECURITY_SQOS_PRESENT | SECURITY_IDENTIFICATION | | 78 FILE_FLAG_OVERLAPPED, |
78 FILE_FLAG_OVERLAPPED, | 79 NULL)); |
79 NULL)); | |
80 if (!client.IsValid()) { | 80 if (!client.IsValid()) { |
81 PLOG(ERROR) << "Failed to connect to '" << pipe_name << "'"; | 81 PLOG(ERROR) << "Failed to connect to '" << pipe_name << "'"; |
82 return false; | 82 return false; |
83 } | 83 } |
84 | 84 |
85 *client_out = client.Take(); | 85 *client_out = client.Pass(); |
86 *server_out = server.Pass(); | 86 *server_out = server.Pass(); |
87 return true; | 87 return true; |
88 } | 88 } |
89 | 89 |
90 bool CreateIpcChannel( | 90 bool CreateIpcChannel( |
91 const std::string& channel_name, | 91 const std::string& channel_name, |
92 const std::string& pipe_security_descriptor, | 92 const std::string& pipe_security_descriptor, |
93 base::win::ScopedHandle* pipe_out) { | 93 base::win::ScopedHandle* pipe_out) { |
94 // Create security descriptor for the channel. | 94 // Create security descriptor for the channel. |
95 ScopedSd sd = ConvertSddlToSd(pipe_security_descriptor); | 95 ScopedSd sd = ConvertSddlToSd(pipe_security_descriptor); |
(...skipping 28 matching lines...) Expand all Loading... |
124 PLOG(ERROR) | 124 PLOG(ERROR) |
125 << "Failed to create the server end of the Chromoting IPC channel"; | 125 << "Failed to create the server end of the Chromoting IPC channel"; |
126 return false; | 126 return false; |
127 } | 127 } |
128 | 128 |
129 *pipe_out = pipe.Pass(); | 129 *pipe_out = pipe.Pass(); |
130 return true; | 130 return true; |
131 } | 131 } |
132 | 132 |
133 } // namespace remoting | 133 } // namespace remoting |
OLD | NEW |