@@ -19,8 +19,6 @@ use cap_std_ext::cap_std::fs::{Metadata, MetadataExt};
19
19
#[ cfg( feature = "install" ) ]
20
20
use cap_std_ext:: dirext:: CapStdExtDirExt ;
21
21
use fn_error_context:: context;
22
- #[ cfg( feature = "install" ) ]
23
- use gvariant:: { aligned_bytes:: TryAsAligned , Marker , Structure } ;
24
22
use ostree_ext:: gio;
25
23
use ostree_ext:: ostree;
26
24
use rustix:: fd:: AsFd ;
@@ -177,12 +175,12 @@ pub(crate) fn selinux_set_permissive(permissive: bool) -> Result<()> {
177
175
#[ cfg( feature = "install" ) ]
178
176
/// Check if the ostree-formatted extended attributes include a security.selinux value.
179
177
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 {
186
184
return true ;
187
185
}
188
186
}
@@ -419,3 +417,19 @@ where
419
417
f ( w)
420
418
} )
421
419
}
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