Conversation
NativeAction::LockScreen synthesised Win+L via SendInput, but winlogon's own secure-desktop hotkey doesn't reliably react to a synthetic Win key press — only the bare L key took effect, so the screen never locked. Call the documented LockWorkStation API directly instead, the same way the macOS backend already calls pmset for Sleep rather than faking a key combo. NativeAction::Sleep was entirely unimplemented on Windows (skipped with a debug log). Wire it to SetSuspendState, which needs SeShutdownPrivilege enabled on the process token first — every process has the privilege available but disabled by default, so add the standard OpenProcessToken/LookupPrivilegeValueW/AdjustTokenPrivileges dance. Fixes AprilNEA#1266
|
enable_shutdown_privilege() flipped SeShutdownPrivilege on for the process token but never restored it — the privilege is a process-wide token attribute, not scoped to the enabling call, so it stayed enabled for the rest of this long-running agent process regardless of whether SetSuspendState succeeded. Splits enable/disable into one adjust_shutdown_privilege(token, attributes) helper reused for both directions, disables the privilege again after the SetSuspendState attempt (success or failure), and adds a mutex around the whole enable/suspend/disable sequence so concurrent Sleep requests can't interleave their privilege toggles. Addresses the Greptile security finding on AprilNEA#1447.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
NativeAction::LockScreenandNativeAction::Sleepboth did nothing useful on Windows.Changes
crates/openlogi-inject/src/inject/windows.rs:LockScreensynthesised Win+L viaSendInput, but as a second reporter confirmed in the issue thread, only the bareLkey actually took effect — winlogon's own secure-desktop hotkey doesn't reliably react to a synthetic Win key press. Switch to callingLockWorkStation()directly, the documented, privilege-free API for exactly this, matching the precedent this same file already sets for macOSSleep(callingpmset sleepnowinstead of faking a key combo).Sleepwas entirely unimplemented (skipped with a debug log, per the existing comment: "no clean win from a background agent"). Wired it toSetSuspendState, which needsSeShutdownPrivilegeenabled on the process token first — every process has the privilege available but disabled by default. Added the standardOpenProcessToken/LookupPrivilegeValueW/AdjustTokenPrivilegesdance, checkingGetLastErrorimmediately afterAdjustTokenPrivileges(before any other call can overwrite it) since that API reports success even when it silently enabled none of the requested privileges.crates/openlogi-inject/Cargo.toml: added thewindows-sysfeature flags these APIs live behind (Win32_Foundation,Win32_Security,Win32_System_Power,Win32_System_Shutdown,Win32_System_Threading).Testing
rustup target add x86_64-pc-windows-gnu, then:cargo check --target x86_64-pc-windows-gnu -p openlogi-inject(caught a real type mismatch onSetSuspendState's bool-typed parameters in thiswindows-sysversion — fixed before this PR)cargo clippy --target x86_64-pc-windows-gnu -p openlogi-inject --all-targets -- -D warningsCargo.tomlchanged:cargo fmt --all -- --check,cargo clippy --workspace --all-targets -- -D warnings,cargo test --workspace,cargo doc --workspace --no-deps --document-private-items(excluding the GUI crates) — all green.LockWorkStation/SetSuspendStateactually lock/sleep the machine, or that the privilege-enable dance succeeds from this agent's actual process context, without real Windows hardware.Fixes #1266