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

Method umockdevLoadFromFile

src/Library/UMockdevDeviceManager.cpp:282–324  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

280 }
281
282 std::vector<std::string> UMockdevDeviceManager::umockdevLoadFromFile(const std::string& definitions_path)
283 {
284 USBGUARD_LOG(Debug) << "Loading device definitions from " << definitions_path;
285 std::vector<std::unique_ptr<UMockdevDeviceDefinition>> definitions;
286 std::vector<std::string> device_paths;
287
288 try {
289 definitions = UMockdevDeviceDefinition::parseFromFile(definitions_path, /*sort_by_hierarchy=*/true);
290 }
291 catch (...) {
292 USBGUARD_LOG(Warning) << "UMockdevDeviceManager: failed to parse " << definitions_path;
293 throw;
294 }
295
296 for (auto&& definition : definitions) {
297 if (_sysfs_path_map.count(definition->getSysfsPath()) > 0) {
298 USBGUARD_LOG(Warning) << "UMockdevDeviceManager: " << definition->getSysfsPath() << ": device already defined, skipping.";
299 continue;
300 }
301
302 std::shared_ptr<UMockdevDeviceDefinition> sharedptr_definition(std::move(definition));
303 std::weak_ptr<UMockdevDeviceDefinition> weakptr_definition(sharedptr_definition);
304
305 if (sharedptr_definition->getDeviceType() == "usb_device") {
306 if (_sysfs_path_map.count(parentPath(sharedptr_definition->getSysfsPath())) < 1) {
307 USBGUARD_LOG(Warning) << "UMockdevDeviceManager: " << sharedptr_definition->getSysfsPath() <<
308 ": parent device not defined, skipping.";
309 continue;
310 }
311
312 USBGUARD_LOG(Debug) << "Adding new USB device definition: " << sharedptr_definition->getSysfsPath();
313 }
314 else {
315 USBGUARD_LOG(Debug) << "Adding new non-USB device definition: " << sharedptr_definition->getSysfsPath();
316 }
317
318 _sysfs_path_map.emplace(sharedptr_definition->getSysfsPath(), sharedptr_definition);
319 _umockdev_file_map.emplace(sharedptr_definition->getUMockdevName(), weakptr_definition);
320 device_paths.push_back(sharedptr_definition->getSysfsPath());
321 }
322
323 return device_paths;
324 }
325
326 std::vector<std::string> UMockdevDeviceManager::umockdevRemoveByFile(const std::string& definitions_path)
327 {

Callers

nothing calls this directly

Calls 2

parentPathFunction · 0.85
countMethod · 0.80

Tested by

no test coverage detected