Skip to content

Commit 9fd0cda

Browse files
committed
Source snapshot from Powershell/openssh-portable:latestw_all
1 parent 6a86fdd commit 9fd0cda

17 files changed

+260
-141
lines changed

appveyor.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: 0.0.13.0.{build}
1+
version: 0.0.14.0.{build}
22
image: Visual Studio 2015
33

44
branches:

contrib/win32/openssh/OpenSSHTestHelper.psm1

+75-8
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ WARNING: Following changes will be made to OpenSSH configuration
119119
- will be replaced with a test sshd_config
120120
- $HOME\.ssh\known_hosts will be backed up as known_hosts.ori
121121
- will be replaced with a test known_hosts
122+
- $HOME\.ssh\config will be backed up as config.ori
123+
- will be replaced with a test config
122124
- sshd test listener will be on port 47002
123125
- $HOME\.ssh\known_hosts will be modified with test host key entry
124126
- test accounts - ssouser, pubkeyuser, and passwduser will be added
@@ -172,17 +174,23 @@ WARNING: Following changes will be made to OpenSSH configuration
172174

173175
#Backup existing known_hosts and replace with test version
174176
#TODO - account for custom known_hosts locations
175-
$knowHostsDirectoryPath = Join-Path $home .ssh
176-
$knowHostsFilePath = Join-Path $knowHostsDirectoryPath known_hosts
177-
if(-not (Test-Path $knowHostsDirectoryPath -PathType Container))
177+
$dotSshDirectoryPath = Join-Path $home .ssh
178+
$knowHostsFilePath = Join-Path $dotSshDirectoryPath known_hosts
179+
if(-not (Test-Path $dotSshDirectoryPath -PathType Container))
178180
{
179-
New-Item -ItemType Directory -Path $knowHostsDirectoryPath -Force -ErrorAction SilentlyContinue | out-null
181+
New-Item -ItemType Directory -Path $dotSshDirectoryPath -Force -ErrorAction SilentlyContinue | out-null
180182
}
181-
if ((Test-Path $knowHostsFilePath -PathType Leaf) -and (-not (Test-Path (Join-Path $knowHostsDirectoryPath known_hosts.ori) -PathType Leaf))) {
182-
Copy-Item $knowHostsFilePath (Join-Path $knowHostsDirectoryPath known_hosts.ori) -Force
183+
if ((Test-Path $knowHostsFilePath -PathType Leaf) -and (-not (Test-Path (Join-Path $dotSshDirectoryPath known_hosts.ori) -PathType Leaf))) {
184+
Copy-Item $knowHostsFilePath (Join-Path $dotSshDirectoryPath known_hosts.ori) -Force
183185
}
184186
Copy-Item (Join-Path $Script:E2ETestDirectory known_hosts) $knowHostsFilePath -Force
185187

188+
$sshConfigFilePath = Join-Path $dotSshDirectoryPath config
189+
if ((Test-Path $sshConfigFilePath -PathType Leaf) -and (-not (Test-Path (Join-Path $dotSshDirectoryPath config.ori) -PathType Leaf))) {
190+
Copy-Item $sshConfigFilePath (Join-Path $dotSshDirectoryPath config.ori) -Force
191+
}
192+
Copy-Item (Join-Path $Script:E2ETestDirectory ssh_config) $sshConfigFilePath -Force
193+
186194
# create test accounts
187195
#TODO - this is Windows specific. Need to be in PAL
188196
foreach ($user in $OpenSSHTestAccounts)
@@ -212,6 +220,7 @@ WARNING: Following changes will be made to OpenSSH configuration
212220
$testPriKeypath = Join-Path $Script:E2ETestDirectory sshtest_userssokey_ed25519
213221
Cleanup-SecureFileACL -FilePath $testPriKeypath -owner $owner
214222
cmd /c "ssh-add $testPriKeypath 2>&1 >> $Script:TestSetupLogFile"
223+
Backup-OpenSSHTestInfo
215224
}
216225
#TODO - this is Windows specific. Need to be in PAL
217226
function Get-LocalUserProfile
@@ -314,6 +323,14 @@ function Cleanup-OpenSSHTestEnvironment
314323
Remove-Item $originKnowHostsPath -Force -ErrorAction SilentlyContinue
315324
}
316325

