Skip to content

Commit

Permalink
xattr
Browse files Browse the repository at this point in the history
  • Loading branch information
Gekko0114 committed May 29, 2024
1 parent 5dd8c5f commit f5a1bed
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
3 changes: 2 additions & 1 deletion experiment/selinux/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod selinux;
pub mod selinux;
pub mod xattr;
28 changes: 26 additions & 2 deletions experiment/selinux/src/selinux.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
use std::io;
use crate::xattr::*;


const XATTR_NAME_SELINUX: &str = "security.selinux";
const ERR_EMPTY_PATH: &str = "empty path";

pub fn set_disabled() {
panic!("not implemented yet")
}
Expand All @@ -10,8 +17,25 @@ pub fn class_index(class: &str) -> Result<i64, String> {
panic!("not implemented yet")
}

pub fn set_file_label(fpath: &str, label: &str) {
panic!("not implemented yet")
// set_file_label sets the SELinux label for this path, following symlinks, or returns an error.
pub fn set_file_label(fpath: &str, label: &str) -> Result<(), std::io::Error> {
if fpath.is_empty() {
return Err(std::io::Error::new(io::ErrorKind::InvalidInput, ERR_EMPTY_PATH));
}

loop {
match set_xattr(fpath, XATTR_NAME_SELINUX, label.as_bytes(), 0) {
Ok(_) => break,
// TODO: Err(Errno::EINTR) => continue,
Err(e) => {
return Err(std::io::Error::new(
std::io::ErrorKind::Other,
format!("setxattr failed: {}", e),
));
}
}
}
Ok(())
}

pub fn lset_file_label(fpath: &str, label: &str) {
Expand Down
3 changes: 3 additions & 0 deletions experiment/selinux/src/xattr/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod xattr;

pub use xattr::*;
4 changes: 4 additions & 0 deletions experiment/selinux/src/xattr/xattr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

pub fn set_xattr(fpath: &str, attr: &str, data: &[u8], flags: i64) -> Result<(), std::io::Error> {
panic!("not implemented yet")
}

0 comments on commit f5a1bed

Please sign in to comment.