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

Side by Side Diff: device/usb/mojo/device_impl.cc

Issue 1847183002: Use interface associations to check function permissions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed nit and fixed Windows build. Created 4 years, 8 months 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 | « device/usb/mock_usb_device_handle.h ('k') | device/usb/mojo/device_impl_unittest.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "device/usb/mojo/device_impl.h" 5 #include "device/usb/mojo/device_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <numeric> 10 #include <numeric>
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 const UsbConfigDescriptor* config = device_->GetActiveConfiguration(); 158 const UsbConfigDescriptor* config = device_->GetActiveConfiguration();
159 159
160 if (!permission_provider_) 160 if (!permission_provider_)
161 return false; 161 return false;
162 162
163 if (recipient == ControlTransferRecipient::INTERFACE || 163 if (recipient == ControlTransferRecipient::INTERFACE ||
164 recipient == ControlTransferRecipient::ENDPOINT) { 164 recipient == ControlTransferRecipient::ENDPOINT) {
165 if (!config) 165 if (!config)
166 return false; 166 return false;
167 167
168 uint8_t interface_number = index & 0xff; 168 const UsbInterfaceDescriptor* interface = nullptr;
169 if (recipient == ControlTransferRecipient::ENDPOINT && 169 if (recipient == ControlTransferRecipient::ENDPOINT) {
170 !device_handle_->FindInterfaceByEndpoint(index & 0xff, 170 interface = device_handle_->FindInterfaceByEndpoint(index & 0xff);
171 &interface_number)) { 171 } else {
172 auto interface_it =
173 std::find_if(config->interfaces.begin(), config->interfaces.end(),
174 [index](const UsbInterfaceDescriptor& this_iface) {
175 return this_iface.interface_number == (index & 0xff);
176 });
177 if (interface_it != config->interfaces.end())
178 interface = &*interface_it;
179 }
180 if (interface == nullptr)
172 return false; 181 return false;
173 }
174 182
175 return permission_provider_->HasInterfacePermission( 183 return permission_provider_->HasFunctionPermission(
176 interface_number, config->configuration_value, *device_info_); 184 interface->first_interface, config->configuration_value, *device_info_);
177 } else if (config) { 185 } else if (config) {
178 return permission_provider_->HasConfigurationPermission( 186 return permission_provider_->HasConfigurationPermission(
179 config->configuration_value, *device_info_); 187 config->configuration_value, *device_info_);
180 } else { 188 } else {
181 // Client must already have device permission to have gotten this far. 189 // Client must already have device permission to have gotten this far.
182 return true; 190 return true;
183 } 191 }
184 } 192 }
185 193
186 void DeviceImpl::OnOpen(const OpenCallback& callback, 194 void DeviceImpl::OnOpen(const OpenCallback& callback,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 callback.Run(false); 237 callback.Run(false);
230 return; 238 return;
231 } 239 }
232 240
233 const UsbConfigDescriptor* config = device_->GetActiveConfiguration(); 241 const UsbConfigDescriptor* config = device_->GetActiveConfiguration();
234 if (!config) { 242 if (!config) {
235 callback.Run(false); 243 callback.Run(false);
236 return; 244 return;
237 } 245 }
238 246
247 auto interface_it =
248 std::find_if(config->interfaces.begin(), config->interfaces.end(),
249 [interface_number](const UsbInterfaceDescriptor& interface) {
250 return interface.interface_number == interface_number;
251 });
252 if (interface_it == config->interfaces.end()) {
253 callback.Run(false);
254 return;
255 }
256
239 if (permission_provider_ && 257 if (permission_provider_ &&
240 permission_provider_->HasInterfacePermission( 258 permission_provider_->HasFunctionPermission(interface_it->first_interface,
241 interface_number, config->configuration_value, *device_info_)) { 259 config->configuration_value,
260 *device_info_)) {
242 device_handle_->ClaimInterface(interface_number, 261 device_handle_->ClaimInterface(interface_number,
243 WrapMojoCallback(callback)); 262 WrapMojoCallback(callback));
244 } else { 263 } else {
245 callback.Run(false); 264 callback.Run(false);
246 } 265 }
247 } 266 }
248 267
249 void DeviceImpl::ReleaseInterface(uint8_t interface_number, 268 void DeviceImpl::ReleaseInterface(uint8_t interface_number,
250 const ReleaseInterfaceCallback& callback) { 269 const ReleaseInterfaceCallback& callback) {
251 if (!device_handle_) { 270 if (!device_handle_) {
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 base::Bind(&OnIsochronousTransferOut, base::Passed(&callback_ptr))); 442 base::Bind(&OnIsochronousTransferOut, base::Passed(&callback_ptr)));
424 } 443 }
425 444
426 void DeviceImpl::OnDeviceRemoved(scoped_refptr<UsbDevice> device) { 445 void DeviceImpl::OnDeviceRemoved(scoped_refptr<UsbDevice> device) {
427 DCHECK_EQ(device_, device); 446 DCHECK_EQ(device_, device);
428 delete this; 447 delete this;
429 } 448 }
430 449
431 } // namespace usb 450 } // namespace usb
432 } // namespace device 451 } // namespace device
OLDNEW
« no previous file with comments | « device/usb/mock_usb_device_handle.h ('k') | device/usb/mojo/device_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698