326+
#Restore ssh_config
327+
$originConfigPath = Join-Path $home .ssh\config.ori
328+
if (Test-Path $originConfigPath)
329+
{
330+
Copy-Item $originConfigPath (Join-Path $home .ssh\config) -Force -ErrorAction SilentlyContinue
331+
Remove-Item $originConfigPath -Force -ErrorAction SilentlyContinue
332+
}
333+
317334
#Delete accounts
318335
foreach ($user in $OpenSSHTestAccounts)
319336
{
@@ -395,7 +412,7 @@ function Run-OpenSSHE2ETest
395412
# Discover all CI tests and run them.
396413
Push-Location $Script:E2ETestDirectory
397414
Write-Log -Message "Running OpenSSH E2E tests..."
398-
$testFolders = Get-ChildItem *.tests.ps1 -Recurse -Exclude SSHDConfig.tests.ps1, SSH.Tests.ps1 | ForEach-Object{ Split-Path $_.FullName} | Sort-Object -Unique
415+
$testFolders = Get-ChildItem *.tests.ps1 -Recurse | ForEach-Object{ Split-Path $_.FullName} | Sort-Object -Unique
399416
Invoke-Pester $testFolders -OutputFormat NUnitXml -OutputFile $Script:E2ETestResultsFile -Tag 'CI'
400417
Pop-Location
401418
}
@@ -439,6 +456,56 @@ function Run-OpenSSHUnitTest
439456
$testfailed
440457
}
441458

459+
function Backup-OpenSSHTestInfo
460+
{
461+
param
462+
(
463+
[string] $BackupFile = $null
464+
)
465+
466+
if ($Global:OpenSSHTestInfo -eq $null) {
467+
Throw "`$OpenSSHTestInfo is null. Did you run Setup-OpenSSHTestEnvironment yet?"
468+
}
469+
470+
$testInfo = $Global:OpenSSHTestInfo
471+
472+
if ([String]::IsNullOrEmpty($BackupFile)) {
473+
$BackupFile = Join-Path $testInfo["TestDataPath"] "OpenSSHTestInfo_backup.txt"
474+
}
475+
476+
$null | Set-Content $BackupFile
477+
478+
foreach ($key in $testInfo.Keys) {
479+
$value = $testInfo[$key]
480+
Add-Content $BackupFile "$key,$value"
481+
}
482+
}
483+
484+
function Recover-OpenSSHTestInfo
485+
{
486+
param
487+
(
488+
[Parameter(Mandatory=$true)]
489+
[ValidateNotNullOrEmpty()]
490+
[string] $BackupFile
491+
)
492+
493+
if($Global:OpenSSHTestInfo -ne $null)
494+
{
495+
$Global:OpenSSHTestInfo.Clear()
496+
$Global:OpenSSHTestInfo = $null
497+
}
498+
499+
$Global:OpenSSHTestInfo = @{}
500+
501+
$entries = Get-Content $BackupFile
502+
503+
foreach ($entry in $entries) {
504+
$data = $entry.Split(",")
505+
$Global:OpenSSHTestInfo[$data[0]] = $data[1]
506+
}
507+
}
508+
442509
<#
443510
Write-Log
444511
#>
@@ -460,4 +527,4 @@ function Write-Log
460527
}
461528
}
462529

463-
Export-ModuleMember -Function Setup-OpenSSHTestEnvironment, Cleanup-OpenSSHTestEnvironment, Run-OpenSSHUnitTest, Run-OpenSSHE2ETest
530+
Export-ModuleMember -Function Setup-OpenSSHTestEnvironment, Cleanup-OpenSSHTestEnvironment, Run-OpenSSHUnitTest, Run-OpenSSHE2ETest, Backup-OpenSSHTestInfo, Recover-OpenSSHTestInfo

contrib/win32/openssh/version.rc

0 Bytes
Binary file not shown.

