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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 namespace remoting { | 22 namespace remoting { |
23 | 23 |
24 // Pipe name prefix used by Chrome IPC channels to convert a channel name into | 24 // Pipe name prefix used by Chrome IPC channels to convert a channel name into |
25 // a pipe name. | 25 // a pipe name. |
26 const char kChromePipeNamePrefix[] = "\\\\.\\pipe\\chrome."; | 26 const char kChromePipeNamePrefix[] = "\\\\.\\pipe\\chrome."; |
27 | 27 |
28 bool CreateConnectedIpcChannel( | 28 bool CreateConnectedIpcChannel( |
29 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, | 29 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
30 IPC::Listener* listener, | 30 IPC::Listener* listener, |
31 base::File* client_out, | 31 base::File* client_out, |
32 scoped_ptr<IPC::ChannelProxy>* server_out) { | 32 std::unique_ptr<IPC::ChannelProxy>* server_out) { |
33 // presubmit: allow wstring | 33 // presubmit: allow wstring |
34 std::wstring user_sid; | 34 std::wstring user_sid; |
35 if (!base::win::GetUserSidString(&user_sid)) { | 35 if (!base::win::GetUserSidString(&user_sid)) { |
36 LOG(ERROR) << "Failed to query the current user SID."; | 36 LOG(ERROR) << "Failed to query the current user SID."; |
37 return false; | 37 return false; |
38 } | 38 } |
39 | 39 |
40 // Create a security descriptor that will be used to protect the named pipe in | 40 // Create a security descriptor that will be used to protect the named pipe in |
41 // between CreateNamedPipe() and CreateFile() calls before it will be passed | 41 // between CreateNamedPipe() and CreateFile() calls before it will be passed |
42 // to the network process. It gives full access to the account that | 42 // to the network process. It gives full access to the account that |
43 // the calling code is running under and denies access by anyone else. | 43 // the calling code is running under and denies access by anyone else. |
44 std::string user_sid_utf8 = base::WideToUTF8(user_sid); | 44 std::string user_sid_utf8 = base::WideToUTF8(user_sid); |
45 std::string security_descriptor = | 45 std::string security_descriptor = |
46 base::StringPrintf("O:%sG:%sD:(A;;GA;;;%s)", user_sid_utf8.c_str(), | 46 base::StringPrintf("O:%sG:%sD:(A;;GA;;;%s)", user_sid_utf8.c_str(), |
47 user_sid_utf8.c_str(), user_sid_utf8.c_str()); | 47 user_sid_utf8.c_str(), user_sid_utf8.c_str()); |
48 | 48 |
49 // Generate a unique name for the channel. | 49 // Generate a unique name for the channel. |
50 std::string channel_name = IPC::Channel::GenerateUniqueRandomChannelID(); | 50 std::string channel_name = IPC::Channel::GenerateUniqueRandomChannelID(); |
51 | 51 |
52 // Create the server end of the channel. | 52 // Create the server end of the channel. |
53 ScopedHandle pipe; | 53 ScopedHandle pipe; |
54 if (!CreateIpcChannel(channel_name, security_descriptor, &pipe)) { | 54 if (!CreateIpcChannel(channel_name, security_descriptor, &pipe)) { |
55 return false; | 55 return false; |
56 } | 56 } |
57 | 57 |
58 // Wrap the pipe into an IPC channel. | 58 // Wrap the pipe into an IPC channel. |
59 scoped_ptr<IPC::ChannelProxy> server = | 59 std::unique_ptr<IPC::ChannelProxy> server = IPC::ChannelProxy::Create( |
60 IPC::ChannelProxy::Create(IPC::ChannelHandle(pipe.Get()), | 60 IPC::ChannelHandle(pipe.Get()), IPC::Channel::MODE_SERVER, listener, |
61 IPC::Channel::MODE_SERVER, | 61 io_task_runner); |
62 listener, | |
63 io_task_runner); | |
64 | 62 |
65 // Convert the channel name to the pipe name. | 63 // Convert the channel name to the pipe name. |
66 std::string pipe_name(kChromePipeNamePrefix); | 64 std::string pipe_name(kChromePipeNamePrefix); |
67 pipe_name.append(channel_name); | 65 pipe_name.append(channel_name); |
68 | 66 |
69 SECURITY_ATTRIBUTES security_attributes = {0}; | 67 SECURITY_ATTRIBUTES security_attributes = {0}; |
70 security_attributes.nLength = sizeof(security_attributes); | 68 security_attributes.nLength = sizeof(security_attributes); |
71 security_attributes.lpSecurityDescriptor = nullptr; | 69 security_attributes.lpSecurityDescriptor = nullptr; |
72 security_attributes.bInheritHandle = TRUE; | 70 security_attributes.bInheritHandle = TRUE; |
73 | 71 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 PLOG(ERROR) | 126 PLOG(ERROR) |
129 << "Failed to create the server end of the Chromoting IPC channel"; | 127 << "Failed to create the server end of the Chromoting IPC channel"; |
130 return false; | 128 return false; |
131 } | 129 } |
132 | 130 |
133 *pipe_out = std::move(pipe); | 131 *pipe_out = std::move(pipe); |
134 return true; | 132 return true; |
135 } | 133 } |
136 | 134 |
137 } // namespace remoting | 135 } // namespace remoting |
OLD | NEW |