diff --git a/Cargo.lock b/Cargo.lock index 266ed837a..9e1eefa68 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -510,6 +510,7 @@ dependencies = [ "portable-pty", "rand", "ratatui", + "sudo", "temp-dir", "tree-sitter-bash", "tree-sitter-highlight", @@ -1006,6 +1007,16 @@ dependencies = [ "syn", ] +[[package]] +name = "sudo" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88bd84d4c082e18e37fef52c0088e4407dabcef19d23a607fb4b5ee03b7d5b83" +dependencies = [ + "libc", + "log", +] + [[package]] name = "syn" version = "2.0.77" diff --git a/tui/Cargo.toml b/tui/Cargo.toml index 40d3c357d..d5532b119 100644 --- a/tui/Cargo.toml +++ b/tui/Cargo.toml @@ -30,6 +30,7 @@ tree-sitter-highlight = "0.24.2" tree-sitter-bash = "0.23.1" anstyle = "1.0.8" ansi-to-tui = "6.0.0" +sudo = "0.6.0" zips = "0.1.7" [build-dependencies] diff --git a/tui/src/main.rs b/tui/src/main.rs index 801e3b1d2..2c309ee8b 100644 --- a/tui/src/main.rs +++ b/tui/src/main.rs @@ -36,6 +36,12 @@ struct Args { } fn main() -> io::Result<()> { + if sudo::check() != sudo::RunningAs::User { + eprintln!("Error: This program is not intended to be run with elevated privileges."); + eprintln!("Please run this program as a regular user to ensure proper security and functionality."); + std::process::exit(1); + } + let args = Args::parse(); let mut state = AppState::new(args.theme, args.override_validation);