Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: remoting/host/ipc_util_win.cc

Issue 2451953002: Use ChannelMojo between the remoting network and desktop processes. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/host/ipc_util_posix.cc ('k') | remoting/host/remoting_me2me_host.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
10 #include "base/logging.h" 9 #include "base/logging.h"
11 #include "base/single_thread_task_runner.h"
12 #include "base/strings/stringprintf.h"
13 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
14 #include "base/win/scoped_handle.h" 11 #include "base/win/scoped_handle.h"
15 #include "base/win/win_util.h" 12 #include "base/win/win_util.h"
16 #include "ipc/attachment_broker.h"
17 #include "ipc/ipc_channel.h" 13 #include "ipc/ipc_channel.h"
18 #include "ipc/ipc_channel_proxy.h"
19 #include "remoting/host/win/security_descriptor.h" 14 #include "remoting/host/win/security_descriptor.h"
20 15
21 using base::win::ScopedHandle;
22
23 namespace remoting { 16 namespace remoting {
24 17
25 // Pipe name prefix used by Chrome IPC channels to convert a channel name into 18 // Pipe name prefix used by Chrome IPC channels to convert a channel name into
26 // a pipe name. 19 // a pipe name.
27 const char kChromePipeNamePrefix[] = "\\\\.\\pipe\\chrome."; 20 const char kChromePipeNamePrefix[] = "\\\\.\\pipe\\chrome.";
28 21
29 bool CreateConnectedIpcChannel(
30 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
31 IPC::Listener* listener,
32 base::File* client_out,
33 std::unique_ptr<IPC::ChannelProxy>* server_out) {
34 // presubmit: allow wstring
35 std::wstring user_sid;
36 if (!base::win::GetUserSidString(&user_sid)) {
37 LOG(ERROR) << "Failed to query the current user SID.";
38 return false;
39 }
40
41 // Create a security descriptor that will be used to protect the named pipe in
42 // between CreateNamedPipe() and CreateFile() calls before it will be passed
43 // to the network process. It gives full access to the account that
44 // the calling code is running under and denies access by anyone else.
45 std::string user_sid_utf8 = base::WideToUTF8(user_sid);
46 std::string security_descriptor =
47 base::StringPrintf("O:%sG:%sD:(A;;GA;;;%s)", user_sid_utf8.c_str(),
48 user_sid_utf8.c_str(), user_sid_utf8.c_str());
49
50 // Generate a unique name for the channel.
51 std::string channel_name = IPC::Channel::GenerateUniqueRandomChannelID();
52
53 // Create the server end of the channel.
54 ScopedHandle pipe;
55 if (!CreateIpcChannel(channel_name, security_descriptor, &pipe)) {
56 return false;
57 }
58
59 // Wrap the pipe into an IPC channel.
60 std::unique_ptr<IPC::ChannelProxy> server(
61 new IPC::ChannelProxy(listener, io_task_runner));
62 IPC::AttachmentBroker* broker = IPC::AttachmentBroker::GetGlobal();
63 DCHECK(broker) << "No AttachmentBroker registered.";
64 if (broker->IsPrivilegedBroker()) {
65 broker->RegisterCommunicationChannel(server.get(), io_task_runner);
66 }
67 server->Init(IPC::ChannelHandle(pipe.Get()), IPC::Channel::MODE_SERVER,
68 /*create_pipe_now=*/true);
69
70 // Convert the channel name to the pipe name.
71 std::string pipe_name(kChromePipeNamePrefix);
72 pipe_name.append(channel_name);
73
74 SECURITY_ATTRIBUTES security_attributes = {0};
75 security_attributes.nLength = sizeof(security_attributes);
76 security_attributes.lpSecurityDescriptor = nullptr;
77 security_attributes.bInheritHandle = TRUE;
78
79 // Create the client end of the channel. This code should match the code in
80 // IPC::Channel.
81 base::File client(CreateFile(base::UTF8ToUTF16(pipe_name).c_str(),
82 GENERIC_READ | GENERIC_WRITE,
83 0,
84 &security_attributes,
85 OPEN_EXISTING,
86 SECURITY_SQOS_PRESENT | SECURITY_IDENTIFICATION |
87 FILE_FLAG_OVERLAPPED,
88 nullptr));
89 if (!client.IsValid()) {
90 PLOG(ERROR) << "Failed to connect to '" << pipe_name << "'";
91 return false;
92 }
93
94 *client_out = std::move(client);
95 *server_out = std::move(server);
96 return true;
97 }
98
99 bool CreateIpcChannel( 22 bool CreateIpcChannel(
100 const std::string& channel_name, 23 const std::string& channel_name,
101 const std::string& pipe_security_descriptor, 24 const std::string& pipe_security_descriptor,
102 base::win::ScopedHandle* pipe_out) { 25 base::win::ScopedHandle* pipe_out) {
103 // Create security descriptor for the channel. 26 // Create security descriptor for the channel.
104 ScopedSd sd = ConvertSddlToSd(pipe_security_descriptor); 27 ScopedSd sd = ConvertSddlToSd(pipe_security_descriptor);
105 if (!sd) { 28 if (!sd) {
106 PLOG(ERROR) << "Failed to create a security descriptor for the Chromoting " 29 PLOG(ERROR) << "Failed to create a security descriptor for the Chromoting "
107 "IPC channel"; 30 "IPC channel";
108 return false; 31 return false;
(...skipping 24 matching lines...) Expand all
133 PLOG(ERROR) 56 PLOG(ERROR)
134 << "Failed to create the server end of the Chromoting IPC channel"; 57 << "Failed to create the server end of the Chromoting IPC channel";
135 return false; 58 return false;
136 } 59 }
137 60
138 *pipe_out = std::move(pipe); 61 *pipe_out = std::move(pipe);
139 return true; 62 return true;
140 } 63 }
141 64
142 } // namespace remoting 65 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/ipc_util_posix.cc ('k') | remoting/host/remoting_me2me_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698