OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "sandbox/linux/syscall_broker/broker_host.h" | 5 #include "sandbox/linux/syscall_broker/broker_host.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <sys/socket.h> | 9 #include <sys/socket.h> |
10 #include <sys/stat.h> | 10 #include <sys/stat.h> |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 : broker_policy_(broker_policy), ipc_channel_(std::move(ipc_channel)) {} | 167 : broker_policy_(broker_policy), ipc_channel_(std::move(ipc_channel)) {} |
168 | 168 |
169 BrokerHost::~BrokerHost() { | 169 BrokerHost::~BrokerHost() { |
170 } | 170 } |
171 | 171 |
172 // Handle a request on the IPC channel ipc_channel_. | 172 // Handle a request on the IPC channel ipc_channel_. |
173 // A request should have a file descriptor attached on which we will reply and | 173 // A request should have a file descriptor attached on which we will reply and |
174 // that we will then close. | 174 // that we will then close. |
175 // A request should start with an int that will be used as the command type. | 175 // A request should start with an int that will be used as the command type. |
176 BrokerHost::RequestStatus BrokerHost::HandleRequest() const { | 176 BrokerHost::RequestStatus BrokerHost::HandleRequest() const { |
177 ScopedVector<base::ScopedFD> fds; | 177 std::vector<base::ScopedFD> fds; |
178 char buf[kMaxMessageLength]; | 178 char buf[kMaxMessageLength]; |
179 errno = 0; | 179 errno = 0; |
180 const ssize_t msg_len = base::UnixDomainSocket::RecvMsg( | 180 const ssize_t msg_len = base::UnixDomainSocket::RecvMsg( |
181 ipc_channel_.get(), buf, sizeof(buf), &fds); | 181 ipc_channel_.get(), buf, sizeof(buf), &fds); |
182 | 182 |
183 if (msg_len == 0 || (msg_len == -1 && errno == ECONNRESET)) { | 183 if (msg_len == 0 || (msg_len == -1 && errno == ECONNRESET)) { |
184 // EOF from the client, or the client died, we should die. | 184 // EOF from the client, or the client died, we should die. |
185 return RequestStatus::LOST_CLIENT; | 185 return RequestStatus::LOST_CLIENT; |
186 } | 186 } |
187 | 187 |
188 // The client should send exactly one file descriptor, on which we | 188 // The client should send exactly one file descriptor, on which we |
189 // will write the reply. | 189 // will write the reply. |
190 // TODO(mdempsky): ScopedVector doesn't have 'at()', only 'operator[]'. | 190 if (msg_len < 0 || fds.size() != 1 || fds.at(0).get() < 0) { |
danakj
2015/12/08 23:44:48
ditto about these at()s
mdempsky
2015/12/09 00:45:37
Reverted.
| |
191 if (msg_len < 0 || fds.size() != 1 || fds[0]->get() < 0) { | |
192 PLOG(ERROR) << "Error reading message from the client"; | 191 PLOG(ERROR) << "Error reading message from the client"; |
193 return RequestStatus::FAILURE; | 192 return RequestStatus::FAILURE; |
194 } | 193 } |
195 | 194 |
196 base::ScopedFD temporary_ipc(std::move(*fds[0])); | 195 base::ScopedFD temporary_ipc(std::move(fds.at(0))); |
197 | 196 |
198 base::Pickle pickle(buf, msg_len); | 197 base::Pickle pickle(buf, msg_len); |
199 base::PickleIterator iter(pickle); | 198 base::PickleIterator iter(pickle); |
200 int command_type; | 199 int command_type; |
201 if (iter.ReadInt(&command_type)) { | 200 if (iter.ReadInt(&command_type)) { |
202 bool command_handled = false; | 201 bool command_handled = false; |
203 // Go through all the possible IPC messages. | 202 // Go through all the possible IPC messages. |
204 switch (command_type) { | 203 switch (command_type) { |
205 case COMMAND_ACCESS: | 204 case COMMAND_ACCESS: |
206 case COMMAND_OPEN: | 205 case COMMAND_OPEN: |
(...skipping 16 matching lines...) Expand all Loading... | |
223 NOTREACHED(); | 222 NOTREACHED(); |
224 } | 223 } |
225 | 224 |
226 LOG(ERROR) << "Error parsing IPC request"; | 225 LOG(ERROR) << "Error parsing IPC request"; |
227 return RequestStatus::FAILURE; | 226 return RequestStatus::FAILURE; |
228 } | 227 } |
229 | 228 |
230 } // namespace syscall_broker | 229 } // namespace syscall_broker |
231 | 230 |
232 } // namespace sandbox | 231 } // namespace sandbox |
OLD | NEW |