| 410 | } |
| 411 | |
| 412 | int UEventDeviceManager::ueventEnumerateTriggerDevice(const std::string& devpath, const std::string& buspath) |
| 413 | { |
| 414 | USBGUARD_LOG(Trace) << "devpath=" << devpath << " buspath=" << buspath; |
| 415 | |
| 416 | try { |
| 417 | std::string sysfs_absolute_path(PATH_MAX, 0); |
| 418 | |
| 419 | if (::realpath(devpath.c_str(), &sysfs_absolute_path[0]) == nullptr) { |
| 420 | USBGUARD_LOG(Warning) << "Cannot resolve realpath for " << devpath; |
| 421 | return 0; |
| 422 | } |
| 423 | |
| 424 | sysfs_absolute_path.resize(::strlen(&sysfs_absolute_path[0])); |
| 425 | |
| 426 | if (!hasPrefix(sysfs_absolute_path, SysFSDevice::getSysfsRoot())) { |
| 427 | USBGUARD_LOG(Warning) << "Device isn't rooted inside " << SysFSDevice::getSysfsRoot() << ". Skipping."; |
| 428 | return 0; |
| 429 | } |
| 430 | |
| 431 | const std::string sysfs_relative_path = removePrefix(SysFSDevice::getSysfsRoot(), sysfs_absolute_path); |
| 432 | USBGUARD_LOG(Debug) << "sysfs_relative_path=" << sysfs_relative_path; |
| 433 | SysFSDevice device(sysfs_relative_path); |
| 434 | |
| 435 | if (device.getUEvent().getAttribute("DEVTYPE") == "usb_device") { |
| 436 | learnSysfsPath(sysfs_relative_path); |
| 437 | ueventProcessAction("add", sysfs_relative_path); |
| 438 | return 1; |
| 439 | } |
| 440 | else { |
| 441 | USBGUARD_LOG(Debug) << "DEVTYPE != usb_device. Skipping."; |
| 442 | } |
| 443 | } |
| 444 | catch (const Exception& ex) { |
| 445 | USBGUARD_LOG(Warning) << "device enumeration exception: " << buspath << ": " << ex.message(); |
| 446 | } |
| 447 | catch (const std::exception& ex) { |
| 448 | USBGUARD_LOG(Warning) << "device enumeration exception: " << buspath << ": " << ex.what(); |
| 449 | } |
| 450 | |
| 451 | return 0; |
| 452 | } |
| 453 | |
| 454 | void UEventDeviceManager::processBacklog() |
| 455 | { |
nothing calls this directly
no test coverage detected