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

Method ueventProcessUEvent

src/Library/UMockdevDeviceManager.cpp:628–721  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

626 }
627
628 void UMockdevDeviceManager::ueventProcessUEvent(const UEvent& uevent)
629 {
630 const std::string subsystem = uevent.getAttribute("SUBSYSTEM");
631 const std::string devtype = uevent.getAttribute("DEVTYPE");
632 const std::string action = uevent.getAttribute("ACTION");
633
634 /*
635 * We don't care about the event if it's not from the "usb" subsystem.
636 * The device type attribute value is checked later based on the data
637 * read from the sysfs uevent file in the device directory.
638 */
639 if (subsystem != "usb") {
640 USBGUARD_LOG(Debug) << "Ignoring non-USB device:"
641 << " subsystem=" << subsystem
642 << " devtype=" << devtype
643 << " action=" << action;
644 return;
645 }
646
647 const std::string sysfs_devpath = uevent.getAttribute("DEVPATH");
648 bool enumeration_notify = false;
649
650 try {
651 std::unique_lock<std::mutex> lock(_enumeration_mutex);
652 uint32_t id = 0;
653 const bool known_path = knownSysfsPath(sysfs_devpath, &id);
654
655 if (action == "add" || action == "change") {
656 lock.unlock();
657 USBGUARD_LOG(Debug) << "known_path=" << known_path << " id=" << id;
658
659 if (known_path && id > 0) {
660 processDevicePresence(id);
661 }
662 else {
663 SysFSDevice sysfs_device(sysfs_devpath);
664
665 /*
666 * Do some additional sanity checking.
667 */
668 if (sysfs_device.getUEvent().hasAttribute("DEVTYPE")) {
669 const std::string devtype = sysfs_device.getUEvent().getAttribute("DEVTYPE");
670
671 if (devtype != "usb_device") {
672 USBGUARD_LOG(Debug) << sysfs_devpath << ": UEvent DEVTYPE != usb_device. Ignoring event.";
673 return;
674 }
675 }
676 else {
677 if (!sysfs_device.hasAttribute("descriptors")) {
678 USBGUARD_LOG(Debug) << sysfs_devpath << ": UEvent doesn't refer to a device with a descriptors file. Ignoring event.";
679 return;
680 }
681 }
682
683 processDeviceInsertion(sysfs_device, /*signal_present=*/known_path);
684 USBGUARD_LOG(Debug) << "Enumeration notify: sysfs_devpath=" << sysfs_devpath
685 << " _enumeration=" << _enumeration

Callers

nothing calls this directly

Calls 2

getAttributeMethod · 0.80
hasAttributeMethod · 0.45

Tested by

no test coverage detected