| 340 | } |
| 341 | |
| 342 | void UEventDeviceManager::ueventProcessAction(const std::string& action, const std::string& sysfs_devpath) |
| 343 | { |
| 344 | try { |
| 345 | uint32_t id = 0; |
| 346 | const bool known_path = knownSysfsPath(sysfs_devpath, &id); |
| 347 | |
| 348 | if (action == "add" /*|| action == "change"*/) { |
| 349 | if (known_path && id > 0) { |
| 350 | processDevicePresence(id); |
| 351 | } |
| 352 | else { |
| 353 | SysFSDevice sysfs_device(sysfs_devpath); |
| 354 | |
| 355 | /* |
| 356 | * Do some additional sanity checking. |
| 357 | */ |
| 358 | if (sysfs_device.getUEvent().hasAttribute("DEVTYPE")) { |
| 359 | const std::string devtype = sysfs_device.getUEvent().getAttribute("DEVTYPE"); |
| 360 | |
| 361 | if (devtype != "usb_device") { |
| 362 | USBGUARD_LOG(Debug) << sysfs_devpath << ": UEvent DEVTYPE != usb_device. Ignoring event."; |
| 363 | return; |
| 364 | } |
| 365 | } |
| 366 | else { |
| 367 | if (!sysfs_device.hasAttribute("descriptors")) { |
| 368 | USBGUARD_LOG(Debug) << sysfs_devpath << ": UEvent doesn't refer to a device with a descriptors file. Ignoring event."; |
| 369 | return; |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | processDeviceInsertion(sysfs_device, /*signal_present=*/known_path); |
| 374 | USBGUARD_LOG(Debug) << "Enumeration notify: sysfs_devpath=" << sysfs_devpath |
| 375 | << " _enumeration=" << _enumeration |
| 376 | << " known_path=" << known_path; |
| 377 | } |
| 378 | } |
| 379 | else if (action == "remove") { |
| 380 | processDeviceRemoval(sysfs_devpath); |
| 381 | } |
| 382 | else if (action == "bind" || action == "unbind") { |
| 383 | USBGUARD_LOG(Debug) << action << "=" << sysfs_devpath; |
| 384 | } |
| 385 | else { |
| 386 | USBGUARD_LOG(Warning) << "Ignoring unknown UEvent action: sysfs_devpath=" << sysfs_devpath |
| 387 | << " action=" << action; |
| 388 | } |
| 389 | } |
| 390 | catch (const Exception& ex) { |
| 391 | USBGUARD_LOG(Warning) << "USB Device Exception: " |
| 392 | << ex.message(); |
| 393 | DeviceException(ex.message()); |
| 394 | } |
| 395 | catch (...) { |
| 396 | USBGUARD_LOG(Warning) << "USB Device Exception: unknown exception"; |
| 397 | DeviceException("unknown exception"); |
| 398 | } |
| 399 | } |
nothing calls this directly
no test coverage detected