-
Notifications
You must be signed in to change notification settings - Fork 354
Fix user environment block construction #813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix user environment block construction #813
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
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
tgauth
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @o-sdn-o!
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