pageant: fall back to GetUserNameA when GetUserNameExA fails - #726
Merged
Conversation
GetUserNameExA(NameUserPrincipal) requires a UPN, which does not exist on non-domain-joined Windows machines (standalone/workgroup). On such machines the API fails with ERROR_NONE_MAPPED (0x80070534), preventing any named-pipe connection to Pageant. The original PuTTY Pageant falls back to GetUserNameA in this case, but the Rust port was missing this fallback. Instead, fall back to the USERNAME environment variable, which provides the SAM account name and matches what GetUserNameA would return on local accounts. Fixes: inability to connect to Pageant on non-domain Windows setups
This was referenced Aug 13, 2026
|
Can confirm on Windows 11 with a local (non-domain) account: GetUserNameExA(NameUserPrincipal) fails with 0x80070534, so the transport never gets a pipe name even though the pipe is right there as The USERNAME fallback would've produced the correct name for us. Hit this while evaluating russh 0.62.6 for a desktop app. +1 for merging. |
Owner
|
Thanks - I've updated it to fall back to GetUserNameA to match what putty is actually doing |
Owner
|
@all-contributors add @cwatanab for code |
Contributor
|
We had trouble processing your request. Please try again later. |
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.
Problem
GetUserNameExA(NameUserPrincipal)requires a UPN (User Principal Name), which does not exist on non-domain-joined Windows machines (standalone/workgroup). On such machines the API fails withERROR_NONE_MAPPED(0x80070534), preventing any named-pipe connection to a running Pageant instance.This affects applications like DBX (Database Explorer) and the
pageantcrate itself.Root Cause
The original PuTTY Pageant (C implementation) falls back to
GetUserNameAwhenGetUserNameExAfails. The code comment acknowledges this but the Rust port chose not to implement the fallback, under the assumption that all modern Windows versions supportGetUserNameExA. However, even on modern Windows 10/11, a non-domain-joined machine has no UPN configured, and the API call fails.Fix
Fall back to the
USERNAMEenvironment variable whenGetUserNameExA(NameUserPrincipal)fails. This provides the SAM account name, which matches what the original PuTTY Pageant'sGetUserNameAfallback would return on local accounts.Testing
GetUserNameExA(NameUserPrincipal)consistently fails withERROR_NONE_MAPPEDUSERNAMEenv var contains the correct SAM account nameThis is consistent with how the reference PuTTY Pageant implementation handles this edge case.