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/logging.h" | 7 #include "base/logging.h" |
8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 if (!base::win::GetUserSidString(&user_sid)) { | 32 if (!base::win::GetUserSidString(&user_sid)) { |
33 LOG(ERROR) << "Failed to query the current user SID."; | 33 LOG(ERROR) << "Failed to query the current user SID."; |
34 return false; | 34 return false; |
35 } | 35 } |
36 | 36 |
37 // Create a security descriptor that will be used to protect the named pipe in | 37 // 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 | 38 // between CreateNamedPipe() and CreateFile() calls before it will be passed |
39 // to the network process. It gives full access to the account that | 39 // to the network process. It gives full access to the account that |
40 // the calling code is running under and denies access by anyone else. | 40 // the calling code is running under and denies access by anyone else. |
41 std::string security_descriptor = base::StringPrintf( | 41 std::string security_descriptor = base::StringPrintf( |
42 "O:%1$sG:%1$sD:(A;;GA;;;%1$s)", WideToUTF8(user_sid).c_str()); | 42 "O:%1$sG:%1$sD:(A;;GA;;;%1$s)", base::WideToUTF8(user_sid).c_str()); |
43 | 43 |
44 // Generate a unique name for the channel. | 44 // Generate a unique name for the channel. |
45 std::string channel_name = IPC::Channel::GenerateUniqueRandomChannelID(); | 45 std::string channel_name = IPC::Channel::GenerateUniqueRandomChannelID(); |
46 | 46 |
47 // Create the server end of the channel. | 47 // Create the server end of the channel. |
48 ScopedHandle pipe; | 48 ScopedHandle pipe; |
49 if (!CreateIpcChannel(channel_name, security_descriptor, &pipe)) { | 49 if (!CreateIpcChannel(channel_name, security_descriptor, &pipe)) { |
50 return false; | 50 return false; |
51 } | 51 } |
52 | 52 |
53 // Wrap the pipe into an IPC channel. | 53 // Wrap the pipe into an IPC channel. |
54 scoped_ptr<IPC::ChannelProxy> server(new IPC::ChannelProxy( | 54 scoped_ptr<IPC::ChannelProxy> server(new IPC::ChannelProxy( |
55 IPC::ChannelHandle(pipe), | 55 IPC::ChannelHandle(pipe), |
56 IPC::Channel::MODE_SERVER, | 56 IPC::Channel::MODE_SERVER, |
57 listener, | 57 listener, |
58 io_task_runner)); | 58 io_task_runner)); |
59 | 59 |
60 // Convert the channel name to the pipe name. | 60 // Convert the channel name to the pipe name. |
61 std::string pipe_name(kChromePipeNamePrefix); | 61 std::string pipe_name(kChromePipeNamePrefix); |
62 pipe_name.append(channel_name); | 62 pipe_name.append(channel_name); |
63 | 63 |
64 SECURITY_ATTRIBUTES security_attributes = {0}; | 64 SECURITY_ATTRIBUTES security_attributes = {0}; |
65 security_attributes.nLength = sizeof(security_attributes); | 65 security_attributes.nLength = sizeof(security_attributes); |
66 security_attributes.lpSecurityDescriptor = NULL; | 66 security_attributes.lpSecurityDescriptor = NULL; |
67 security_attributes.bInheritHandle = TRUE; | 67 security_attributes.bInheritHandle = TRUE; |
68 | 68 |
69 // Create the client end of the channel. This code should match the code in | 69 // Create the client end of the channel. This code should match the code in |
70 // IPC::Channel. | 70 // IPC::Channel. |
71 ScopedHandle client; | 71 ScopedHandle client; |
72 client.Set(CreateFile(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 LOG_GETLASTERROR(ERROR) << "Failed to connect to '" << pipe_name << "'"; | 81 LOG_GETLASTERROR(ERROR) << "Failed to connect to '" << pipe_name << "'"; |
82 return false; | 82 return false; |
(...skipping 22 matching lines...) Expand all Loading... |
105 security_attributes.bInheritHandle = FALSE; | 105 security_attributes.bInheritHandle = FALSE; |
106 | 106 |
107 // Convert the channel name to the pipe name. | 107 // Convert the channel name to the pipe name. |
108 std::string pipe_name(kChromePipeNamePrefix); | 108 std::string pipe_name(kChromePipeNamePrefix); |
109 pipe_name.append(channel_name); | 109 pipe_name.append(channel_name); |
110 | 110 |
111 // Create the server end of the pipe. This code should match the code in | 111 // Create the server end of the pipe. This code should match the code in |
112 // IPC::Channel with exception of passing a non-default security descriptor. | 112 // IPC::Channel with exception of passing a non-default security descriptor. |
113 base::win::ScopedHandle pipe; | 113 base::win::ScopedHandle pipe; |
114 pipe.Set(CreateNamedPipe( | 114 pipe.Set(CreateNamedPipe( |
115 UTF8ToUTF16(pipe_name).c_str(), | 115 base::UTF8ToUTF16(pipe_name).c_str(), |
116 PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED | FILE_FLAG_FIRST_PIPE_INSTANCE, | 116 PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED | FILE_FLAG_FIRST_PIPE_INSTANCE, |
117 PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, | 117 PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, |
118 1, | 118 1, |
119 IPC::Channel::kReadBufferSize, | 119 IPC::Channel::kReadBufferSize, |
120 IPC::Channel::kReadBufferSize, | 120 IPC::Channel::kReadBufferSize, |
121 5000, | 121 5000, |
122 &security_attributes)); | 122 &security_attributes)); |
123 if (!pipe.IsValid()) { | 123 if (!pipe.IsValid()) { |
124 LOG_GETLASTERROR(ERROR) << | 124 LOG_GETLASTERROR(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 |