OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "remoting/host/ipc_util.h" | |
6 | |
7 #include <utility> | |
8 | |
9 #include "base/logging.h" | |
10 #include "base/strings/utf_string_conversions.h" | |
11 #include "base/win/scoped_handle.h" | |
12 #include "base/win/win_util.h" | |
13 #include "ipc/ipc_channel.h" | |
14 #include "remoting/host/win/security_descriptor.h" | |
15 | |
16 namespace remoting { | |
17 | |
18 // Pipe name prefix used by Chrome IPC channels to convert a channel name into | |
19 // a pipe name. | |
20 const char kChromePipeNamePrefix[] = "\\\\.\\pipe\\chrome."; | |
21 | |
22 bool CreateIpcChannel( | |
23 const std::string& channel_name, | |
24 const std::string& pipe_security_descriptor, | |
25 base::win::ScopedHandle* pipe_out) { | |
26 // Create security descriptor for the channel. | |
27 ScopedSd sd = ConvertSddlToSd(pipe_security_descriptor); | |
28 if (!sd) { | |
29 PLOG(ERROR) << "Failed to create a security descriptor for the Chromoting " | |
30 "IPC channel"; | |
31 return false; | |
32 } | |
33 | |
34 SECURITY_ATTRIBUTES security_attributes = {0}; | |
35 security_attributes.nLength = sizeof(security_attributes); | |
36 security_attributes.lpSecurityDescriptor = sd.get(); | |
37 security_attributes.bInheritHandle = FALSE; | |
38 | |
39 // Convert the channel name to the pipe name. | |
40 std::string pipe_name(kChromePipeNamePrefix); | |
41 pipe_name.append(channel_name); | |
42 | |
43 // Create the server end of the pipe. This code should match the code in | |
44 // IPC::Channel with exception of passing a non-default security descriptor. | |
45 base::win::ScopedHandle pipe; | |
46 pipe.Set(CreateNamedPipe( | |
47 base::UTF8ToUTF16(pipe_name).c_str(), | |
48 PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED | FILE_FLAG_FIRST_PIPE_INSTANCE, | |
49 PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, | |
50 1, | |
51 IPC::Channel::kReadBufferSize, | |
52 IPC::Channel::kReadBufferSize, | |
53 5000, | |
54 &security_attributes)); | |
55 if (!pipe.IsValid()) { | |
56 PLOG(ERROR) | |
57 << "Failed to create the server end of the Chromoting IPC channel"; | |
58 return false; | |
59 } | |
60 | |
61 *pipe_out = std::move(pipe); | |
62 return true; | |
63 } | |
64 | |
65 } // namespace remoting | |
OLD | NEW |