Fix Windows session-based logon and lock-screen detection (#14620)

* Fix Windows session-based logon and lock-screen detection

  - scope LogonUI and locked-state checks to the current Windows session
  - allow permanent password fallback for logon and lock-screen access

Signed-off-by: 21pages <sunboeasy@gmail.com>

* Log permanent-password fallback on logon screen

Signed-off-by: 21pages <sunboeasy@gmail.com>

---------

Signed-off-by: 21pages <sunboeasy@gmail.com>
This commit is contained in:
21pages
2026-03-27 13:22:16 +08:00
committed by GitHub
parent 170516572e
commit f02cd9c0f6
3 changed files with 27 additions and 17 deletions

View File

@@ -580,9 +580,8 @@ extern "C"
return rdp_or_console;
}
BOOL is_session_locked(BOOL include_rdp)
BOOL is_session_locked(DWORD session_id)
{
DWORD session_id = get_current_session(include_rdp);
if (session_id == 0xFFFFFFFF) {
return FALSE;
}

View File

@@ -523,7 +523,7 @@ const SERVICE_TYPE: ServiceType = ServiceType::OWN_PROCESS;
extern "C" {
fn get_current_session(rdp: BOOL) -> DWORD;
fn is_session_locked(include_rdp: BOOL) -> BOOL;
fn is_session_locked(session_id: DWORD) -> BOOL;
fn LaunchProcessWin(
cmd: *const u16,
session_id: DWORD,
@@ -1149,20 +1149,21 @@ pub fn is_prelogin() -> bool {
}
pub fn is_locked() -> bool {
unsafe { is_session_locked(share_rdp()) == TRUE }
let Some(session_id) = get_current_process_session_id() else {
return false;
};
unsafe { is_session_locked(session_id) == TRUE }
}
// `is_logon_ui()` is regardless of multiple sessions now.
// It only check if "LogonUI.exe" exists.
//
// If there're mulitple sessions (logged in users),
// some are in the login screen, while the others are not.
// Then this function may not work fine if the session we want to handle(connect) is not in the login screen.
// But it's a rare case and cannot be simply handled, so it will not be dealt with for the time being.
#[inline]
pub fn is_logon_ui() -> ResultType<bool> {
let Some(current_sid) = get_current_process_session_id() else {
return Ok(false);
};
let pids = get_pids("LogonUI.exe")?;
Ok(!pids.is_empty())
Ok(pids
.into_iter()
.any(|pid| get_session_id_of_process(pid) == Some(current_sid)))
}
pub fn is_root() -> bool {