Skip to content

Commit

Permalink
Merge pull request #570 from MolotovCherry/getcurrentprocess-service-…
Browse files Browse the repository at this point in the history
…patch

Use GetCurrentProcess instead of OpenProcess
  • Loading branch information
Nukesor authored Oct 22, 2024
2 parents c5a2697 + a3c3caf commit 4b7fa7d
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions pueue/src/daemon/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use std::{
ffi::{c_void, OsString},
iter,
path::PathBuf,
process, ptr,
ptr,
sync::{
atomic::{AtomicBool, Ordering},
mpsc::{channel, Receiver, Sender},
Expand All @@ -61,10 +61,9 @@ use windows::{
RemoteDesktop::{WTSGetActiveConsoleSessionId, WTSQueryUserToken},
SystemServices::MAXIMUM_ALLOWED,
Threading::{
CreateProcessAsUserW, GetExitCodeProcess, OpenProcess, OpenProcessToken,
CreateProcessAsUserW, GetCurrentProcess, GetExitCodeProcess, OpenProcessToken,
TerminateProcess, WaitForSingleObject, CREATE_NO_WINDOW,
CREATE_UNICODE_ENVIRONMENT, INFINITE, PROCESS_INFORMATION,
PROCESS_QUERY_INFORMATION, STARTUPINFOW,
CREATE_UNICODE_ENVIRONMENT, INFINITE, PROCESS_INFORMATION, STARTUPINFOW,
},
},
},
Expand Down Expand Up @@ -373,12 +372,11 @@ fn event_loop() -> Result<()> {
/// Set the specified process privilege to state.
/// https://learn.microsoft.com/en-us/windows/win32/secauthz/privilege-constants
fn set_privilege(name: PCWSTR, state: bool) -> Result<()> {
let handle: OwnedHandle =
unsafe { OpenProcess(PROCESS_QUERY_INFORMATION, false, process::id())?.into() };
let process: OwnedHandle = unsafe { GetCurrentProcess().into() };

let mut token: OwnedHandle = OwnedHandle::default();
unsafe {
OpenProcessToken(handle.0, TOKEN_ADJUST_PRIVILEGES, &mut token.0)?;
OpenProcessToken(process.0, TOKEN_ADJUST_PRIVILEGES, &mut token.0)?;
}

let mut luid = LUID::default();
Expand Down

0 comments on commit 4b7fa7d

Please sign in to comment.