diff options
author | qkzk <qu3nt1n@gmail.com> | 2023-04-12 18:26:54 +0200 |
---|---|---|
committer | qkzk <qu3nt1n@gmail.com> | 2023-04-12 18:27:50 +0200 |
commit | 99c4b33276016b3fcadf5e1d8761b985ae70056d (patch) | |
tree | 8cd89ec12f84347ea7fe90ce0508277712944c23 /src/event_exec.rs | |
parent | d0f34b98002f44c7fe307e83db02c3cfb4f3915e (diff) |
run a shell sudo command with `sudo command args`
Diffstat (limited to 'src/event_exec.rs')
-rw-r--r-- | src/event_exec.rs | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/src/event_exec.rs b/src/event_exec.rs index 1e66987..3b7ef2a 100644 --- a/src/event_exec.rs +++ b/src/event_exec.rs @@ -15,6 +15,7 @@ use crate::config::Colors; use crate::constant_strings_paths::{CONFIG_PATH, DEFAULT_DRAGNDROP}; use crate::content_window::RESERVED_ROWS; use crate::copy_move::CopyMove; +use crate::cryptsetup::drop_sudo; use crate::cryptsetup::BlockDeviceAction; use crate::fileinfo::FileKind; use crate::filter::FilterKind; @@ -28,7 +29,7 @@ use crate::opener::{ execute_and_capture_output_without_check, execute_in_child, execute_in_child_without_output_with_path, InternalVariant, }; -use crate::password::sudo_password; +use crate::password::sudo_with_password; use crate::password::{PasswordKind, PasswordUsage}; use crate::preview::Preview; use crate::selectable_content::SelectableContent; @@ -1874,34 +1875,33 @@ impl EventExec { ) -> Result<()> { match dest { PasswordUsage::ISO => match action { - Some(BlockDeviceAction::MOUNT) => { - EventExec::event_mount_iso_drive(status)?; - } - Some(BlockDeviceAction::UMOUNT) => { - EventExec::event_umount_iso_drive(status)?; - } - None => (), + Some(BlockDeviceAction::MOUNT) => EventExec::event_mount_iso_drive(status), + Some(BlockDeviceAction::UMOUNT) => EventExec::event_umount_iso_drive(status), + None => Ok(()), }, PasswordUsage::CRYPTSETUP => match action { - Some(BlockDeviceAction::MOUNT) => { - EventExec::event_mount_encrypted_drive(status)?; - } - Some(BlockDeviceAction::UMOUNT) => { - EventExec::event_umount_encrypted_drive(status)?; - } - None => (), + Some(BlockDeviceAction::MOUNT) => EventExec::event_mount_encrypted_drive(status), + Some(BlockDeviceAction::UMOUNT) => EventExec::event_umount_encrypted_drive(status), + None => Ok(()), }, - PasswordUsage::SUDOCOMMAND => { - let Some(sudo_command) = &status.sudo_command else { return Ok(()); }; - info!("dispatch password {sudo_command}"); - let args = ShellCommandParser::new(sudo_command).compute(status)?; - if args.is_empty() { - return Ok(()); - } - sudo_password(&args[1..], &status.password_holder.sudo()?)?; - } + PasswordUsage::SUDOCOMMAND => Self::run_sudo_command(status), } - Ok(()) + } + + fn run_sudo_command(status: &mut Status) -> Result<()> { + let Some(sudo_command) = &status.sudo_command else { return Ok(()); }; + info!("dispatch password {sudo_command}"); + let mut args = ShellCommandParser::new(sudo_command).compute(status)?; + if args.len() < 2 { + return Ok(()); + } + args.remove(0); + if args[0] != *"-S" { + args.insert(0, "-S".to_owned()); + } + sudo_with_password(&args[1..], &status.password_holder.sudo()?)?; + status.password_holder.reset(); + drop_sudo() } /// Open the config file. |