Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,5 @@ async fn main() {

// Main
mainCommand(loaded_prefs);

}
8 changes: 7 additions & 1 deletion src/utils/luks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,17 @@ pub fn check_luks(mount_address: &String, user_password: &Option<String>, pref:
cmd
};

let mut child = command.spawn().expect("Failed to spawn cryptsetup command");
let mut child = match command.spawn() {
Ok(child) => child,
Err(_) => return false, // Return false if spawn fails
};

if let Some(password) = user_password {
if let Some(stdin) = child.stdin.as_mut() {
stdin
.write_all(format!("{}\n", password).as_bytes())
.expect("Failed to write sudo password to stdin");
stdin.flush().expect("Failed to flush stdin");
}
}

Expand Down Expand Up @@ -96,13 +100,15 @@ pub fn lock(user_password: &Option<String>, address: &String, config: &HashMap<S
cmd
};

command.stdin(Stdio::piped());
let mut child = command.spawn().expect("Failed to spawn cryptsetup command");

if let Some(password) = user_password {
if let Some(stdin) = child.stdin.as_mut() {
stdin
.write_all(format!("{}\n", password).as_bytes())
.expect("Failed to write sudo password to stdin");
stdin.flush().expect("Failed to flush stdin");
}
}

Expand Down
37 changes: 35 additions & 2 deletions src/utils/mounting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub fn mount(mount_point: &MountPoint, preferences: &Preferences) {
});
unlock(&user_password, &mount_point.address, passphrase);
}
let encrypted = false;

let default_flags = if mount_point.ask_for_password == Some(true) {
let password = if use_dmenu {
Expand Down Expand Up @@ -109,8 +110,38 @@ pub fn mount(mount_point: &MountPoint, preferences: &Preferences) {
let flags1 = flag_merge(&default_flags, &global_flags, &merge_ignore);
let flags2 = flag_merge(&flags1, &mount_point_flags, &merge_ignore);

let mut command = Command::new("sudo");
command.arg("-S").arg("mount");
// Create the mountpoint folder if doesn't exist
let mut mkdir = Command::new(if sudo { "sudo" } else { "mkdir" });
if sudo {
mkdir.arg("-S").arg("mkdir");
}
mkdir.arg("-p").arg(&mount_point.mount_location);
mkdir.stdin(Stdio::piped());
let mut mkdir_child = mkdir.spawn().expect("Failed to spawn mount command");
if sudo {
if let Some(password) = &user_password {
if let Some(stdin) = mkdir_child.stdin.as_mut() {
stdin
.write_all(format!("{}\n", password).as_bytes())
.expect("Failed to write to stdin");
stdin.flush().expect("Failed to flush stdin");
}
}
}
let mkdir_output = mkdir_child.wait_with_output().expect("Failed to execute command");
if !mkdir_output.status.success() {
console_error(
&preferences.config,
format!("Mkdir failed with status code: {}", mkdir_output.status).as_str(),
);
eprintln!("Stderr: {}", String::from_utf8_lossy(&mkdir_output.stderr));
exit(1);
}

let mut command = Command::new(if sudo { "sudo" } else { "mount" });
if sudo {
command.arg("-S").arg("mount");
}

add_flags(&mut command, flags2);

Expand All @@ -123,6 +154,7 @@ pub fn mount(mount_point: &MountPoint, preferences: &Preferences) {
command.arg(&mount_point.address);
}
command.arg(&mount_point.mount_location);
command.stdin(Stdio::piped());

let mut child = command.spawn().expect("Failed to spawn mount command");

Expand All @@ -132,6 +164,7 @@ pub fn mount(mount_point: &MountPoint, preferences: &Preferences) {
stdin
.write_all(format!("{}\n", password).as_bytes())
.expect("Failed to write to stdin");
stdin.flush().expect("Failed to flush stdin");
}
}
}
Expand Down