Skip to content

Commit b2ead8a

Browse files
feat(xattr): attribute_display for linux compatibility
This will add custom formatting to "security.capability" attribute. Adds capctl as a dependency only for linux.
1 parent 12a0cb0 commit b2ead8a

3 files changed

Lines changed: 41 additions & 5 deletions

File tree

Cargo.lock

Lines changed: 22 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ default-features = false
118118

119119
[target.'cfg(target_os = "linux")'.dependencies]
120120
proc-mounts = "0.3"
121+
capctl = "0.2.4"
121122

122123
[target.'cfg(unix)'.dependencies]
123124
uzers = "0.12.1"

src/fs/feature/xattr.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,13 @@ const ATTRIBUTE_DISPLAYS: &[AttributeDisplay] = &[
588588
},
589589
];
590590

591-
#[cfg(not(target_os = "macos"))]
591+
#[cfg(target_os = "linux")]
592+
const ATTRIBUTE_DISPLAYS: &[AttributeDisplay] = &[AttributeDisplay {
593+
attribute: "security.capability",
594+
display: display_capability,
595+
}];
596+
597+
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
592598
const ATTRIBUTE_DISPLAYS: &[AttributeDisplay] = &[];
593599

594600
// com.apple.lastuseddate is two 64-bit values representing the seconds and nano seconds
@@ -665,6 +671,17 @@ fn display_macl(attribute: &Attribute) -> Option<String> {
665671
})
666672
}
667673

674+
// "security.capability" attribute represents capabilities in a binary format.
675+
// See "capabilities(7)"
676+
#[cfg(target_os = "linux")]
677+
fn display_capability(attribute: &Attribute) -> Option<String> {
678+
attribute
679+
.value
680+
.as_ref()
681+
.and_then(|v| capctl::FileCaps::unpack_attrs(v).ok())
682+
.map(|caps| format!("{caps}"))
683+
}
684+
668685
// plist::XmlWriter takes the writer instead of borrowing it. This is a
669686
// wrapper around a borrowed vector that just forwards the Write trait
670687
// calls to the borrowed vector.

0 commit comments

Comments
 (0)