| 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 <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <sys/socket.h> | 8 #include <sys/socket.h> |
| 9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
| 10 #include <sys/syscall.h> | 10 #include <sys/syscall.h> |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 | 147 |
| 148 if (sent <= 0) { | 148 if (sent <= 0) { |
| 149 LOG(ERROR) << "Could not send IPC reply"; | 149 LOG(ERROR) << "Could not send IPC reply"; |
| 150 return false; | 150 return false; |
| 151 } | 151 } |
| 152 return true; | 152 return true; |
| 153 } | 153 } |
| 154 | 154 |
| 155 } // namespace | 155 } // namespace |
| 156 | 156 |
| 157 BrokerHost::BrokerHost(const BrokerPolicy& broker_policy, int ipc_channel) | 157 BrokerHost::BrokerHost(const BrokerPolicy& broker_policy, |
| 158 : broker_policy_(broker_policy), ipc_channel_(ipc_channel) { | 158 BrokerChannel::EndPoint ipc_channel) |
| 159 : broker_policy_(broker_policy), ipc_channel_(ipc_channel.Pass()) { |
| 159 } | 160 } |
| 160 | 161 |
| 161 BrokerHost::~BrokerHost() { | 162 BrokerHost::~BrokerHost() { |
| 162 } | 163 } |
| 163 | 164 |
| 164 // Handle a request on the IPC channel ipc_channel_. | 165 // Handle a request on the IPC channel ipc_channel_. |
| 165 // A request should have a file descriptor attached on which we will reply and | 166 // A request should have a file descriptor attached on which we will reply and |
| 166 // that we will then close. | 167 // that we will then close. |
| 167 // A request should start with an int that will be used as the command type. | 168 // A request should start with an int that will be used as the command type. |
| 168 BrokerHost::RequestStatus BrokerHost::HandleRequest() const { | 169 BrokerHost::RequestStatus BrokerHost::HandleRequest() const { |
| 169 ScopedVector<base::ScopedFD> fds; | 170 ScopedVector<base::ScopedFD> fds; |
| 170 char buf[kMaxMessageLength]; | 171 char buf[kMaxMessageLength]; |
| 171 errno = 0; | 172 errno = 0; |
| 172 const ssize_t msg_len = | 173 const ssize_t msg_len = |
| 173 UnixDomainSocket::RecvMsg(ipc_channel_, buf, sizeof(buf), &fds); | 174 UnixDomainSocket::RecvMsg(ipc_channel_.get(), buf, sizeof(buf), &fds); |
| 174 | 175 |
| 175 if (msg_len == 0 || (msg_len == -1 && errno == ECONNRESET)) { | 176 if (msg_len == 0 || (msg_len == -1 && errno == ECONNRESET)) { |
| 176 // EOF from the client, or the client died, we should die. | 177 // EOF from the client, or the client died, we should die. |
| 177 return RequestStatus::LOST_CLIENT; | 178 return RequestStatus::LOST_CLIENT; |
| 178 } | 179 } |
| 179 | 180 |
| 180 // The client should send exactly one file descriptor, on which we | 181 // The client should send exactly one file descriptor, on which we |
| 181 // will write the reply. | 182 // will write the reply. |
| 182 // TODO(mdempsky): ScopedVector doesn't have 'at()', only 'operator[]'. | 183 // TODO(mdempsky): ScopedVector doesn't have 'at()', only 'operator[]'. |
| 183 if (msg_len < 0 || fds.size() != 1 || fds[0]->get() < 0) { | 184 if (msg_len < 0 || fds.size() != 1 || fds[0]->get() < 0) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 NOTREACHED(); | 216 NOTREACHED(); |
| 216 } | 217 } |
| 217 | 218 |
| 218 LOG(ERROR) << "Error parsing IPC request"; | 219 LOG(ERROR) << "Error parsing IPC request"; |
| 219 return RequestStatus::FAILURE; | 220 return RequestStatus::FAILURE; |
| 220 } | 221 } |
| 221 | 222 |
| 222 } // namespace syscall_broker | 223 } // namespace syscall_broker |
| 223 | 224 |
| 224 } // namespace sandbox | 225 } // namespace sandbox |
| OLD | NEW |