Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #216: Correctly parse device-properties for Linux #217

Open
wants to merge 1 commit into
base: ctap2-2021
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ crypto_nss = ["nss-gk-api", "pkcs11-bindings"]
gecko = ["nss-gk-api/gecko"]

[target.'cfg(target_os = "linux")'.dependencies]
libudev = "^0.2"
libudev = "^0.3"

[target.'cfg(target_os = "freebsd")'.dependencies]
devd-rs = "0.3"
Expand Down
28 changes: 24 additions & 4 deletions src/transport/linux/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,35 @@ pub fn get_property_linux(path: &PathBuf, prop_name: &str) -> io::Result<String>
// Iterate all existing devices, since we don't have a syspath
// and libudev-rs doesn't implement opening by devnode.
for dev in enumerator.scan_devices()? {
if dev.devnode().is_some() && dev.devnode().unwrap() == path {
// Find the one that we currently work on (same `path`)
if dev.devnode().map_or(false, |p| p == path) {
// Check if the current device has the properties we want, and if not
// iterate over all it's parents in search of the first "usb_device"
// in the device-tree
let can_use_dev = dev.devtype().map_or(false, |p| p != "usb_device");
let d = if can_use_dev {
dev
} else {
let mut parent = dev.parent();
while let Some(ref next_parent) = parent {
if next_parent.devtype().map_or(false, |p| p == "usb_device") {
break;
}
let next = next_parent.parent();
parent = next;
}
parent.unwrap_or(dev)
};

debug!(
"get_property_linux Querying property {} from {}",
prop_name,
dev.syspath().display()
d.syspath()
.map_or(String::from("No syspath set"), |d| d.display().to_string())
);

let value = dev
.attribute_value(prop_name)
let value = d
.attribute_value(prop_name.to_lowercase())
.ok_or(io::ErrorKind::Other)?
.to_string_lossy();

Expand Down