@@ -108,6 +108,10 @@ function Setup-OpenSSHTestEnvironment
108108 }
109109
110110 $Global :OpenSSHTestInfo.Add (" OpenSSHBinPath" , $script :OpenSSHBinPath )
111+ if (-not ($env: Path.ToLower ().Contains($script :OpenSSHBinPath.ToLower ())))
112+ {
113+ $env: Path = " $ ( $script :OpenSSHBinPath ) ;$ ( $env: path ) "
114+ }
111115
112116 $warning = @"
113117WARNING: Following changes will be made to OpenSSH configuration
@@ -125,15 +129,12 @@ WARNING: Following changes will be made to OpenSSH configuration
125129 if (-not $Quiet ) {
126130 Write-Warning $warning
127131 $continue = Read-Host - Prompt " Do you want to continue with the above changes? [Yes] Y; [No] N (default is `" Y`" )"
128- if ( ($continue -eq " " ) -or ($continue -ieq " Y" ) -or ($continue -ieq " Yes" ) )
129- {
130- }
131- elseif ( ($continue -ieq " N" ) -or ($continue -ieq " No" ) )
132+ if ( ($continue -ieq " N" ) -or ($continue -ieq " No" ) )
132133 {
133134 Write-Host " User decided not to make the changes."
134135 return
135136 }
136- else
137+ elseif (( $continue -ne " " ) -and ( $continue -ine " Y " ) -and ( $continue -ine " Yes " ))
137138 {
138139 Throw " User entered invalid option ($continue ). Exit now."
139140 }
@@ -152,9 +153,21 @@ WARNING: Following changes will be made to OpenSSH configuration
152153 Copy-Item (Join-Path $script :OpenSSHBinPath sshd_config) $backupConfigPath - Force
153154 }
154155
155- # copy new sshd_config
156- Copy-Item (Join-Path $Script :E2ETestDirectory sshd_config) (Join-Path $script :OpenSSHBinPath sshd_config) - Force
157- Copy-Item " $ ( $Script :E2ETestDirectory ) \sshtest*hostkey*" $script :OpenSSHBinPath - Force
156+ # copy new sshd_config
157+ Copy-Item (Join-Path $Script :E2ETestDirectory sshd_config) (Join-Path $script :OpenSSHBinPath sshd_config) - Force
158+
159+ # workaround for the cariggage new line added by git before copy them
160+ Get-ChildItem " $ ( $Script :E2ETestDirectory ) \sshtest_*key*" | % {
161+ (Get-Content $_.FullName - Raw).Replace(" `r`n " , " `n " ) | Set-Content $_.FullName - Force
162+ }
163+
164+ # copy sshtest keys
165+ Copy-Item " $ ( $Script :E2ETestDirectory ) \sshtest*hostkey*" $script :OpenSSHBinPath - Force
166+ $owner = New-Object System.Security.Principal.NTAccount($env: USERDOMAIN , $env: USERNAME )
167+ Get-ChildItem " $ ( $script :OpenSSHBinPath ) \sshtest*hostkey*" - Exclude * .pub | % {
168+ Cleanup- SecureFileACL - FilePath $_.FullName - Owner $owner
169+ Add-PermissionToFileACL - FilePath $_.FullName - User " NT Service\sshd" - Perm " Read"
170+ }
158171 Restart-Service sshd - Force
159172
160173 # Backup existing known_hosts and replace with test version
@@ -174,45 +187,50 @@ WARNING: Following changes will be made to OpenSSH configuration
174187 # TODO - this is Windows specific. Need to be in PAL
175188 foreach ($user in $OpenSSHTestAccounts )
176189 {
177- try
190+ try
178191 {
179192 $objUser = New-Object System.Security.Principal.NTAccount($user )
180193 $strSID = $objUser.Translate ([System.Security.Principal.SecurityIdentifier ])
181194 }
182195 catch
183- {
196+ {
184197 # only add the local user when it does not exists on the machine
185198 net user $user $Script :OpenSSHTestAccountsPassword / ADD 2>&1 >> $Script :TestSetupLogFile
186- }
199+ }
187200 }
188201
189- # setup single sign on for ssouser
190- # TODO - this is Windows specific. Need to be in PAL
191- $ssousersid = Get-UserSID - User sshtest_ssouser
192- $ssouserProfileRegistry = Join-Path " HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" $ssousersid
193- if (-not (Test-Path $ssouserProfileRegistry ) ) {
194- # create profile
195- if (-not ($env: DISPLAY )) { $env: DISPLAY = 1 }
196- $env: SSH_ASKPASS = " $ ( $env: ComSpec ) /c echo $ ( $OpenSSHTestAccountsPassword ) "
197- cmd / c " ssh -p 47002 sshtest_ssouser@localhost echo %userprofile% > profile.txt"
198- if ($env: DISPLAY -eq 1 ) { Remove-Item env:\DISPLAY }
199- remove-item " env:SSH_ASKPASS" - ErrorAction SilentlyContinue
200- }
201- $ssouserProfile = (Get-ItemProperty - Path $ssouserProfileRegistry - Name ' ProfileImagePath' ).ProfileImagePath
202+ # setup single sign on for ssouser
203+ $ssouserProfile = Get-LocalUserProfile - User $SSOUser
204+ $Global :OpenSSHTestInfo.Add (" SSOUserProfile" , $ssouserProfile )
205+ $Global :OpenSSHTestInfo.Add (" PubKeyUserProfile" , (Get-LocalUserProfile - User $PubKeyUser ))
206+
202207 New-Item - ItemType Directory - Path (Join-Path $ssouserProfile .ssh) - Force - ErrorAction SilentlyContinue | out-null
203208 $authorizedKeyPath = Join-Path $ssouserProfile .ssh\authorized_keys
204- $testPubKeyPath = Join-Path $Script :E2ETestDirectory sshtest_userssokey_ed25519.pub
205- # workaround for the cariggage new line added by git
206- (Get-Content $testPubKeyPath - Raw).Replace(" `r`n " , " `n " ) | Set-Content $testPubKeyPath - Force
209+ $testPubKeyPath = Join-Path $Script :E2ETestDirectory sshtest_userssokey_ed25519.pub
207210 Copy-Item $testPubKeyPath $authorizedKeyPath - Force - ErrorAction SilentlyContinue
208- $acl = get-acl $authorizedKeyPath
209- $ar = New-Object System.Security.AccessControl.FileSystemAccessRule(" NT Service\sshd" , " Read" , " Allow" )
210- $acl.SetAccessRule ($ar )
211- Set-Acl $authorizedKeyPath $acl
211+ Add-PermissionToFileACL - FilePath $authorizedKeyPath - User " NT Service\sshd" - Perm " Read"
212212 $testPriKeypath = Join-Path $Script :E2ETestDirectory sshtest_userssokey_ed25519
213- ( Get-Content $testPriKeypath - Raw).Replace( " `r`n " , " `n " ) | Set-Content $testPriKeypath - Force
213+ Cleanup - SecureFileACL - FilePath $testPriKeypath - owner $owner
214214 cmd / c " ssh-add $testPriKeypath 2>&1 >> $Script :TestSetupLogFile "
215215}
216+ # TODO - this is Windows specific. Need to be in PAL
217+ function Get-LocalUserProfile
218+ {
219+ param ([string ]$User )
220+ $sid = Get-UserSID - User $User
221+ $userProfileRegistry = Join-Path " HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" $sid
222+ if (-not (Test-Path $userProfileRegistry ) ) {
223+ # create profile
224+ if (-not ($env: DISPLAY )) { $env: DISPLAY = 1 }
225+ $env: SSH_ASKPASS = " $ ( $env: ComSpec ) /c echo $ ( $OpenSSHTestAccountsPassword ) "
226+ $ret = ssh - p 47002 " $User @localhost" echo % userprofile%
227+ if ($env: DISPLAY -eq 1 ) { Remove-Item env:\DISPLAY }
228+ remove-item " env:SSH_ASKPASS" - ErrorAction SilentlyContinue
229+ }
230+
231+ (Get-ItemProperty - Path $userProfileRegistry - Name ' ProfileImagePath' ).ProfileImagePath
232+ }
233+
216234
217235<#
218236 . SYNOPSIS
0 commit comments