Skip to content

Commit

Permalink
fix(daemon): Clearer error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxuser committed Sep 8, 2024
1 parent b8986a4 commit 8c6883c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
8 changes: 7 additions & 1 deletion crates/impersonate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand All @@ -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(())
}
Expand Down
19 changes: 11 additions & 8 deletions crates/solstice_daemon/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 8c6883c

Please sign in to comment.