Skip to content

Conversation

@o-sdn-o
Copy link

@o-sdn-o o-sdn-o commented Oct 29, 2025

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 sshd prefix.

Fixes PowerShell/Win32-OpenSSH#2407

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
@tgauth
Copy link
Collaborator

tgauth commented Oct 30, 2025

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@tgauth tgauth requested a review from Copilot November 3, 2025 20:10
Copy link

Copilot AI left a 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 CreateEnvironmentBlock to 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.

@tgauth
Copy link
Collaborator

tgauth commented Nov 3, 2025

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@tgauth
Copy link
Collaborator

tgauth commented Nov 4, 2025

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Collaborator

@tgauth tgauth left a 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!

@tgauth tgauth merged commit 18133aa into PowerShell:latestw_all Nov 4, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

USERDOMAIN Environmental Variable Returns COMPUTERDOMAIN Value

2 participants