Repository navigation
Fix user environment block construction - #813
Merged
Tess Gauthier (tgauth) merged 17 commits intoNov 4, 2025
Merged
Tess Gauthier (tgauth) merged 17 commits into
Tess Gauthier (tgauth) merged 17 commits into
Conversation
Currently, when a user connects, the environment block from the LocalSystem context in which sshd.exe is running is used to create the user session environment. The fix ensures that the user environment block is loaded for users with names without the sshd prefix. Fixes PowerShell/Win32-OpenSSH#2407
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Pull Request Overview
This PR refactors Windows environment handling for SSH sessions to use the Windows CreateEnvironmentBlock API instead of manually setting environment variables from the registry. The key changes simplify environment setup by leveraging Windows native functionality while maintaining session state.
- Introduces
CreateEnvironmentBlockto automatically load user environment blocks with session state inheritance - Refactors registry access code to be more focused and efficient
- Adds username extraction from user tokens to conditionally apply environment blocks
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| contrib/win32/win32compat/w32fd.c | Adds get_username_from_token function and updates spawn_child_internal to conditionally create user environment blocks, excluding sshd service accounts |
| contrib/win32/win32compat/w32-doexec.c | Refactors setup_session_user_vars to only set HOMEPATH/HOMEDRIVE and PATH, removes manual registry enumeration of all environment variables, adds get_registry_key_value helper function |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…block for 'sshd' users)
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Tess Gauthier (tgauth)
approved these changes
Nov 4, 2025
Tess Gauthier (tgauth)
left a comment
Collaborator
There was a problem hiding this comment.
thanks Dmitry Sapozhnikov (@o-sdn-o)!
Hazel Duvall (hazelduvall)
pushed a commit
to hazelduvall/openssh-portable
that referenced
this pull request
May 6, 2026
* Fix user environment block construction. Currently, when a user connects, the environment block from the LocalSystem context in which sshd.exe is running is used to create the user session environment. The fix ensures that the user environment block is loaded for users with names without the sshd prefix. Fixes PowerShell/Win32-OpenSSH#2407 * Simplify user environment block loading * Do not reassign environment variables * Edit comments * Set the HOMEPATH and HOMEDRIVE variables only if they are not assigned * Edit comments * Fix error_message releasing * Fix error_message releasing * Fix user_path releasing * Fix user_name/domain_name lookup * Fix incorrect size calculation (name_length/domain_length) * Use wcslen(L"sshd") for clarity * Reverse the condition to match the comment (don't create environment block for 'sshd' users) * Fix cases where only HKLM or only HKCU PATH is available * Fix incorrect spelling ('preppended' -> 'prepended') * Revert reversing the condition to match the comment * Use wcslen(L"sshd") for clarity (again)
3 tasks done
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.
PR Summary
Fix construction of user environment block when user connects.
PR Context
Currently, when a user connects, the environment block from the LocalSystem context (in which sshd.exe
is running) is used to create the user session environment.
The fix ensures that the user environment block is loaded for users with names without the
sshdprefix.Fixes PowerShell/Win32-OpenSSH#2407