From f22501ce7d13a93fbf808eb292b9db45ee3f94d7 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 25 Feb 2025 02:48:19 -0800 Subject: [PATCH] Add elevation check at start --- Cargo.lock | 109 ++++++++++++++++++++++++++++++++++++----- boot_diags/Cargo.toml | 1 + boot_diags/src/main.rs | 24 +++++++-- deja_vu/Cargo.toml | 1 + deja_vu/src/main.rs | 24 +++++++-- 5 files changed, 138 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1296869..9a21a57 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -189,6 +189,7 @@ name = "boot-diags" version = "0.1.0" dependencies = [ "anyhow", + "check_elevation", "clap", "color-eyre", "core", @@ -289,6 +290,15 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "check_elevation" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34f7310b71e7b968cdadd13480b9e4f2def9f173f67fd7317e8eddb8d7a4ba00" +dependencies = [ + "windows", +] + [[package]] name = "clap" version = "4.5.27" @@ -585,6 +595,7 @@ name = "deja-vu" version = "0.2.0" dependencies = [ "anyhow", + "check_elevation", "clap", "color-eyre", "core", @@ -937,7 +948,7 @@ dependencies = [ "cfg-if", "libc", "wasi 0.13.3+wasi-0.2.2", - "windows-targets", + "windows-targets 0.52.6", ] [[package]] @@ -2044,7 +2055,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-targets", + "windows-targets 0.52.6", ] [[package]] @@ -3129,13 +3140,32 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.51.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca229916c5ee38c2f2bc1e9d8f04df975b4bd93f9955dc69fabb5d91270045c9" +dependencies = [ + "windows-core", + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-core" +version = "0.51.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1f8cf84f35d2db49a46868f947758c7a1138116f7fac3bc844f43ade1292e64" +dependencies = [ + "windows-targets 0.48.5", +] + [[package]] name = "windows-sys" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets", + "windows-targets 0.52.6", ] [[package]] @@ -3144,7 +3174,22 @@ version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" dependencies = [ - "windows-targets", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", ] [[package]] @@ -3153,28 +3198,46 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", ] +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + [[package]] name = "windows_aarch64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + [[package]] name = "windows_aarch64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + [[package]] name = "windows_i686_gnu" version = "0.52.6" @@ -3187,24 +3250,48 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + [[package]] name = "windows_i686_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + [[package]] name = "windows_x86_64_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + [[package]] name = "windows_x86_64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + [[package]] name = "windows_x86_64_msvc" version = "0.52.6" diff --git a/boot_diags/Cargo.toml b/boot_diags/Cargo.toml index cf73a7a..4cd14e3 100644 --- a/boot_diags/Cargo.toml +++ b/boot_diags/Cargo.toml @@ -40,6 +40,7 @@ toml = "0.8.13" tracing = "0.1.41" tracing-error = "0.2.0" tracing-subscriber = { version = "0.3.18", features = ["env-filter", "serde"] } +check_elevation = "0.2.4" [build-dependencies] anyhow = "1.0.86" diff --git a/boot_diags/src/main.rs b/boot_diags/src/main.rs index 3cefdda..7128445 100644 --- a/boot_diags/src/main.rs +++ b/boot_diags/src/main.rs @@ -24,11 +24,25 @@ mod diags; #[tokio::main] async fn main() -> Result<()> { - core::errors::init()?; - core::logging::init()?; + let mut msg = None; + if cfg!(windows) { + use check_elevation::is_elevated; + if !is_elevated().expect("Failed to get elevation status.") { + msg.replace("Administrator privedges required for Deja-Vu."); + } + }; + match msg { + Some(text) => { + println!("{text}"); + } + None => { + core::errors::init()?; + core::logging::init()?; - let args = core::cli::Cli::parse(); - let mut app = App::new(args.tick_rate, args.frame_rate)?; - app.run().await?; + let args = core::cli::Cli::parse(); + let mut app = App::new(args.tick_rate, args.frame_rate)?; + app.run().await?; + } + } Ok(()) } diff --git a/deja_vu/Cargo.toml b/deja_vu/Cargo.toml index ae4ab91..13af3e8 100644 --- a/deja_vu/Cargo.toml +++ b/deja_vu/Cargo.toml @@ -39,6 +39,7 @@ tokio-util = "0.7.11" tracing = "0.1.41" tracing-error = "0.2.0" tracing-subscriber = { version = "0.3.18", features = ["env-filter", "serde"] } +check_elevation = "0.2.4" [build-dependencies] anyhow = "1.0.86" diff --git a/deja_vu/src/main.rs b/deja_vu/src/main.rs index 82b0996..39999d2 100644 --- a/deja_vu/src/main.rs +++ b/deja_vu/src/main.rs @@ -23,11 +23,25 @@ mod app; #[tokio::main] async fn main() -> Result<()> { - core::errors::init()?; - core::logging::init()?; + let mut msg = None; + if cfg!(windows) { + use check_elevation::is_elevated; + if !is_elevated().expect("Failed to get elevation status.") { + msg.replace("Administrator privedges required for Deja-Vu."); + } + }; + match msg { + Some(text) => { + println!("{text}"); + } + None => { + core::errors::init()?; + core::logging::init()?; - let args = core::cli::Cli::parse(); - let mut app = App::new(args.tick_rate, args.frame_rate)?; - app.run().await?; + let args = core::cli::Cli::parse(); + let mut app = App::new(args.tick_rate, args.frame_rate)?; + app.run().await?; + } + } Ok(()) }