diff --git a/Cargo.lock b/Cargo.lock index 965bb546..cbe23701 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4353,6 +4353,7 @@ dependencies = [ "eyre", "libc", "orb-build-info 0.0.0", + "rustix", "tempfile", "thiserror", ] diff --git a/Cargo.toml b/Cargo.toml index 8d37b1ab..2129a9be 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,6 +60,7 @@ libc = "0.2.153" nix = { version = "0.28", default-features = false, features = [] } reqwest = { version = "0.11", default-features = false, features = ["rustls-tls", "stream"] } ring = "0.16" +rustix = "0.38.37" secrecy = "0.8" serde = { version = "1.0.197", features = ["derive"] } serde_json = "1" diff --git a/slot-ctrl/Cargo.toml b/slot-ctrl/Cargo.toml index 77f0772e..e7026976 100644 --- a/slot-ctrl/Cargo.toml +++ b/slot-ctrl/Cargo.toml @@ -20,6 +20,13 @@ orb-build-info.path = "../build-info" thiserror.workspace = true tempfile = "3.12.0" +[dependencies.rustix] +workspace = true +features = [ + "fs", + "process", +] + [build-dependencies] orb-build-info = { path = "../build-info", features = ["build-script"] } diff --git a/slot-ctrl/src/efivar/mod.rs b/slot-ctrl/src/efivar/mod.rs index 2bbece6f..33d021b7 100644 --- a/slot-ctrl/src/efivar/mod.rs +++ b/slot-ctrl/src/efivar/mod.rs @@ -8,6 +8,7 @@ //! [efivar Documentation](https://www.kernel.org/doc/html/latest/filesystems/efivarfs.html) use std::{ + ffi::c_int, fs::{self, File}, io::{self, Read, Write}, path::{Path, PathBuf}, @@ -109,7 +110,7 @@ impl EfiVar { let file_read = File::open(&self.path).map_err(|e| Error::open_file(&self.path, e))?; - let original_attributes: libc::c_int = + let original_attributes: c_int = ioctl::read_file_attributes(&file_read).map_err(Error::GetAttributes)?; // Make file mutable. diff --git a/slot-ctrl/src/program.rs b/slot-ctrl/src/program.rs index 7661a873..a8e5ff4f 100644 --- a/slot-ctrl/src/program.rs +++ b/slot-ctrl/src/program.rs @@ -64,9 +64,9 @@ enum StatusCommands { } fn check_running_as_root(error: crate::Error) { - let uid = unsafe { libc::getuid() }; - let euid = unsafe { libc::geteuid() }; - if !matches!((uid, euid), (0, 0)) { + let uid = rustix::process::getuid(); + let euid = rustix::process::geteuid(); + if !(uid.is_root() && euid.is_root()) { println!("Please try again as root user."); exit(1) }