summaryrefslogtreecommitdiff
path: root/init/src/mounts/rescue.rs
diff options
context:
space:
mode:
Diffstat (limited to 'init/src/mounts/rescue.rs')
-rw-r--r--init/src/mounts/rescue.rs46
1 files changed, 41 insertions, 5 deletions
diff --git a/init/src/mounts/rescue.rs b/init/src/mounts/rescue.rs
index 078984d..2238297 100644
--- a/init/src/mounts/rescue.rs
+++ b/init/src/mounts/rescue.rs
@@ -1,6 +1,29 @@
-use crate::log::log_success;
+use crate::log::{log_success, log_warning};
use std::ffi::CString;
-use std::fs::create_dir;
+use std::fs::{create_dir, metadata};
+use std::os::unix::fs::MetadataExt;
+
+fn check_mount_point_permissions(path: &str) -> Result<(), Box<dyn std::error::Error>> {
+ if !std::path::Path::new(path).exists() {
+ create_dir(path)?;
+ }
+
+ let meta = metadata(path)?;
+
+ if !meta.is_dir() {
+ return Err(format!("Mount point {} is not a directory", path).into());
+ }
+
+ // TODO
+ // let mode = meta.mode();
+
+ let uid = meta.uid();
+ if uid != 0 {
+ log_warning(&format!("Warning: Mount point {} not owned by root", path));
+ }
+
+ Ok(())
+}
pub fn mount_system() -> Result<(), Box<dyn std::error::Error>> {
let mounts: &[(&str, &str, Option<&str>)] = &[
@@ -13,11 +36,24 @@ pub fn mount_system() -> Result<(), Box<dyn std::error::Error>> {
unsafe {
for &(target, fstype, source) in mounts {
+ if let Err(e) = check_mount_point_permissions(target) {
+ log_warning(&format!("Permission check failed for {}: {}", target, e));
+ }
+
let target_c = CString::new(target)?;
let fstype_c = CString::new(fstype)?;
- let source_c = source.map(|s| CString::new(s).unwrap());
-
- let _ = create_dir(target);
+ // let source_c = source.map(|s| CString::new(s).map_err(|e| ));
+ let source_c = match source {
+ Some(s) => match CString::new(s) {
+ Ok(c_string) => Some(c_string),
+ Err(null_err) => {
+ log_warning(&format!("Source string contains NULL bytes (\\0), skipping: {}", null_err));
+ continue;
+ }
+ },
+ None => None
+ };
+
let source_ptr = source_c.as_ref().map_or(std::ptr::null(), |s| s.as_ptr());