Skip to content

Commit 16b1472

Browse files
authored
Merge pull request #829 from cgwalters/drop-gvariant
Drop gvariant
2 parents 49618d9 + abf7eae commit 16b1472

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ clap_mangen = { version = "0.2.20", optional = true }
2626
cap-std-ext = { workspace = true, features = ["fs_utf8"] }
2727
hex = "^0.4.3"
2828
fn-error-context = { workspace = true }
29-
gvariant = "0.5.0"
3029
indicatif = "0.17.8"
3130
libc = { workspace = true }
3231
liboverdrop = "0.1.0"

lib/src/lsm.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ use cap_std_ext::cap_std::fs::{Metadata, MetadataExt};
1919
#[cfg(feature = "install")]
2020
use cap_std_ext::dirext::CapStdExtDirExt;
2121
use fn_error_context::context;
22-
#[cfg(feature = "install")]
23-
use gvariant::{aligned_bytes::TryAsAligned, Marker, Structure};
2422
use ostree_ext::gio;
2523
use ostree_ext::ostree;
2624
use rustix::fd::AsFd;
@@ -177,12 +175,12 @@ pub(crate) fn selinux_set_permissive(permissive: bool) -> Result<()> {
177175
#[cfg(feature = "install")]
178176
/// Check if the ostree-formatted extended attributes include a security.selinux value.
179177
pub(crate) fn xattrs_have_selinux(xattrs: &ostree::glib::Variant) -> bool {
180-
let v = xattrs.data_as_bytes();
181-
let v = v.try_as_aligned().unwrap();
182-
let v = gvariant::gv!("a(ayay)").cast(v);
183-
for xattr in v.iter() {
184-
let k = xattr.to_tuple().0;
185-
if k == SELINUX_XATTR {
178+
let n = xattrs.n_children();
179+
for i in 0..n {
180+
let child = xattrs.child_value(i);
181+
let key = child.child_value(0);
182+
let key = key.data_as_bytes();
183+
if key == SELINUX_XATTR {
186184
return true;
187185
}
188186
}
@@ -419,3 +417,19 @@ where
419417
f(w)
420418
})
421419
}
420+
421+
#[cfg(test)]
422+
mod tests {
423+
use super::*;
424+
use gio::glib::Variant;
425+
426+
#[test]
427+
fn test_selinux_xattr() {
428+
let notfound: &[&[(&[u8], &[u8])]] = &[&[], &[(b"foo", b"bar")]];
429+
for case in notfound {
430+
assert!(!xattrs_have_selinux(&Variant::from(case)));
431+
}
432+
let found: &[(&[u8], &[u8])] = &[(b"foo", b"bar"), (SELINUX_XATTR, b"foo_t")];
433+
assert!(xattrs_have_selinux(&Variant::from(found)));
434+
}
435+
}

0 commit comments

Comments
 (0)