From c997a3d89e6908a6fb76d15da03ee43a6ed4fdda Mon Sep 17 00:00:00 2001 From: Jeevitha Kannan K S Date: Sun, 13 Oct 2024 18:37:30 +0530 Subject: [PATCH] Add root check --- Cargo.lock | 11 +++++++++++ tui/Cargo.toml | 1 + tui/src/main.rs | 6 ++++++ 3 files changed, 18 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 266ed837..9e1eefa6 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 40d3c357..d5532b11 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 801e3b1d..2c309ee8 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);