Skip to content

Commit

Permalink
Merge pull request #829 from cgwalters/drop-gvariant
Browse files Browse the repository at this point in the history
Drop gvariant
  • Loading branch information
cgwalters authored Oct 16, 2024
2 parents 49618d9 + abf7eae commit 16b1472
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ clap_mangen = { version = "0.2.20", optional = true }
cap-std-ext = { workspace = true, features = ["fs_utf8"] }
hex = "^0.4.3"
fn-error-context = { workspace = true }
gvariant = "0.5.0"
indicatif = "0.17.8"
libc = { workspace = true }
liboverdrop = "0.1.0"
Expand Down
30 changes: 22 additions & 8 deletions lib/src/lsm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ use cap_std_ext::cap_std::fs::{Metadata, MetadataExt};
#[cfg(feature = "install")]
use cap_std_ext::dirext::CapStdExtDirExt;
use fn_error_context::context;
#[cfg(feature = "install")]
use gvariant::{aligned_bytes::TryAsAligned, Marker, Structure};
use ostree_ext::gio;
use ostree_ext::ostree;
use rustix::fd::AsFd;
Expand Down Expand Up @@ -177,12 +175,12 @@ pub(crate) fn selinux_set_permissive(permissive: bool) -> Result<()> {
#[cfg(feature = "install")]
/// Check if the ostree-formatted extended attributes include a security.selinux value.
pub(crate) fn xattrs_have_selinux(xattrs: &ostree::glib::Variant) -> bool {
let v = xattrs.data_as_bytes();
let v = v.try_as_aligned().unwrap();
let v = gvariant::gv!("a(ayay)").cast(v);
for xattr in v.iter() {
let k = xattr.to_tuple().0;
if k == SELINUX_XATTR {
let n = xattrs.n_children();
for i in 0..n {
let child = xattrs.child_value(i);
let key = child.child_value(0);
let key = key.data_as_bytes();
if key == SELINUX_XATTR {
return true;
}
}
Expand Down Expand Up @@ -419,3 +417,19 @@ where
f(w)
})
}

#[cfg(test)]
mod tests {
use super::*;
use gio::glib::Variant;

#[test]
fn test_selinux_xattr() {
let notfound: &[&[(&[u8], &[u8])]] = &[&[], &[(b"foo", b"bar")]];
for case in notfound {
assert!(!xattrs_have_selinux(&Variant::from(case)));
}
let found: &[(&[u8], &[u8])] = &[(b"foo", b"bar"), (SELINUX_XATTR, b"foo_t")];
assert!(xattrs_have_selinux(&Variant::from(found)));
}
}

0 comments on commit 16b1472

Please sign in to comment.