MCPcopy Create free account
hub / github.com/USBGuard/usbguard / processDeviceInsertion

Method processDeviceInsertion

src/Library/DeviceManagerBase.cpp:282–340  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

280 }
281
282 void DeviceManagerBase::processDeviceInsertion(SysFSDevice& sysfs_device, const bool signal_present)
283 {
284 USBGUARD_LOG(Trace) << "sysfs_device=" << sysfs_device.getPath();
285
286 try {
287 std::shared_ptr<DeviceBase> device = std::make_shared<DeviceBase>(*this, sysfs_device);
288 DeviceManager::AuthorizedDefaultType auth_default = getAuthorizedDefault();
289
290 if (device->isController() && !_enumeration_only_mode) {
291 USBGUARD_LOG(Debug) << "Setting default blocked state for controller device to " <<
292 DeviceManager::authorizedDefaultTypeToString(auth_default);
293 setDeviceAuthorizedDefault(&device->sysfsDevice(), auth_default);
294 }
295
296 insertDevice(device);
297
298 /*
299 * Signal insertions as presence if device enumeration hasn't
300 * completed yet.
301 */
302 if (signal_present) {
303 DeviceEvent(DeviceManager::EventType::Present, device);
304 }
305 else {
306 DeviceEvent(DeviceManager::EventType::Insert, device);
307 }
308
309 return;
310 }
311 catch (const Exception& ex) {
312 USBGUARD_LOG(Error) << "Device insert exception: " << ex.message();
313 DeviceException(ex.message());
314 }
315 catch (const std::exception& ex) {
316 USBGUARD_LOG(Error) << "Device insert exception: " << ex.what();
317 DeviceException(ex.what());
318 }
319 catch (...) {
320 USBGUARD_LOG(Error) << "BUG: Unknown device insert exception.";
321 DeviceException("BUG: Unknown device insert exception.");
322 }
323
324 /*
325 * Skip device reject when in enumeration only mode.
326 */
327 if (_enumeration_only_mode) {
328 return;
329 }
330
331 /*
332 * Something went wrong and an exception was generated.
333 * Either the device is malicious or the system lacks some
334 * resources to successfully process the device. In either
335 * case, we take the safe route and fallback to rejecting
336 * the device.
337 */
338 USBGUARD_LOG(Warning) << "Rejecting device at syspath=" << sysfs_device.getPath();
339 sysfsApplyTarget(sysfs_device, Rule::Target::Reject);

Callers

nothing calls this directly

Calls 2

isControllerMethod · 0.80
whatMethod · 0.80

Tested by

no test coverage detected