@@ -108,6 +108,10 @@ function Setup-OpenSSHTestEnvironment
108
108
}
109
109
110
110
$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
+ }
111
115
112
116
$warning = @"
113
117
WARNING: Following changes will be made to OpenSSH configuration
@@ -125,15 +129,12 @@ WARNING: Following changes will be made to OpenSSH configuration
125
129
if (-not $Quiet ) {
126
130
Write-Warning $warning
127
131
$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" ) )
132
133
{
133
134
Write-Host " User decided not to make the changes."
134
135
return
135
136
}
136
- else
137
+ elseif (( $continue -ne " " ) -and ( $continue -ine " Y " ) -and ( $continue -ine " Yes " ))
137
138
{
138
139
Throw " User entered invalid option ($continue ). Exit now."
139
140
}
@@ -152,9 +153,21 @@ WARNING: Following changes will be made to OpenSSH configuration
152
153
Copy-Item (Join-Path $script :OpenSSHBinPath sshd_config) $backupConfigPath - Force
153
154
}
154
155
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
+ }
158
171
Restart-Service sshd - Force
159
172
160
173
# Backup existing known_hosts and replace with test version
@@ -174,45 +187,50 @@ WARNING: Following changes will be made to OpenSSH configuration
174
187
# TODO - this is Windows specific. Need to be in PAL
175
188
foreach ($user in $OpenSSHTestAccounts )
176
189
{
177
- try
190
+ try
178
191
{
179
192
$objUser = New-Object System.Security.Principal.NTAccount($user )
180
193
$strSID = $objUser.Translate ([System.Security.Principal.SecurityIdentifier ])
181
194
}
182
195
catch
183
- {
196
+ {
184
197
# only add the local user when it does not exists on the machine
185
198
net user $user $Script :OpenSSHTestAccountsPassword / ADD 2>&1 >> $Script :TestSetupLogFile
186
- }
199
+ }
187
200
}
188
201
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
+
202
207
New-Item - ItemType Directory - Path (Join-Path $ssouserProfile .ssh) - Force - ErrorAction SilentlyContinue | out-null
203
208
$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
207
210
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"
212
212
$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
214
214
cmd / c " ssh-add $testPriKeypath 2>&1 >> $Script :TestSetupLogFile "
215
215
}
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
+
216
234
217
235
<#
218
236
. SYNOPSIS
0 commit comments