From 8c6883ce8409ce719dfd4b96dda108e5a5abae86 Mon Sep 17 00:00:00 2001 From: tuxuser <462620+tuxuser@users.noreply.github.com> Date: Sun, 8 Sep 2024 23:10:26 +0200 Subject: [PATCH] fix(daemon): Clearer error handling --- crates/impersonate/src/lib.rs | 8 +++++++- crates/solstice_daemon/src/main.rs | 19 +++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/crates/impersonate/src/lib.rs b/crates/impersonate/src/lib.rs index 5cd2a79..89cabe4 100644 --- a/crates/impersonate/src/lib.rs +++ b/crates/impersonate/src/lib.rs @@ -104,6 +104,10 @@ impl Impersonate { PrivilegeCheck(self.original_token, &mut priv_set, &mut priv_enabled)?; debug!("SeDebugPrivilege is: {:?}", priv_enabled); + + if priv_enabled.0 == 0 { + return Err("Failed to set enable debug privilege".into()); + } } Ok(()) @@ -113,7 +117,9 @@ impl Impersonate { unsafe { let proc_handle = OpenProcess(PROCESS_QUERY_INFORMATION, TRUE, pid)?; let new_token = Impersonate::get_impersonation_token(proc_handle)?; - SetThreadToken(None, new_token)?; + if let Err(e) = SetThreadToken(None, new_token) { + return Err("Failed to set thread token, err: {e:?}".into()); + } } Ok(()) } diff --git a/crates/solstice_daemon/src/main.rs b/crates/solstice_daemon/src/main.rs index d627860..a70ebb1 100644 --- a/crates/solstice_daemon/src/main.rs +++ b/crates/solstice_daemon/src/main.rs @@ -94,15 +94,18 @@ async fn main() { debug!("using config dir: {config_dir:?}"); let mut impersonate = Impersonate::create(); - if let Ok(_) = impersonate.do_impersonate_process_name("XboxUI.exe") { - if let Err(e) = toast::show_toast() { - error!("Failed to show toast notification: {:?}", e); + match impersonate.do_impersonate_process_name("XboxUI.exe") { + Ok(_) => { + if let Err(e) = toast::show_toast() { + error!("Failed to show toast notification: {:?}", e); + } + if let Err(e) = Impersonate::revert_to_self() { + error!("Failed to revert impersonation: {:?}", e); + } + }, + Err(e) => { + error!("Failed to impersonate to show toast notification, err={e:?}"); } - if let Err(e) = Impersonate::revert_to_self() { - error!("Failed to revert impersonation: {:?}", e); - } - } else { - error!("Failed to impersonate to show toast notification"); } if let Err(e) = crate::ssh::start_ssh_server(SSH_LISTEN_PORT, config_dir).await {