Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pageant/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ namedpipes = [
"dep:windows-strings",
"windows/Win32_Security_Authentication_Identity",
"windows/Win32_Security_Cryptography",
"windows/Win32_System_WindowsProgramming",
]
17 changes: 12 additions & 5 deletions pageant/src/namedpipes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use windows::Win32::Security::Authentication::Identity::{GetUserNameExA, NameUse
use windows::Win32::Security::Cryptography::{
CRYPTPROTECTMEMORY_BLOCK_SIZE, CRYPTPROTECTMEMORY_CROSS_PROCESS, CryptProtectMemory,
};
use windows::Win32::System::WindowsProgramming::GetUserNameA;
use windows_strings::PSTR;

use crate::Error;
Expand Down Expand Up @@ -65,11 +66,17 @@ impl PageantStream {
Some(PSTR(name_buf.as_mut_ptr())),
&mut name_length,
) {
// Pageant falls back to GetUserNameA here,
// but as far as I can tell, all Versions of Windows supported by Rust today
// should be able to answer the UserNameEx request - the comments in Pageant source
// point to Windows XP and earlier compatibility...
return Err(Error::from_win32());
// GetUserNameExA fails on non-domain-joined machines, where no UPN
// (NameUserPrincipal) is configured. Fall back to GetUserNameA
// (the SAM account name), like the original PuTTY Pageant.
debug!("GetUserNameExA failed, falling back to GetUserNameA");

let mut name_length = 0;
// don't check result on this, always returns ERROR_INSUFFICIENT_BUFFER
let _ = GetUserNameA(None, &mut name_length);

name_buf = vec![0u8; name_length as usize];
GetUserNameA(Some(PSTR(name_buf.as_mut_ptr())), &mut name_length)?;
}

//remove terminating null
Expand Down
Loading