contrib/win32/win32compat/console.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ typedef struct _SCREEN_RECORD {
6666

6767
PSCREEN_RECORD pSavedScreenRec = NULL;
6868
int in_raw_mode = 0;
69-
char *consoleTitle = "Microsoft openSSH client";
69+
char *consoleTitle = "OpenSSH SSH client";
7070

7171
/* Used to enter the raw mode */
7272
int

contrib/win32/win32compat/misc.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ char* _sys_errlist_ext[] = {
117117
"No STREAM resources", /* ENOSR 124 */
118118
"Not a STREAM", /* ENOSTR 125 */
119119
"The socket is not connected", /* ENOTCONN 126 */
120-
"enotecoverable", /* ENOTRECOVERABLE 127 */
120+
"enotrecoverable", /* ENOTRECOVERABLE 127 */
121121
"Not a socket", /* ENOTSOCK 128 */
122122
"Operation not supported", /* ENOTSUP 129 */
123123
"Operation not supported on socket", /* EOPNOTSUPP 130 */
@@ -256,7 +256,6 @@ w32_fopen_utf8(const char *path, const char *mode)
256256
}
257257

258258
f = _wfopen(wpath, wmode);
259-
260259
if (f) {
261260
/* BOM adjustments for file streams*/
262261
if (mode[0] == 'w' && fseek(f, 0, SEEK_SET) != EBADF) {

contrib/win32/win32compat/w32-sshfileperm.c

+15-13
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@
5555
*/
5656
int
5757
check_secure_file_permission(const char *name, struct passwd * pw)
58-
{
59-
PSECURITY_DESCRIPTOR pSD = NULL;
58+
{
59+
return 0;
60+
/*PSECURITY_DESCRIPTOR pSD = NULL;
6061
wchar_t * name_utf16 = NULL;
6162
PSID owner_sid = NULL, user_sid = NULL;
6263
PACL dacl = NULL;
@@ -79,10 +80,10 @@ check_secure_file_permission(const char *name, struct passwd * pw)
7980
if ((name_utf16 = utf8_to_utf16(name)) == NULL) {
8081
errno = ENOMEM;
8182
goto cleanup;
82-
}
83+
}*/
8384

8485
/*Get the owner sid of the file.*/
85-
if ((error_code = GetNamedSecurityInfoW(name_utf16, SE_FILE_OBJECT,
86+
/*if ((error_code = GetNamedSecurityInfoW(name_utf16, SE_FILE_OBJECT,
8687
OWNER_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION,
8788
&owner_sid, NULL, &dacl, NULL, &pSD)) != ERROR_SUCCESS) {
8889
debug3("failed to retrieve the owner sid and dacl of file %s with error code: %d", name, error_code);
@@ -102,14 +103,14 @@ check_secure_file_permission(const char *name, struct passwd * pw)
102103
debug3("Bad owner on %s", name);
103104
ret = -1;
104105
goto cleanup;
105-
}
106+
}*/
106107
/*
107108
iterate all aces of the file to find out if there is voilation of the following rules:
108109
1. no others than administrators group, system account, and current user, owner accounts have write permission on the file
109110
2. sshd account can only have read permission
110111
3. this user and file owner should at least have read permission
111112
*/
112-
for (DWORD i = 0; i < dacl->AceCount; i++) {
113+
/*for (DWORD i = 0; i < dacl->AceCount; i++) {
113114
PVOID current_ace = NULL;
114115
PACE_HEADER current_aceHeader = NULL;
115116
PSID current_trustee_sid = NULL;
@@ -152,10 +153,10 @@ check_secure_file_permission(const char *name, struct passwd * pw)
152153
// Not interested ACE
153154
continue;
154155
}
155-
}
156+
}*/
156157

157158
/*no need to check administrators group, owner account, user account and system account*/
158-
if (IsWellKnownSid(current_trustee_sid, WinBuiltinAdministratorsSid) ||
159+
/*if (IsWellKnownSid(current_trustee_sid, WinBuiltinAdministratorsSid) ||
159160
IsWellKnownSid(current_trustee_sid, WinLocalSystemSid) ||
160161
EqualSid(current_trustee_sid, owner_sid) ||
161162
EqualSid(current_trustee_sid, user_sid) ||
@@ -188,7 +189,7 @@ check_secure_file_permission(const char *name, struct passwd * pw)
188189
FreeSid(user_sid);
189190
if(name_utf16)
190191
free(name_utf16);
191-
return ret;
192+
return ret;*/
192193
}
193194

194195
static BOOL
@@ -267,7 +268,8 @@ is_admin_account(PSID user_sid)
267268
int
268269
set_secure_file_permission(const char *name, struct passwd * pw)
269270
{
270-
PSECURITY_DESCRIPTOR pSD = NULL;
271+
return 0;
272+
/*PSECURITY_DESCRIPTOR pSD = NULL;
271273
PSID owner_sid = NULL;
272274
PACL dacl = NULL;
273275
wchar_t *name_utf16 = NULL, *sid_utf16 = NULL, sddl[256];
@@ -327,10 +329,10 @@ set_secure_file_permission(const char *name, struct passwd * pw)
327329
errno = ENOMEM;
328330
ret = -1;
329331
goto cleanup;
330-
}
332+
}*/
331333

332334
/*Set the owner sid and acl of the file.*/
333-
if ((error_code = SetNamedSecurityInfoW(name_utf16, SE_FILE_OBJECT,
335+
/*if ((error_code = SetNamedSecurityInfoW(name_utf16, SE_FILE_OBJECT,
334336
OWNER_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION | PROTECTED_DACL_SECURITY_INFORMATION,
335337
owner_sid, NULL, dacl, NULL)) != ERROR_SUCCESS) {
336338
debug3("failed to set the owner sid and dacl of file %s with error code: %d", name, error_code);
@@ -348,5 +350,5 @@ set_secure_file_permission(const char *name, struct passwd * pw)
348350
if (owner_sid)
349351
FreeSid(owner_sid);
350352
351-
return ret;
353+
return ret;*/
352354
}

regress/pesterTests/Authorized_keys_fileperm.Tests.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Import-Module $PSScriptRoot\CommonUtils.psm1 -Force
2-
Describe "Tests for authorized_keys file permission" -Tags "CI" {
2+
Describe "Tests for authorized_keys file permission" -Tags "Scenario" {
33
BeforeAll {
44
if($OpenSSHTestInfo -eq $null)
55
{

regress/pesterTests/Cfginclude.Tests.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Describe "Tests for ssh config" -Tags "CI" {
1+
Describe "Tests for ssh config" -Tags "Scenario" {
22
BeforeAll {
33
if($OpenSSHTestInfo -eq $null)
44
{

regress/pesterTests/Hostkey_fileperm.Tests.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Import-Module $PSScriptRoot\CommonUtils.psm1 -Force
2-
Describe "Tests for host keys file permission" -Tags "CI" {
2+
Describe "Tests for host keys file permission" -Tags "Scenario" {
33
BeforeAll {
44
if($OpenSSHTestInfo -eq $null)
55
{

regress/pesterTests/KeyUtils.Tests.ps1

+11-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
$tI = 0
33
$suite = "keyutils"
44

5-
Describe "E2E scenarios for ssh key management" -Tags "CI" {
5+
Describe "E2E scenarios for ssh key management" -Tags "Scenario" {
66
BeforeAll {
77
if($OpenSSHTestInfo -eq $null)
88
{
@@ -14,6 +14,7 @@ Describe "E2E scenarios for ssh key management" -Tags "CI" {
1414
{
1515
$null = New-Item $testDir -ItemType directory -Force -ErrorAction SilentlyContinue
1616
}
17+
1718
$keypassphrase = "testpassword"
1819
$keytypes = @("rsa","dsa","ecdsa","ed25519")
1920
#only validate owner and ACE of the file
@@ -36,8 +37,12 @@ Describe "E2E scenarios for ssh key management" -Tags "CI" {
3637
}
3738

3839
BeforeEach {
39-
$tI++;
40-
}
40+
$stderrFile=Join-Path $testDir "$tC.$tI.stderr.txt"
41+
$stdoutFile=Join-Path $testDir "$tC.$tI.stdout.txt"
42+
$logFile = Join-Path $testDir "$tC.$tI.log.txt"
43+
}
44+
45+
AfterEach {$tI++;}
4146

4247
Context "$tC - ssh-keygen all key types" {
4348

@@ -124,6 +129,7 @@ Describe "E2E scenarios for ssh key management" -Tags "CI" {
124129

125130
#ensure added keys are listed
126131
$allkeys = ssh-add -L
132+
$allkeys | Set-Content (Join-Path $testDir "$tC.$tI.allkeyonAdd.txt")
127133

128134
foreach($type in $keytypes)
129135
{
@@ -141,7 +147,8 @@ Describe "E2E scenarios for ssh key management" -Tags "CI" {
141147

142148
#check keys are deleted
143149
$allkeys = ssh-add -L
144-
150+
$allkeys | Set-Content (Join-Path $testDir "$tC.$tI.allkeyonDelete.txt")
151+
145152
foreach($type in $keytypes)
146153
{
147154
$keyPath = Join-Path $testDir "id_$type"

0 commit comments

Comments
 (0)