From 6aa5b815c2f718f5d2f295e917a6f17cfc96536a Mon Sep 17 00:00:00 2001 From: Manoj Ampalam Date: Mon, 19 Dec 2016 14:48:14 -0800 Subject: [PATCH] To be cleaned sources from Win32 Fork --- .gitignore | 286 ++++++++ appveyor.yml | 43 ++ contrib/win32/openssh/AnalyzeCodeDiff.ps1 | 200 ++++++ .../win32/openssh/OpenSSL-1.0.2d_build.cmd | 45 ++ contrib/win32/openssh/appveyor.psm1 | 619 +++++++++++++++++ contrib/win32/openssh/build.psm1 | 383 +++++++++++ contrib/win32/openssh/unittest-bitmap.vcxproj | 214 ++++++ .../win32/openssh/unittest-hostkeys.vcxproj | 221 +++++++ contrib/win32/openssh/unittest-kex.vcxproj | 210 ++++++ contrib/win32/openssh/unittest-sshbuf.vcxproj | 220 ++++++ contrib/win32/openssh/unittest-sshkey.vcxproj | 225 +++++++ contrib/win32/openssh/unittest-utf8.vcxproj | 208 ++++++ .../openssh/unittest-win32compat.vcxproj | 210 ++++++ contrib/win32/openssh/win32iocompat.vcxproj | 205 ++++++ .../openssh/win32iocompat.vcxproj.filters | 135 ++++ openbsd-compat/bsd-misc.c | 2 + openbsd-compat/bsd-misc.h | 2 + regress/netcat.c | 25 +- .../pesterTests/PlatformAbstractLayer.psm1 | 361 ++++++++++ regress/pesterTests/PortForwarding.Tests.ps1 | 56 ++ regress/pesterTests/PowerShell.SSH.Tests.ps1 | 83 +++ regress/pesterTests/SCP.Tests.ps1 | 214 ++++++ regress/pesterTests/SSH.Tests.ps1 | 139 ++++ regress/setuid-allowed.c | 4 + regress/unittests/hostkeys/test_iterate.c | 11 +- regress/unittests/kex/test_kex.c | 4 + regress/unittests/sshbuf/tests.c | 4 + regress/unittests/sshkey/common.c | 5 +- regress/unittests/sshkey/test_file.c | 17 +- regress/unittests/sshkey/test_fuzz.c | 12 +- regress/unittests/sshkey/test_sshkey.c | 17 +- regress/unittests/sshkey/tests.c | 3 +- regress/unittests/test_helper/test_helper.c | 6 + regress/unittests/utf8/tests.c | 14 +- regress/unittests/win32compat/file_tests.c | 250 +++++++ regress/unittests/win32compat/socket_tests.c | 624 ++++++++++++++++++ regress/unittests/win32compat/tests.c | 24 + 37 files changed, 5274 insertions(+), 27 deletions(-) create mode 100644 .gitignore create mode 100644 appveyor.yml create mode 100644 contrib/win32/openssh/AnalyzeCodeDiff.ps1 create mode 100644 contrib/win32/openssh/OpenSSL-1.0.2d_build.cmd create mode 100644 contrib/win32/openssh/appveyor.psm1 create mode 100644 contrib/win32/openssh/build.psm1 create mode 100644 contrib/win32/openssh/unittest-bitmap.vcxproj create mode 100644 contrib/win32/openssh/unittest-hostkeys.vcxproj create mode 100644 contrib/win32/openssh/unittest-kex.vcxproj create mode 100644 contrib/win32/openssh/unittest-sshbuf.vcxproj create mode 100644 contrib/win32/openssh/unittest-sshkey.vcxproj create mode 100644 contrib/win32/openssh/unittest-utf8.vcxproj create mode 100644 contrib/win32/openssh/unittest-win32compat.vcxproj create mode 100644 contrib/win32/openssh/win32iocompat.vcxproj create mode 100644 contrib/win32/openssh/win32iocompat.vcxproj.filters create mode 100644 regress/pesterTests/PlatformAbstractLayer.psm1 create mode 100644 regress/pesterTests/PortForwarding.Tests.ps1 create mode 100644 regress/pesterTests/PowerShell.SSH.Tests.ps1 create mode 100644 regress/pesterTests/SCP.Tests.ps1 create mode 100644 regress/pesterTests/SSH.Tests.ps1 create mode 100644 regress/unittests/win32compat/file_tests.c create mode 100644 regress/unittests/win32compat/socket_tests.c create mode 100644 regress/unittests/win32compat/tests.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..1e9a2cc22 --- /dev/null +++ b/.gitignore @@ -0,0 +1,286 @@ +################################################################################ +# This .gitignore file was automatically created by Microsoft(R) Visual Studio. +################################################################################ + +/bin/x64/Debug +/contrib/win32/openssh/.vs/Win32-OpenSSH/v14 +/contrib/win32/openssh/lib +/contrib/win32/openssh/Win32/Debug/config/config.tlog +/contrib/win32/openssh/Win32/Debug/libssh/libssh.tlog +/contrib/win32/openssh/Win32/Debug/libssh +/config.h + +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +project.fragment.lock.json +artifacts/ +Properties/launchSettings.json + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc +*.c.bak +*.h.bak + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/ \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 000000000..727d98c39 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,43 @@ +version: 0.0.4.0.{build} +image: Visual Studio 2015 + +branches: + only: + - V_7_3w + - latestw_cwb + +init: + - ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) + +build_script: + - ps: | + Import-Module $env:APPVEYOR_BUILD_FOLDER\contrib\win32\openssh\AppVeyor.psm1 + Invoke-AppVeyorBuild + +after_build: + - ps: | + Import-Module $env:APPVEYOR_BUILD_FOLDER\contrib\win32\openssh\AppVeyor.psm1 + Install-OpenSSH + - ps: Write-Verbose "Restart computer ..." + - ps: Restart-Computer -ComputerName localhost -Force + - ps: Start-Sleep -s 5 # Needs to be proceeded with -ps: as it's interpreted by AppVeyor + - ps: Write-Verbose "Restart computer completed" + +before_test: + - ps: | + Import-Module $env:APPVEYOR_BUILD_FOLDER\contrib\win32\openssh\AppVeyor.psm1 + Install-TestDependencies + +test_script: + - cmd: | + "%ProgramFiles%\PowerShell\6.0.0.12\powershell.exe" -Command "Import-Module \"%APPVEYOR_BUILD_FOLDER%\contrib\win32\openssh\AppVeyor.psm1\";Run-OpenSSHTests" + +after_test: + - ps: | + Import-Module $env:APPVEYOR_BUILD_FOLDER\contrib\win32\openssh\AppVeyor.psm1 + Upload-OpenSSHTestResults + +on_finish: + - ps: | + Import-Module $env:APPVEYOR_BUILD_FOLDER\contrib\win32\openssh\AppVeyor.psm1 + Publish-Artifact diff --git a/contrib/win32/openssh/AnalyzeCodeDiff.ps1 b/contrib/win32/openssh/AnalyzeCodeDiff.ps1 new file mode 100644 index 000000000..a4b4953be --- /dev/null +++ b/contrib/win32/openssh/AnalyzeCodeDiff.ps1 @@ -0,0 +1,200 @@ +Set-StrictMode -Version Latest +$Win32Macro = 'WIN32_FIXME' +$sourceRoot = 'C:\openssh\Win32-OpenSSH' + +[int]$g_code = 0 +[int]$g_win32 = 0 +[int]$g_unix = 0 + +function AnalyzeFile($file, [bool]$log) +{ + $file = Join-Path $sourceRoot $file + if ($log) { Write-Host -ForegroundColor Gray $file } + $content = Get-Content $file + [int]$commentlines = 0 #comments + [int]$emptylines = 0 #emptylines + [int]$code = 0 #all code lines + [int]$win32 = 0 #win32 only lines + [int]$win32substituted = 0#lines in win32 block that have a corresponding Unix block (#ifdef with #else) + [int]$unix = 0; #unix only lines + [int]$unixsubstituted = 0 #lines in unix block that have a corresponding Win32 block (#ifdef with #else) + [int]$total = 0 + [int]$nestedmacros = 0 #tracks nested macro blocks inside a win32 or a unix block + [bool]$incommentblock = $false + [bool]$inWin32block = $false + [bool]$inUnixblock = $false + [int]$currentblockcode = 0 + [bool]$insubstitutedblock = $false + + + foreach ($linestr in $content) + { + $total++ + $line = [String]$linestr + $line = $line.Trim() + #skip if line is empty + if ($line.Length -gt 0) + { + if ($incommentblock) + { + $commentlines++ + if ($line.EndsWith('*/')) {$incommentblock = $false} + } + else + { + if ($line.StartsWith('//')) {$commentlines++} + elseif ($line.StartsWith('/*')) + { + if (!($line.EndsWith('*/'))) { $incommentblock = $true } + $commentlines++ + } + else + { + $code++ + if ($inWin32block) + { + $win32++ + $currentblockcode++ + #keep skipping inner #ifdefs + if ($line.StartsWith('#ifdef')) {$nestedmacros++} + + if ($line.EndsWith('#endif') -or $line.EndsWith('#else')) + { + if ($nestedmacros -eq 0) + { + $inWin32block = $false + if ($line.EndsWith('#else')) + { + $inUnixblock = $true + $insubstitutedblock = $true + $win32substituted += $currentblockcode + } + elseif ($insubstitutedblock) + { + $win32substituted += $currentblockcode + $insubstitutedblock = $false + } + $currentblockcode = 0 + } + else + { + if ($line.EndsWith('#endif')) {$nestedmacros--} + } + } + } + elseif ($inUnixblock) + { + $unix++ + $currentblockcode++ + #keep skipping inner #ifdefs + if ($line.StartsWith('#ifdef')) {$nestedmacros++} + + if ($line.EndsWith('#endif') -or $line.EndsWith('#else')) + { + if ($nestedmacros -eq 0) + { + $inUnixblock = $false + if ($line.EndsWith('#else')) + { + $inWin32block = $true + $insubstitutedblock = $true + $unixsubstituted += $currentblockcode + } + elseif ($insubstitutedblock) + { + $unixsubstituted += $currentblockcode + $insubstitutedblock = $false + } + + $currentblockcode = 0 + } + else + { + if ($line.EndsWith('#endif')) {$nestedmacros--} + } + } + } + else + { + if ($line.StartsWith('#ifdef') -and $line.Contains($Win32Macro)) + { + $inWin32block = $true + $currentblockcode = 0 + } + if ($line.StartsWith('#ifndef') -and $line.Contains($Win32Macro)) + { + $inUnixblock = $true + $currentblockcode = 0; + } + } + + } + } + } + else {$emptylines++} + } + + if ($log) + { + Write-Host -ForegroundColor Yellow " Comments " $commentlines + Write-Host -ForegroundColor Green " Blank " $emptylines + Write-Host -ForegroundColor Cyan " Code " $code + Write-Host -ForegroundColor DarkMagenta " Total " $total " check("($commentlines+$emptylines+$code)")" + Write-Host -ForegroundColor Cyan " Win32 " $win32 + Write-Host -ForegroundColor Cyan " Unix " $unix + Write-Host -ForegroundColor Cyan " Win32sub " $win32substituted + Write-Host -ForegroundColor Cyan " Unixsub " $unixsubstituted + } + + $global:g_code += $code + $global:g_win32 += $win32 + $global:g_unix += $unix + +} + + +function AnalyzeProject($project, [bool]$log) +{ + if ($log) { Write-Host "Project: " $project} + $projectName = $project + $projectroot = Join-Path $sourceRoot 'contrib\win32\openssh' + $project = Join-Path $projectroot $project + $project = $project + '.vcxproj' + + $global:g_code = 0 + $global:g_win32 = 0 + $global:g_unix = 0 + + $c = Get-Content $project + foreach ($ln in $c){ + $l = [String]$ln + $l = $l.Trim() + + if ($l.StartsWith(' +function Invoke-MSIEXEC +{ + [CmdletBinding()] + param( + [Parameter(Mandatory=$true)] + [string] $InstallFile + ) + + Write-Verbose "Installing $InstallFile..." + $arguments = @( + "/i" + "`"$InstallFile`"" + "/qn" + "/norestart" + ) + $process = Start-Process -FilePath msiexec.exe -ArgumentList $arguments -Wait -PassThru + if ($process.ExitCode -eq 0){ + Write-Output "$InstallFile has been successfully installed" + } + else { + Write-Output "installer exit code $($process.ExitCode) for file $($InstallFile)" + } + + return $process.ExitCode +} + +<# + .Synopsis + This function installs PSCore MSI on the AppVeyor build machine +#> +function Install-PSCoreFromGithub +{ + $downloadLocation = Download-PSCoreMSI + + Write-Output "Installing PSCore ..." + if(-not [string]::IsNullOrEmpty($downloadLocation)) + { + $processExitCode = Invoke-MSIEXEC -InstallFile $downloadLocation + Write-Output "Process exitcode: $processExitCode" + } +} + +<# + .Synopsis + Retuns MSI location for PSCore for Win10, Windows 8.1 and 2012 R2 +#> +function Get-PSCoreMSIDownloadURL +{ + $osversion = [String][Environment]::OSVersion.Version + Write-Host "osversion:$osversion" + if($osversion.StartsWith("6")) + { + if ($($env:PROCESSOR_ARCHITECTURE).Contains('64')) + { + return 'https://github.com/PowerShell/PowerShell/releases/download/v6.0.0-alpha.12/PowerShell_6.0.0.12-alpha.12-win81-x64.msi' + } + else + { + return '' + } + } + elseif ($osversion.Contains("10.0")) + { + if ($($env:PROCESSOR_ARCHITECTURE).Contains('64')) + { + return 'https://github.com/PowerShell/PowerShell/releases/download/v6.0.0-alpha.12/PowerShell_6.0.0.12-alpha.12-win10-x64.msi' + } + else + { + return '' + } + } +} + +<# + .Synopsis + This functions downloads MSI and returns the path where the file is downloaded. +#> +function Download-PSCoreMSI +{ + $url = Get-PSCoreMSIDownloadURL + if([string]::IsNullOrEmpty($url)) + { + Write-Output "url is empty" + return '' + } + $parsed = $url.Substring($url.LastIndexOf("/") + 1) + if(-not (Test-path "$env:SystemDrive\PScore" -PathType Container)) + { + New-Item -ItemType Directory -Force -Path "$env:SystemDrive\PScore" | out-null + } + $downloadLocation = "$env:SystemDrive\PScore\$parsed" + if(-not (Test-path $downloadLocation -PathType Leaf)) + { + Invoke-WebRequest -Uri $url -OutFile $downloadLocation -ErrorVariable v + } + + if ($v) + { + throw "Failed to download PSCore MSI package from $url" + } + else + { + return $downloadLocation + } +} + +<# + .SYNOPSIS + This function installs the tools required by our tests + 1) Pester for running the tests + 2) sysinternals required by the tests on windows. + #> +function Install-TestDependencies +{ + [CmdletBinding()] + param () + + $isModuleAvailable = Get-Module 'Pester' -ListAvailable + if (-not ($isModuleAvailable)) + { + Write-Output 'Installing Pester...' + choco install Pester -y --force + } + + if ( -not (Test-Path "$env:ProgramData\chocolatey\lib\sysinternals\tools" ) ) { + Write-Output "sysinternals not present. Installing sysinternals." + choco install sysinternals -y + } + Write-Output "Installing pscore..." + Install-PSCoreFromGithub +} +<# + .Synopsis + Deploy all required files to a location and install the binaries +#> +function Install-OpenSSH +{ + [CmdletBinding()] + param + ( + [string] $OpenSSHDir = "$env:SystemDrive\OpenSSH", + + [ValidateSet('Debug', 'Release')] + [string]$Configuration = "Debug", + + [ValidateSet('x86', 'x64', '')] + [string]$NativeHostArch = "" + ) + + Build-Win32OpenSSHPackage @PSBoundParameters + + Push-Location $OpenSSHDir + &( "$OpenSSHDir\install-sshd.ps1") + .\ssh-keygen.exe -A + Start-Service ssh-agent + &( "$OpenSSHDir\install-sshlsa.ps1") + + Set-Service sshd -StartupType Automatic + Set-Service ssh-agent -StartupType Automatic + Start-Service sshd + + Pop-Location +} + +<# + .Synopsis + uninstalled sshd and sshla +#> +function UnInstall-OpenSSH +{ + [CmdletBinding()] + param + ( + [string] $OpenSSHDir = "$env:SystemDrive\OpenSSH" + ) + + Push-Location $OpenSSHDir + + Stop-Service sshd + &( "$OpenSSHDir\uninstall-sshd.ps1") + &( "$OpenSSHDir\uninstall-sshlsa.ps1") + Pop-Location +} + +<# + .Synopsis + Deploy all required files to build a package and create zip file. +#> +function Build-Win32OpenSSHPackage +{ + [CmdletBinding()] + param + ( + [string] $OpenSSHDir = "$env:SystemDrive\OpenSSH", + + [ValidateSet('Debug', 'Release')] + [string]$Configuration = "Debug", + + [ValidateSet('x86', 'x64', '')] + [string]$NativeHostArch = "" + ) + + if (-not (Test-Path -Path $OpenSSHDir -PathType Container)) + { + New-Item -Path $OpenSSHDir -ItemType Directory -Force -ErrorAction Stop + } + + [string] $platform = $env:PROCESSOR_ARCHITECTURE + if(-not [String]::IsNullOrEmpty($NativeHostArch)) + { + $folderName = $NativeHostArch + if($NativeHostArch -eq 'x86') + { + $folderName = "Win32" + } + } + else + { + if($platform -ieq "AMD64") + { + $folderName = "x64" + } + else + { + $folderName = "Win32" + } + } + + [System.IO.DirectoryInfo] $repositoryRoot = Get-RepositoryRoot + $sourceDir = Join-Path $repositoryRoot.FullName -ChildPath "bin\$folderName\$Configuration" + Copy-Item -Path "$sourceDir\*" -Destination $OpenSSHDir -Include *.exe,*.dll -Exclude *unittest*.* -Force -ErrorAction Stop + $sourceDir = Join-Path $repositoryRoot.FullName -ChildPath "contrib\win32\openssh" + Copy-Item -Path "$sourceDir\*" -Destination $OpenSSHDir -Include *.ps1,sshd_config -Exclude AnalyzeCodeDiff.ps1 -Force -ErrorAction Stop + + $packageName = "rktools.2003" + $rktoolsPath = "${env:ProgramFiles(x86)}\Windows Resource Kits\Tools\ntrights.exe" + if (-not (Test-Path -Path $rktoolsPath)) + { + Write-Information -MessageData "$packageName not present. Installing $packageName." + choco install $packageName -y --force + } + + Copy-Item -Path $rktoolsPath -Destination $OpenSSHDir -Force -ErrorAction Stop + + $packageFolder = $env:SystemDrive + if ($env:APPVEYOR_BUILD_FOLDER) + { + $packageFolder = $env:APPVEYOR_BUILD_FOLDER + } + + $package = "$packageFolder\Win32OpenSSH$Configuration$folderName.zip" + $allPackage = "$packageFolder\Win32OpenSSH*.zip" + if (Test-Path $allPackage) + { + Remove-Item -Path $allPackage -Force -ErrorAction SilentlyContinue + } + + Add-Type -assemblyname System.IO.Compression.FileSystem + [System.IO.Compression.ZipFile]::CreateFromDirectory($OpenSSHDir, $package) +} + +<# + .Synopsis + After build and test run completes, upload all artifacts from the build machine. +#> +function Deploy-OpenSSHTests +{ + [CmdletBinding()] + param + ( + [string] $OpenSSHTestDir = "$env:SystemDrive\OpenSSH", + + [ValidateSet('Debug', 'Release')] + [string]$Configuration = "Debug", + + [ValidateSet('x86', 'x64', '')] + [string]$NativeHostArch = "" + ) + + if (-not (Test-Path -Path $OpenSSHTestDir -PathType Container)) + { + New-Item -Path $OpenSSHTestDir -ItemType Directory -Force -ErrorAction Stop + } + + [string] $platform = $env:PROCESSOR_ARCHITECTURE + if(-not [String]::IsNullOrEmpty($NativeHostArch)) + { + $folderName = $NativeHostArch + if($NativeHostArch -eq 'x86') + { + $folderName = "Win32" + } + } + else + { + if($platform -ieq "AMD64") + { + $folderName = "x64" + } + else + { + $folderName = "Win32" + } + } + + + [System.IO.DirectoryInfo] $repositoryRoot = Get-RepositoryRoot + + $sourceDir = Join-Path $repositoryRoot.FullName -ChildPath "regress\pesterTests" + Copy-Item -Path "$sourceDir\*" -Destination $OpenSSHTestDir -Include *.ps1,*.psm1 -Force -ErrorAction Stop + + $sourceDir = Join-Path $repositoryRoot.FullName -ChildPath "bin\$folderName\$Configuration" + Copy-Item -Path "$sourceDir\*" -Destination $OpenSSHTestDir -Exclude ssh-agent.exe, sshd.exe -Force -ErrorAction Stop + +} + + +<# + .Synopsis + Adds a build log to the list of published artifacts. + .Description + If a build log exists, it is renamed to reflect the associated CLR runtime then added to the list of + artifacts to publish. If it doesn't exist, a warning is written and the file is skipped. + The rename is needed since publishing overwrites the artifact if it already exists. + .Parameter artifacts + An array list to add the fully qualified build log path + .Parameter buildLog + The build log file produced by the build. +#> +function Add-BuildLog +{ + param + ( + [ValidateNotNull()] + [System.Collections.ArrayList] $artifacts, + + [Parameter(Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [string] $buildLog + ) + + if (Test-Path -Path $buildLog) + { + Write-Output "Adding $buildLog to local artifacts" + $null = $artifacts.Add($buildLog) + Write-Output "Adding $buildLog to local artifacts- completed" + } + else + { + Write-Warning "Skip publishing build log. $buildLog does not exist" + } +} + +<# + .Synopsis + Publishes package build artifacts. + .Parameter artifacts + An array list to add the fully qualified build log path + .Parameter packageFile + Path to the package +#> +function Add-Artifact +{ + param + ( + [ValidateNotNull()] + [System.Collections.ArrayList] $artifacts, + [string] $FileToAdd = "$env:SystemDrive\Win32OpenSSH*.zip" + ) + + $files = Get-ChildItem -Path $FileToAdd -ErrorAction Ignore + if ($files -ne $null) + { + + $files | % { + Write-Output "Adding $($_.FullName) to local artifacts" + $null = $artifacts.Add($_.FullName) + Write-Output "Adding $($_.FullName) to local artifacts- completed" + } + + } + else + { + Write-Warning "Skip publishing package artifacts. $FileToAdd does not exist" + } +} + +<# + .Synopsis + After build and test run completes, upload all artifacts from the build machine. +#> +function Publish-Artifact +{ + Write-Output "Publishing project artifacts" + [System.Collections.ArrayList] $artifacts = [System.Collections.ArrayList]::new() + + $packageFolder = $env:SystemDrive + if ($env:APPVEYOR_BUILD_FOLDER) + { + $packageFolder = $env:APPVEYOR_BUILD_FOLDER + } + + Add-Artifact -artifacts $artifacts -FileToAdd "$packageFolder\Win32OpenSSH*.zip" + Add-Artifact -artifacts $artifacts -FileToAdd "$packageFolder\OpenSSH\UnitTestResults.txt" + + # Get the build.log file for each build configuration + #Add-BuildLog -artifacts $artifacts -buildLog (Get-BuildLogFile -root $repoRoot.FullName -Configuration Release -NativeHostArch x86) + #Add-BuildLog -artifacts $artifacts -buildLog (Get-BuildLogFile -root $repoRoot.FullName -Configuration Debug -NativeHostArch x86) + #Add-BuildLog -artifacts $artifacts -buildLog (Get-BuildLogFile -root $repoRoot.FullName -Configuration Release -NativeHostArch x64) + Add-BuildLog -artifacts $artifacts -buildLog (Get-BuildLogFile -root $repoRoot.FullName -Configuration Debug -NativeHostArch x64) + + foreach ($artifact in $artifacts) + { + Write-Output "Publishing $artifact as Appveyor artifact" + # NOTE: attempt to publish subsequent artifacts even if the current one fails + Push-AppveyorArtifact $artifact -ErrorAction "Continue" + } +} + +<# + .Synopsis + Run OpenSSH pester tests. +#> +function Run-OpenSSHPesterTest +{ + param($testRoot, $outputXml) + + # Discover all CI tests and run them. + Push-Location $testRoot + Write-Output "Running OpenSSH Pester tests..." + $testFolders = Get-ChildItem *.tests.ps1 -Recurse | ForEach-Object{ Split-Path $_.FullName} | Sort-Object -Unique + + Invoke-Pester $testFolders -OutputFormat NUnitXml -OutputFile $outputXml -Tag 'CI' + Pop-Location +} + +<# + .Synopsis + Run unit tests. +#> +function Run-OpenSSHUnitTest +{ + param($testRoot, $unitTestOutputFile) + + # Discover all CI tests and run them. + Push-Location $testRoot + Write-Output "Running OpenSSH unit tests..." + if (Test-Path $unitTestOutputFile) + { + Remove-Item -Path $unitTestOutputFile -Force -ErrorAction SilentlyContinue + } + + $unitTestFiles = Get-ChildItem -Path "$testRoot\unittest*.exe" + $testFailed = $false + if ($unitTestFiles -ne $null) + { + $unitTestFiles | % { + Write-Output "Running OpenSSH unit $($_.FullName)..." + & $_.FullName >> $unitTestOutputFile + $errorCode = $LASTEXITCODE + if ($errorCode -ne 0) + { + $testFailed = $true + Write-Output "$($_.FullName) test failed for OpenSSH.`nExitCode: $error" + } + } + + if($testFailed) + { + throw "SSH unit tests failed" + } + } + + Pop-Location +} + +<# + .Synopsis + Runs the tests for this repo + + .Parameter testResultsFile + The name of the xml file to write pester results. + The default value is '.\testResults.xml' + + .Parameter uploadResults + Uploads the tests results. + + .Example + .\RunTests.ps1 + Runs the tests and creates the default 'testResults.xml' + + .Example + .\RunTests.ps1 -uploadResults + Runs the tests and creates teh default 'testResults.xml' and uploads it to appveyor. + + #> +function Run-OpenSSHTests +{ + [CmdletBinding()] + param + ( + [string] $testResultsFile = "$env:SystemDrive\OpenSSH\TestResults.xml", + [string] $unitTestResultsFile = "$env:SystemDrive\OpenSSH\UnitTestResults.txt", + [string] $testInstallFolder = "$env:SystemDrive\OpenSSH" + ) + + Deploy-OpenSSHTests -OpenSSHTestDir $testInstallFolder + + # Run all pester tests. + Run-OpenSSHPesterTest -testRoot $testInstallFolder -outputXml $testResultsFile + + $xml = [xml](Get-Content -raw $testResultsFile) + if ([int]$xml.'test-results'.failures -gt 0) + { + throw "$($xml.'test-results'.failures) tests in regress\pesterTests failed" + } + + # Writing out warning when the $Error.Count is non-zero. Tests Should clean $Error after success. + if ($Error.Count -gt 0) + { + $Error| Out-File "$env:SystemDrive\OpenSSH\TestError.txt" -Append + } + + Run-OpenSSHUnitTest -testRoot $testInstallFolder -unitTestOutputFile $unitTestResultsFile +} + +function Upload-OpenSSHTestResults +{ + [CmdletBinding()] + param + ( + [string] $testResultsFile = "$env:SystemDrive\OpenSSH\TestResults.xml" + ) + + if ($env:APPVEYOR_JOB_ID) + { + (New-Object 'System.Net.WebClient').UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path $testResultsFile)) + } + +} diff --git a/contrib/win32/openssh/build.psm1 b/contrib/win32/openssh/build.psm1 new file mode 100644 index 000000000..0eeff8f62 --- /dev/null +++ b/contrib/win32/openssh/build.psm1 @@ -0,0 +1,383 @@ + +Set-StrictMode -Version Latest +[string] $script:platform = $env:PROCESSOR_ARCHITECTURE +[string] $script:vcPath = $null +[System.IO.DirectoryInfo] $script:OpenSSHRoot = $null +[bool] $script:Verbose = $false +[string] $script:BuildLogFile = $null + +<# + Called by Write-BuildMsg to write to the build log, if it exists. +#> +function Write-Log +{ + param + ( + [Parameter(Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [string] $Message + ) + # write it to the log file, if present. + if (-not ([string]::IsNullOrEmpty($script:BuildLogFile))) + { + Add-Content -Path $script:BuildLogFile -Value $Message + } +} + +<# +.Synopsis + Writes a build message. +.Parameter Message + The message to write. +.Parameter AsInfo + Writes a user message using Write-Information. +.Parameter AsVerbose + Writes a message using Write-Verbose and to the build log if -Verbose was specified to Start-DscBuild. +.Parameter AsWarning + Writes a message using Write-Warning and to the build log. +.Parameter AsError + Writes a message using Write-Error and to the build log. +.Parameter Silent + Writes the message only to the log. +.Parameter ErrorAction + Determines if the script is terminated when errors are written. + This parameter is ignored when -Silent is specified. +.Example + Write-BuildMsg -AsInfo 'Starting the build' + Writes an informational message to the log and to the user +.Example + Write-BuildMsg -AsError 'Terminating build' -Silent + Writes an error message only to the log +.Example + Write-BuildMsg -AsError 'Terminating build' -ErrorAction Stop + Writes an error message to the log and the user and terminates the build. +.Example + Write-BuildMsg -AsInfo 'Nuget is already installed' -Silent:(-not $script:Verbose) + Writes an informational message to the log. If -Verbose was specified, also + writes to message to the user. +#> +function Write-BuildMsg +{ + [CmdletBinding()] + param + ( + [Parameter(Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [string] $Message, + + [Parameter(ParameterSetName='Info')] + [switch] $AsInfo, + + [Parameter(ParameterSetName='Verbose')] + [switch] $AsVerbose, + + [Parameter(ParameterSetName='Warning')] + [switch] $AsWarning, + + [Parameter(ParameterSetName='Error')] + [switch] $AsError, + + [switch] $Silent + ) + + if ($AsVerbose) + { + if ($script:Verbose) + { + Write-Log -Message "VERBOSE: $message" + if (-not $Silent) + { + Write-Verbose -Message $message -Verbose + } + } + return + } + + if ($AsInfo) + { + Write-Log -Message "INFO: $message" + if (-not $Silent) + { + Write-Information -MessageData $message -InformationAction Continue + } + return + } + + if ($AsWarning) + { + Write-Log -Message "WARNING: $message" + if (-not $Silent) + { + Write-Warning -Message $message + } + return + } + + if ($AsError) + { + Write-Log -Message "ERROR: $message" + if (-not $Silent) + { + Write-Error -Message $message + } + return + } + + # if we reached here, no output type switch was specified. + Write-BuildMsg -AsError -ErrorAction Stop -Message 'Write-BuildMsg was called without selecting an output type.' +} + +<# +.Synopsis + Verifies all tools and dependencies required for building Open SSH are installed on the machine. +#> +function Start-SSHBootstrap +{ + Set-StrictMode -Version Latest + Write-BuildMsg -AsInfo -Message "Checking tools and dependencies" + + $machinePath = [Environment]::GetEnvironmentVariable('Path', 'MACHINE') + $newMachineEnvironmentPath = $machinePath + + # NOTE: Unless -Verbose is specified, most informational output will only go to the log file. + [bool] $silent = -not $script:Verbose + + # Install chocolatey + $chocolateyPath = "$env:AllUsersProfile\chocolatey\bin" + if(Get-Command "choco" -ErrorAction SilentlyContinue) + { + Write-BuildMsg -AsVerbose -Message "Chocolatey is already installed. Skipping installation." -Silent:$silent + } + else + { + Write-BuildMsg -AsInfo -Message "Chocolatey not present. Installing chocolatey." + Invoke-Expression ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1')) + + if (-not ($machinePath.ToLower().Contains($chocolateyPath.ToLower()))) + { + Write-BuildMsg -AsVerbose -Message "Adding $chocolateyPath to Path environment variable" + $newMachineEnvironmentPath += ";$chocolateyPath" + $env:Path += ";$chocolateyPath" + } + else + { + Write-BuildMsg -AsVerbose -Message "$chocolateyPath already present in Path environment variable" + } + } + + # Add git\cmd to the path + $gitCmdPath = "$env:ProgramFiles\git\cmd" + if (-not ($machinePath.ToLower().Contains($gitCmdPath.ToLower()))) + { + Write-BuildMsg -AsVerbose -Message "Adding $gitCmdPath to Path environment variable" + $newMachineEnvironmentPath = "$gitCmdPath;$newMachineEnvironmentPath" + } + else + { + Write-BuildMsg -AsVerbose -Message "$gitCmdPath already present in Path environment variable" -Silent:$silent + } + + $nativeMSBuildPath = "${env:ProgramFiles(x86)}\MSBuild\14.0\bin" + if($script:platform -ieq "AMD64") + { + $nativeMSBuildPath += "\amd64" + } + + if (-not ($machinePath.ToLower().Contains($nativeMSBuildPath.ToLower()))) + { + Write-BuildMsg -AsVerbose -Message "Adding $nativeMSBuildPath to Path environment variable" + $newMachineEnvironmentPath += ";$nativeMSBuildPath" + $env:Path += ";$nativeMSBuildPath" + } + else + { + Write-BuildMsg -AsVerbose -Message "$nativeMSBuildPath already present in Path environment variable" -Silent:$silent + } + + # Update machine environment path + if ($newMachineEnvironmentPath -ne $machinePath) + { + [Environment]::SetEnvironmentVariable('Path', $newMachineEnvironmentPath, 'MACHINE') + } + + # install nasm + $packageName = "nasm" + $nasmPath = "${env:ProgramFiles(x86)}\NASM" + + if (-not (Test-Path -Path $nasmPath -PathType Container)) + { + Write-BuildMsg -AsInfo -Message "$packageName not present. Installing $packageName." + choco install $packageName -y --force --execution-timeout 10000 + } + else + { + Write-BuildMsg -AsVerbose -Message "$packageName present. Skipping installation." -Silent:$silent + } + + # Install Visual Studio 2015 Community + $packageName = "VisualStudio2015Community" + $VSPackageInstalled = Get-ItemProperty "HKLM:\software\WOW6432Node\Microsoft\VisualStudio\14.0\setup\vs" -ErrorAction SilentlyContinue + + if ($null -eq $VSPackageInstalled) + { + Write-BuildMsg -AsInfo -Message "$packageName not present. Installing $packageName." + $adminFilePath = "$script:OpenSSHRoot\contrib\win32\openssh\VSWithBuildTools.xml" + choco install $packageName -packageParameters "--AdminFile $adminFilePath" -y --force --execution-timeout 10000 + } + else + { + Write-BuildMsg -AsVerbose -Message "$packageName present. Skipping installation." -Silent:$silent + } + + # Install Windows 8.1 SDK + $packageName = "windows-sdk-8.1" + $sdkPath = "C:\Program Files (x86)\Windows Kits\8.1\bin\x86\register_app.vbs" + + if (-not (Test-Path -Path $sdkPath)) + { + Write-BuildMsg -AsInfo -Message "Windows 8.1 SDK not present. Installing $packageName." + choco install $packageName -y --force + } + else + { + Write-BuildMsg -AsInfo -Message "$packageName present. Skipping installation." -Silent:$silent + } + + # Require restarting PowerShell session + if ($null -eq $VSPackageInstalled) + { + Write-Host "To apply changes, please close this PowerShell window, open a new one and call Start-SSHBuild or Start-DscBootstrap again." -ForegroundColor Black -BackgroundColor Yellow + Write-Host -NoNewLine 'Press any key to close this PowerShell window...' -ForegroundColor Black -BackgroundColor Yellow + $null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown') + exit + } + + # Ensure the VS C toolset is installed + if ($null -eq $env:VS140COMNTOOLS) + { + Write-BuildMsg -AsError -ErrorAction Stop -Message "Cannot find Visual Studio 2015 Environment variable VS140COMNTOOlS" + } + + $item = Get-Item(Join-Path -Path $env:VS140COMNTOOLS -ChildPath '../../vc') + + $script:vcPath = $item.FullName + Write-BuildMsg -AsVerbose -Message "vcPath: $script:vcPath" + if ((Test-Path -Path "$script:vcPath\vcvarsall.bat") -eq $false) + { + Write-BuildMsg -AsError -ErrorAction Stop -Message "Could not find Visual Studio vcvarsall.bat at" + $script:vcPath + } +} + +function Start-SSHBuild +{ + [CmdletBinding(SupportsShouldProcess=$false)] + param + ( + [ValidateSet('x86', 'x64')] + [string]$NativeHostArch = "x64", + + [ValidateSet('Debug', 'Release', '')] + [string]$Configuration = "Debug" + ) + Set-StrictMode -Version Latest + $script:BuildLogFile = $null + + [System.IO.DirectoryInfo] $repositoryRoot = Get-RepositoryRoot + + # Get openssh-portable root + $script:OpenSSHRoot = Get-Item -Path $repositoryRoot.FullName + + if($PSBoundParameters.ContainsKey("Verbose")) + { + $script:Verbose = ($PSBoundParameters['Verbose']).IsPresent + } + + $script:BuildLogFile = Get-BuildLogFile -root $repositoryRoot.FullName -Configuration $Configuration -NativeHostArch $NativeHostArch + if (Test-Path -Path $script:BuildLogFile) + { + Remove-Item -Path $script:BuildLogFile + } + + Write-BuildMsg -AsInfo -Message "Starting Open SSH build." + Write-BuildMsg -AsInfo -Message "Build Log: $($script:BuildLogFile)" + + Start-SSHBootstrap + $msbuildCmd = "msbuild.exe" + $solutionFile = Get-SolutionFile -root $repositoryRoot.FullName + $cmdMsg = @("${solutionFile}", "/p:Platform=${NativeHostArch}", "/p:Configuration=${Configuration}", "/fl", "/flp:LogFile=${script:BuildLogFile}`;Append`;Verbosity=diagnostic") + + Write-Information -MessageData $msbuildCmd + Write-Information -MessageData $cmdMsg + + & $msbuildCmd $cmdMsg + $errorCode = $LASTEXITCODE + + if ($errorCode -ne 0) + { + Write-BuildMsg -AsError -ErrorAction Stop -Message "Build failed for OpenSSH.`nExitCode: $error" + } + + Write-BuildMsg -AsVerbose -Message "Finished Open SSH build." +} + +function Get-BuildLogFile +{ + param + ( + [Parameter(Mandatory=$true)] + [ValidateNotNull()] + [System.IO.DirectoryInfo] $root, + + [ValidateSet('x86', 'x64')] + [string]$NativeHostArch = "x64", + + [ValidateSet('Debug', 'Release', '')] + [string]$Configuration = "Debug" + + ) + return Join-Path -Path $root -ChildPath "contrib\win32\openssh\OpenSSH$($Configuration)$($NativeHostArch).log" +} + +function Get-SolutionFile +{ + param + ( + [Parameter(Mandatory=$true)] + [ValidateNotNull()] + [System.IO.DirectoryInfo] $root + ) + return Join-Path -Path $root -ChildPath "contrib\win32\openssh\Win32-OpenSSH.sln" +} + +<# +.Synopsis + Finds the root of the git repository + +.Outputs + A System.IO.DirectoryInfo for the location of the root. + +.Inputs + None + +.Notes + FileNotFoundException is thrown if the current directory does not contain a CMakeLists.txt file. +#> +function Get-RepositoryRoot +{ + Set-StrictMode -Version Latest + $currentDir = (Get-Item -Path $PSCommandPath).Directory + + while ($null -ne $currentDir.Parent) + { + $path = Join-Path -Path $currentDir.FullName -ChildPath '.git' + if (Test-Path -Path $path) + { + return $currentDir + } + $currentDir = $currentDir.Parent + } + + throw new-object System.IO.DirectoryNotFoundException("Could not find the root of the GIT repository") +} + +Export-ModuleMember -Function Start-SSHBuild, Get-RepositoryRoot, Get-BuildLogFile \ No newline at end of file diff --git a/contrib/win32/openssh/unittest-bitmap.vcxproj b/contrib/win32/openssh/unittest-bitmap.vcxproj new file mode 100644 index 000000000..f99eac19c --- /dev/null +++ b/contrib/win32/openssh/unittest-bitmap.vcxproj @@ -0,0 +1,214 @@ + + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {D901596E-76C7-4608-9CFA-2B42A9FD7250} + Win32Proj + Win32OpenSSH + 8.1 + unittest-bitmap + + + + Application + true + v140 + MultiByte + + + Application + true + v140 + MultiByte + + + Application + false + v140 + true + MultiByte + + + Application + false + v140 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + false + $(Platform)\$(Configuration)\$(TargetName)\ + unittest-bitmap + $(OpenSSH-Bin-Path)$(Platform)\$(Configuration)\ + $(OpenSSH-Src-Path)contrib\win32\win32compat\inc;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + false + $(Platform)\$(Configuration)\$(TargetName)\ + unittest-bitmap + $(OpenSSH-Bin-Path)$(Platform)\$(Configuration)\ + $(OpenSSH-Src-Path)contrib\win32\win32compat\inc;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + false + $(OpenSSH-Bin-Path)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\$(TargetName)\ + unittest-bitmap + $(OpenSSH-Src-Path)contrib\win32\win32compat\inc;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + false + $(OpenSSH-Bin-Path)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\$(TargetName)\ + unittest-bitmap + $(OpenSSH-Src-Path)contrib\win32\win32compat\inc;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + + NotUsing + Level1 + Disabled + _WIN32_WINNT=0x600;WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions) + false + $(SolutionDir);$(OpenSSL-Win32-Debug-Path)include;$(OpenSSH-Src-Path)includes;$(OpenSSH-Src-Path);$(OpenSSH-Src-Path)contrib\win32\win32compat;$(OpenSSH-Src-Path)libkrb;$(OpenSSH-Src-Path)libkrb\libKrb5;%(AdditionalIncludeDirectories) + CompileAsC + MultiThreadedDebug + Sync + ProgramDatabase + + + Console + true + $(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-Win32-Debug-Path)lib;%(AdditionalLibraryDirectories) + Netapi32.lib;posix_compat.lib;bcrypt.lib;Userenv.lib;Ws2_32.lib;Secur32.lib;Shlwapi.lib;openbsd_compat.lib;libssh.lib;libeay32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + wmainCRTStartup + + + targetos.manifest + + + + + NotUsing + Level1 + Disabled + _WIN32_WINNT=0x600;WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions) + false + $(SolutionDir);$(OpenSSL-x64-Debug-Path)include;$(OpenSSH-Src-Path)includes;$(OpenSSH-Src-Path);$(OpenSSH-Src-Path)contrib\win32\win32compat;$(OpenSSH-Src-Path)libkrb;$(OpenSSH-Src-Path)libkrb\libKrb5;%(AdditionalIncludeDirectories) + CompileAsC + MultiThreadedDebug + ProgramDatabase + + + Console + true + $(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-x64-Debug-Path)lib;%(AdditionalLibraryDirectories) + Netapi32.lib;posix_compat.lib;bcrypt.lib;Userenv.lib;Ws2_32.lib;Secur32.lib;Shlwapi.lib;openbsd_compat.lib;libssh.lib;libeay32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + wmainCRTStartup + + + targetos.manifest + + + + + Level1 + NotUsing + MaxSpeed + true + true + _WIN32_WINNT=0x600;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + $(SolutionDir);$(OpenSSL-Win32-Release-Path)include;$(OpenSSH-Src-Path)includes;$(OpenSSH-Src-Path);$(OpenSSH-Src-Path)contrib\win32\win32compat;$(OpenSSH-Src-Path)libkrb;$(OpenSSH-Src-Path)libkrb\libKrb5;%(AdditionalIncludeDirectories) + MultiThreaded + + + Console + No + true + true + $(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-Win32-Release-Path)lib;%(AdditionalLibraryDirectories) + Netapi32.lib;posix_compat.lib;bcrypt.lib;Userenv.lib;Ws2_32.lib;Secur32.lib;Shlwapi.lib;openbsd_compat.lib;libssh.lib;libeay32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + wmainCRTStartup + + + targetos.manifest + + + + + Level1 + NotUsing + MaxSpeed + true + true + _WIN32_WINNT=0x600;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + $(SolutionDir);$(OpenSSL-x64-Release-Path)include;$(OpenSSH-Src-Path)includes;$(OpenSSH-Src-Path);$(OpenSSH-Src-Path)contrib\win32\win32compat;$(OpenSSH-Src-Path)libkrb;$(OpenSSH-Src-Path)libkrb\libKrb5;%(AdditionalIncludeDirectories) + MultiThreaded + true + + + Console + No + true + true + $(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-x64-Release-Path)lib;%(AdditionalLibraryDirectories) + Netapi32.lib;posix_compat.lib;bcrypt.lib;Userenv.lib;Ws2_32.lib;Secur32.lib;Shlwapi.lib;openbsd_compat.lib;libssh.lib;libeay32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + wmainCRTStartup + + + targetos.manifest + + + + + true + + + true + + + true + + + + + + \ No newline at end of file diff --git a/contrib/win32/openssh/unittest-hostkeys.vcxproj b/contrib/win32/openssh/unittest-hostkeys.vcxproj new file mode 100644 index 000000000..247e56dc5 --- /dev/null +++ b/contrib/win32/openssh/unittest-hostkeys.vcxproj @@ -0,0 +1,221 @@ + + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {890C6129-286F-4CD8-8252-FB8D3B4E6E1B} + Win32Proj + Win32OpenSSH + 8.1 + unittest-hostkeys + + + + Application + true + v140 + MultiByte + + + Application + true + v140 + MultiByte + + + Application + false + v140 + true + MultiByte + + + Application + false + v140 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + false + $(Platform)\$(Configuration)\$(TargetName)\ + unittest-hostkeys + $(OpenSSH-Bin-Path)$(Platform)\$(Configuration)\ + $(OpenSSH-Src-Path)contrib\win32\win32compat\inc;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + false + $(Platform)\$(Configuration)\$(TargetName)\ + unittest-hostkeys + $(OpenSSH-Bin-Path)$(Platform)\$(Configuration)\ + $(OpenSSH-Src-Path)contrib\win32\win32compat\inc;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + false + $(OpenSSH-Bin-Path)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\$(TargetName)\ + unittest-hostkeys + $(OpenSSH-Src-Path)contrib\win32\win32compat\inc;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + false + $(OpenSSH-Bin-Path)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\$(TargetName)\ + unittest-hostkeys + $(OpenSSH-Src-Path)contrib\win32\win32compat\inc;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + + NotUsing + Level1 + Disabled + _WIN32_WINNT=0x600;WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions) + false + $(SolutionDir);$(OpenSSL-Win32-Debug-Path)include;$(OpenSSH-Src-Path)includes;$(OpenSSH-Src-Path);$(OpenSSH-Src-Path)contrib\win32\win32compat;$(OpenSSH-Src-Path)libkrb;$(OpenSSH-Src-Path)libkrb\libKrb5;%(AdditionalIncludeDirectories) + CompileAsC + MultiThreadedDebug + Sync + ProgramDatabase + + + Console + true + $(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-Win32-Debug-Path)lib;%(AdditionalLibraryDirectories) + Netapi32.lib;posix_compat.lib;bcrypt.lib;Userenv.lib;Ws2_32.lib;Secur32.lib;Shlwapi.lib;openbsd_compat.lib;libssh.lib;libeay32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + wmainCRTStartup + + + targetos.manifest + + + copy /Y $(ProjectDir)..\..\..\regress\unittests\hostkeys\testdata\* $(OutDir) + + + + + NotUsing + Level1 + Disabled + _WIN32_WINNT=0x600;WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions) + false + $(SolutionDir);$(OpenSSL-x64-Debug-Path)include;$(OpenSSH-Src-Path)includes;$(OpenSSH-Src-Path);$(OpenSSH-Src-Path)contrib\win32\win32compat;$(OpenSSH-Src-Path)libkrb;$(OpenSSH-Src-Path)libkrb\libKrb5;%(AdditionalIncludeDirectories) + CompileAsC + MultiThreadedDebug + ProgramDatabase + + + Console + true + $(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-x64-Debug-Path)lib;%(AdditionalLibraryDirectories) + Netapi32.lib;posix_compat.lib;bcrypt.lib;Userenv.lib;Ws2_32.lib;Secur32.lib;Shlwapi.lib;openbsd_compat.lib;libssh.lib;libeay32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + wmainCRTStartup + + + targetos.manifest + + + copy /Y $(ProjectDir)..\..\..\regress\unittests\hostkeys\testdata\* $(OutDir) + + + + + Level1 + NotUsing + MaxSpeed + true + true + _WIN32_WINNT=0x600;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + $(SolutionDir);$(OpenSSL-Win32-Release-Path)include;$(OpenSSH-Src-Path)includes;$(OpenSSH-Src-Path);$(OpenSSH-Src-Path)contrib\win32\win32compat;$(OpenSSH-Src-Path)libkrb;$(OpenSSH-Src-Path)libkrb\libKrb5;%(AdditionalIncludeDirectories) + MultiThreaded + + + Console + No + true + true + $(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-Win32-Release-Path)lib;%(AdditionalLibraryDirectories) + Netapi32.lib;posix_compat.lib;bcrypt.lib;Userenv.lib;Ws2_32.lib;Secur32.lib;Shlwapi.lib;openbsd_compat.lib;libssh.lib;libeay32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + wmainCRTStartup + + + targetos.manifest + + + copy /Y $(ProjectDir)..\..\..\regress\unittests\hostkeys\testdata\* $(OutDir) + + + + + Level1 + NotUsing + MaxSpeed + true + true + _WIN32_WINNT=0x600;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + $(SolutionDir);$(OpenSSL-x64-Release-Path)include;$(OpenSSH-Src-Path)includes;$(OpenSSH-Src-Path);$(OpenSSH-Src-Path)contrib\win32\win32compat;$(OpenSSH-Src-Path)libkrb;$(OpenSSH-Src-Path)libkrb\libKrb5;%(AdditionalIncludeDirectories) + MultiThreaded + true + + + Console + No + true + true + $(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-x64-Release-Path)lib;%(AdditionalLibraryDirectories) + Netapi32.lib;posix_compat.lib;bcrypt.lib;Userenv.lib;Ws2_32.lib;Secur32.lib;Shlwapi.lib;openbsd_compat.lib;libssh.lib;libeay32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + wmainCRTStartup + + + targetos.manifest + + + copy /Y $(ProjectDir)..\..\..\regress\unittests\hostkeys\testdata\* $(OutDir) + + + + + + + + + + + + \ No newline at end of file diff --git a/contrib/win32/openssh/unittest-kex.vcxproj b/contrib/win32/openssh/unittest-kex.vcxproj new file mode 100644 index 000000000..d71458474 --- /dev/null +++ b/contrib/win32/openssh/unittest-kex.vcxproj @@ -0,0 +1,210 @@ + + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {8EC56B06-5A9A-4D6D-804D-037FE26FD43E} + Win32Proj + Win32OpenSSH + 8.1 + unittest-kex + + + + Application + true + v140 + MultiByte + + + Application + true + v140 + MultiByte + + + Application + false + v140 + true + MultiByte + + + Application + false + v140 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + false + $(Platform)\$(Configuration)\$(TargetName)\ + unittest-kex + $(OpenSSH-Bin-Path)$(Platform)\$(Configuration)\ + $(OpenSSH-Src-Path)contrib\win32\win32compat\inc;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + false + $(Platform)\$(Configuration)\$(TargetName)\ + unittest-kex + $(OpenSSH-Bin-Path)$(Platform)\$(Configuration)\ + $(OpenSSH-Src-Path)contrib\win32\win32compat\inc;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + false + $(OpenSSH-Bin-Path)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\$(TargetName)\ + unittest-kex + $(OpenSSH-Src-Path)contrib\win32\win32compat\inc;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + false + $(OpenSSH-Bin-Path)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\$(TargetName)\ + unittest-kex + $(OpenSSH-Src-Path)contrib\win32\win32compat\inc;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + + NotUsing + Level1 + Disabled + _WIN32_WINNT=0x600;WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions) + false + $(SolutionDir);$(OpenSSL-Win32-Debug-Path)include;$(OpenSSH-Src-Path)includes;$(OpenSSH-Src-Path);$(OpenSSH-Src-Path)contrib\win32\win32compat;$(OpenSSH-Src-Path)libkrb;$(OpenSSH-Src-Path)libkrb\libKrb5;%(AdditionalIncludeDirectories) + CompileAsC + MultiThreadedDebug + Sync + ProgramDatabase + + + Console + true + $(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-Win32-Debug-Path)lib;%(AdditionalLibraryDirectories) + Netapi32.lib;posix_compat.lib;bcrypt.lib;Userenv.lib;Ws2_32.lib;Secur32.lib;Shlwapi.lib;openbsd_compat.lib;libssh.lib;libeay32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + wmainCRTStartup + + + targetos.manifest + + + + + NotUsing + Level1 + Disabled + _WIN32_WINNT=0x600;WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions) + false + $(SolutionDir);$(OpenSSL-x64-Debug-Path)include;$(OpenSSH-Src-Path)includes;$(OpenSSH-Src-Path);$(OpenSSH-Src-Path)contrib\win32\win32compat;$(OpenSSH-Src-Path)libkrb;$(OpenSSH-Src-Path)libkrb\libKrb5;%(AdditionalIncludeDirectories) + CompileAsC + MultiThreadedDebug + ProgramDatabase + + + Console + true + $(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-x64-Debug-Path)lib;%(AdditionalLibraryDirectories) + Netapi32.lib;posix_compat.lib;bcrypt.lib;Userenv.lib;Ws2_32.lib;Secur32.lib;Shlwapi.lib;openbsd_compat.lib;libssh.lib;libeay32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + wmainCRTStartup + + + targetos.manifest + + + + + Level1 + NotUsing + MaxSpeed + true + true + _WIN32_WINNT=0x600;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + $(SolutionDir);$(OpenSSL-Win32-Release-Path)include;$(OpenSSH-Src-Path)includes;$(OpenSSH-Src-Path);$(OpenSSH-Src-Path)contrib\win32\win32compat;$(OpenSSH-Src-Path)libkrb;$(OpenSSH-Src-Path)libkrb\libKrb5;%(AdditionalIncludeDirectories) + MultiThreaded + + + Console + No + true + true + $(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-Win32-Release-Path)lib;%(AdditionalLibraryDirectories) + Netapi32.lib;posix_compat.lib;bcrypt.lib;Userenv.lib;Ws2_32.lib;Secur32.lib;Shlwapi.lib;openbsd_compat.lib;libssh.lib;libeay32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + wmainCRTStartup + + + targetos.manifest + + + + + Level1 + NotUsing + MaxSpeed + true + true + _WIN32_WINNT=0x600;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + $(SolutionDir);$(OpenSSL-x64-Release-Path)include;$(OpenSSH-Src-Path)includes;$(OpenSSH-Src-Path);$(OpenSSH-Src-Path)contrib\win32\win32compat;$(OpenSSH-Src-Path)libkrb;$(OpenSSH-Src-Path)libkrb\libKrb5;%(AdditionalIncludeDirectories) + MultiThreaded + true + + + Console + No + true + true + $(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-x64-Release-Path)lib;%(AdditionalLibraryDirectories) + Netapi32.lib;posix_compat.lib;bcrypt.lib;Userenv.lib;Ws2_32.lib;Secur32.lib;Shlwapi.lib;openbsd_compat.lib;libssh.lib;libeay32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + wmainCRTStartup + + + targetos.manifest + + + + + + + + + + + + + \ No newline at end of file diff --git a/contrib/win32/openssh/unittest-sshbuf.vcxproj b/contrib/win32/openssh/unittest-sshbuf.vcxproj new file mode 100644 index 000000000..c70c2cfea --- /dev/null +++ b/contrib/win32/openssh/unittest-sshbuf.vcxproj @@ -0,0 +1,220 @@ + + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {CD9740CE-C96E-49B3-823F-012E09D17806} + Win32Proj + Win32OpenSSH + 8.1 + unittest-sshbuf + + + + Application + true + v140 + MultiByte + + + Application + true + v140 + MultiByte + + + Application + false + v140 + true + MultiByte + + + Application + false + v140 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + false + $(Platform)\$(Configuration)\$(TargetName)\ + unittest-sshbuf + $(OpenSSH-Bin-Path)$(Platform)\$(Configuration)\ + $(OpenSSH-Src-Path)contrib\win32\win32compat\inc;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + false + $(Platform)\$(Configuration)\$(TargetName)\ + unittest-sshbuf + $(OpenSSH-Bin-Path)$(Platform)\$(Configuration)\ + $(OpenSSH-Src-Path)contrib\win32\win32compat\inc;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + false + $(OpenSSH-Bin-Path)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\$(TargetName)\ + unittest-sshbuf + $(OpenSSH-Src-Path)contrib\win32\win32compat\inc;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + false + $(OpenSSH-Bin-Path)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\$(TargetName)\ + unittest-sshbuf + $(OpenSSH-Src-Path)contrib\win32\win32compat\inc;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + + NotUsing + Level1 + Disabled + _WIN32_WINNT=0x600;WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions) + false + $(SolutionDir);$(OpenSSL-Win32-Debug-Path)include;$(OpenSSH-Src-Path)includes;$(OpenSSH-Src-Path);$(OpenSSH-Src-Path)contrib\win32\win32compat;$(OpenSSH-Src-Path)libkrb;$(OpenSSH-Src-Path)libkrb\libKrb5;%(AdditionalIncludeDirectories) + CompileAsC + MultiThreadedDebug + Sync + ProgramDatabase + + + Console + true + $(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-Win32-Debug-Path)lib;%(AdditionalLibraryDirectories) + Netapi32.lib;posix_compat.lib;bcrypt.lib;Userenv.lib;Ws2_32.lib;Secur32.lib;Shlwapi.lib;openbsd_compat.lib;libssh.lib;libeay32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + wmainCRTStartup + + + targetos.manifest + + + + + NotUsing + Level1 + Disabled + _WIN32_WINNT=0x600;WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions) + false + $(SolutionDir);$(OpenSSL-x64-Debug-Path)include;$(OpenSSH-Src-Path)includes;$(OpenSSH-Src-Path);$(OpenSSH-Src-Path)contrib\win32\win32compat;$(OpenSSH-Src-Path)libkrb;$(OpenSSH-Src-Path)libkrb\libKrb5;%(AdditionalIncludeDirectories) + CompileAsC + MultiThreadedDebug + ProgramDatabase + + + Console + true + $(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-x64-Debug-Path)lib;%(AdditionalLibraryDirectories) + Netapi32.lib;posix_compat.lib;bcrypt.lib;Userenv.lib;Ws2_32.lib;Secur32.lib;Shlwapi.lib;openbsd_compat.lib;libssh.lib;libeay32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + wmainCRTStartup + + + targetos.manifest + + + + + Level1 + NotUsing + MaxSpeed + true + true + _WIN32_WINNT=0x600;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + $(SolutionDir);$(OpenSSL-Win32-Release-Path)include;$(OpenSSH-Src-Path)includes;$(OpenSSH-Src-Path);$(OpenSSH-Src-Path)contrib\win32\win32compat;$(OpenSSH-Src-Path)libkrb;$(OpenSSH-Src-Path)libkrb\libKrb5;%(AdditionalIncludeDirectories) + MultiThreaded + + + Console + No + true + true + $(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-Win32-Release-Path)lib;%(AdditionalLibraryDirectories) + Netapi32.lib;posix_compat.lib;bcrypt.lib;Userenv.lib;Ws2_32.lib;Secur32.lib;Shlwapi.lib;openbsd_compat.lib;libssh.lib;libeay32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + wmainCRTStartup + + + targetos.manifest + + + + + Level1 + NotUsing + MaxSpeed + true + true + _WIN32_WINNT=0x600;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;WIN32;NDEBUG;%(PreprocessorDefinitions) + false + $(SolutionDir);$(OpenSSL-x64-Release-Path)include;$(OpenSSH-Src-Path)includes;$(OpenSSH-Src-Path);$(OpenSSH-Src-Path)contrib\win32\win32compat;$(OpenSSH-Src-Path)libkrb;$(OpenSSH-Src-Path)libkrb\libKrb5;%(AdditionalIncludeDirectories) + MultiThreaded + true + + + Console + No + true + true + $(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-x64-Release-Path)lib;%(AdditionalLibraryDirectories) + Netapi32.lib;posix_compat.lib;bcrypt.lib;Userenv.lib;Ws2_32.lib;Secur32.lib;Shlwapi.lib;openbsd_compat.lib;libssh.lib;libeay32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + wmainCRTStartup + + + targetos.manifest + + + + + + + + + + true + + + true + + + + + + + + + + \ No newline at end of file diff --git a/contrib/win32/openssh/unittest-sshkey.vcxproj b/contrib/win32/openssh/unittest-sshkey.vcxproj new file mode 100644 index 000000000..03eea3f5c --- /dev/null +++ b/contrib/win32/openssh/unittest-sshkey.vcxproj @@ -0,0 +1,225 @@ + + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {FC568FF0-60F2-4B2E-AF62-FD392EDBA1B9} + Win32Proj + Win32OpenSSH + 8.1 + unittest-sshkey + + + + Application + true + v140 + MultiByte + + + Application + true + v140 + MultiByte + + + Application + false + v140 + true + MultiByte + + + Application + false + v140 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + false + $(Platform)\$(Configuration)\$(TargetName)\ + unittest-sshkey + $(OpenSSH-Bin-Path)$(Platform)\$(Configuration)\ + $(OpenSSH-Src-Path)contrib\win32\win32compat\inc;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + false + $(Platform)\$(Configuration)\$(TargetName)\ + unittest-sshkey + $(OpenSSH-Bin-Path)$(Platform)\$(Configuration)\ + $(OpenSSH-Src-Path)contrib\win32\win32compat\inc;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + false + $(OpenSSH-Bin-Path)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\$(TargetName)\ + unittest-sshkey + $(OpenSSH-Src-Path)contrib\win32\win32compat\inc;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + false + $(OpenSSH-Bin-Path)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\$(TargetName)\ + unittest-sshkey + $(OpenSSH-Src-Path)contrib\win32\win32compat\inc;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + + NotUsing + Level1 + Disabled + _WIN32_WINNT=0x600;WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions) + false + $(SolutionDir);$(OpenSSL-Win32-Debug-Path)include;$(OpenSSH-Src-Path)includes;$(OpenSSH-Src-Path);$(OpenSSH-Src-Path)contrib\win32\win32compat;$(OpenSSH-Src-Path)libkrb;$(OpenSSH-Src-Path)libkrb\libKrb5;%(AdditionalIncludeDirectories) + CompileAsC + MultiThreadedDebug + Sync + ProgramDatabase + + + Console + true + $(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-Win32-Debug-Path)lib;%(AdditionalLibraryDirectories) + Netapi32.lib;posix_compat.lib;bcrypt.lib;Userenv.lib;Ws2_32.lib;Secur32.lib;Shlwapi.lib;openbsd_compat.lib;libssh.lib;libeay32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + wmainCRTStartup + + + targetos.manifest + + + copy /Y $(ProjectDir)..\..\..\regress\unittests\sshkey\testdata\* $(OutDir) + + + + + NotUsing + Level1 + Disabled + _WIN32_WINNT=0x600;WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions) + false + $(SolutionDir);$(OpenSSL-x64-Debug-Path)include;$(OpenSSH-Src-Path)includes;$(OpenSSH-Src-Path);$(OpenSSH-Src-Path)contrib\win32\win32compat;$(OpenSSH-Src-Path)libkrb;$(OpenSSH-Src-Path)libkrb\libKrb5;%(AdditionalIncludeDirectories) + CompileAsC + MultiThreadedDebug + ProgramDatabase + + + Console + true + $(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-x64-Debug-Path)lib;%(AdditionalLibraryDirectories) + Netapi32.lib;posix_compat.lib;bcrypt.lib;Userenv.lib;Ws2_32.lib;Secur32.lib;Shlwapi.lib;openbsd_compat.lib;libssh.lib;libeay32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + wmainCRTStartup + + + targetos.manifest + + + copy /Y $(ProjectDir)..\..\..\regress\unittests\sshkey\testdata\* $(OutDir) + + + + + Level1 + NotUsing + MaxSpeed + true + true + _WIN32_WINNT=0x600;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + $(SolutionDir);$(OpenSSL-Win32-Release-Path)include;$(OpenSSH-Src-Path)includes;$(OpenSSH-Src-Path);$(OpenSSH-Src-Path)contrib\win32\win32compat;$(OpenSSH-Src-Path)libkrb;$(OpenSSH-Src-Path)libkrb\libKrb5;%(AdditionalIncludeDirectories) + MultiThreaded + + + Console + No + true + true + $(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-Win32-Release-Path)lib;%(AdditionalLibraryDirectories) + Netapi32.lib;posix_compat.lib;bcrypt.lib;Userenv.lib;Ws2_32.lib;Secur32.lib;Shlwapi.lib;openbsd_compat.lib;libssh.lib;libeay32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + wmainCRTStartup + + + targetos.manifest + + + copy /Y $(ProjectDir)..\..\..\regress\unittests\sshkey\testdata\* $(OutDir) + + + + + Level1 + NotUsing + MaxSpeed + true + true + _WIN32_WINNT=0x600;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + $(SolutionDir);$(OpenSSL-x64-Release-Path)include;$(OpenSSH-Src-Path)includes;$(OpenSSH-Src-Path);$(OpenSSH-Src-Path)contrib\win32\win32compat;$(OpenSSH-Src-Path)libkrb;$(OpenSSH-Src-Path)libkrb\libKrb5;%(AdditionalIncludeDirectories) + MultiThreaded + true + + + Console + No + true + true + $(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-x64-Release-Path)lib;%(AdditionalLibraryDirectories) + Netapi32.lib;posix_compat.lib;bcrypt.lib;Userenv.lib;Ws2_32.lib;Secur32.lib;Shlwapi.lib;openbsd_compat.lib;libssh.lib;libeay32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + wmainCRTStartup + + + targetos.manifest + + + copy /Y $(ProjectDir)..\..\..\regress\unittests\sshkey\testdata\* $(OutDir) + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/contrib/win32/openssh/unittest-utf8.vcxproj b/contrib/win32/openssh/unittest-utf8.vcxproj new file mode 100644 index 000000000..62aef0c74 --- /dev/null +++ b/contrib/win32/openssh/unittest-utf8.vcxproj @@ -0,0 +1,208 @@ + + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {114CAA59-46C0-4B87-BA86-C1946A68101D} + Win32Proj + Win32OpenSSH + 8.1 + unittest-utf8 + + + + Application + true + v140 + MultiByte + + + Application + true + v140 + MultiByte + + + Application + false + v140 + true + MultiByte + + + Application + false + v140 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + false + $(Platform)\$(Configuration)\$(TargetName)\ + unittest-utf8 + $(OpenSSH-Bin-Path)$(Platform)\$(Configuration)\ + $(OpenSSH-Src-Path)contrib\win32\win32compat\inc;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + false + $(Platform)\$(Configuration)\$(TargetName)\ + unittest-utf8 + $(OpenSSH-Bin-Path)$(Platform)\$(Configuration)\ + $(OpenSSH-Src-Path)contrib\win32\win32compat\inc;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + false + $(OpenSSH-Bin-Path)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\$(TargetName)\ + unittest-utf8 + $(OpenSSH-Src-Path)contrib\win32\win32compat\inc;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + false + $(OpenSSH-Bin-Path)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\$(TargetName)\ + unittest-utf8 + $(OpenSSH-Src-Path)contrib\win32\win32compat\inc;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + + NotUsing + Level1 + Disabled + _WIN32_WINNT=0x600;WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions) + false + $(SolutionDir);$(OpenSSL-Win32-Debug-Path)include;$(OpenSSH-Src-Path)includes;$(OpenSSH-Src-Path);$(OpenSSH-Src-Path)contrib\win32\win32compat;$(OpenSSH-Src-Path)libkrb;$(OpenSSH-Src-Path)libkrb\libKrb5;%(AdditionalIncludeDirectories) + CompileAsC + MultiThreadedDebug + Sync + ProgramDatabase + + + Console + true + $(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-Win32-Debug-Path)lib;%(AdditionalLibraryDirectories) + Netapi32.lib;posix_compat.lib;bcrypt.lib;Userenv.lib;Ws2_32.lib;Secur32.lib;Shlwapi.lib;openbsd_compat.lib;libssh.lib;libeay32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + wmainCRTStartup + + + targetos.manifest + + + + + NotUsing + Level1 + Disabled + _WIN32_WINNT=0x600;WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions) + false + $(SolutionDir);$(OpenSSL-x64-Debug-Path)include;$(OpenSSH-Src-Path)includes;$(OpenSSH-Src-Path);$(OpenSSH-Src-Path)contrib\win32\win32compat;$(OpenSSH-Src-Path)libkrb;$(OpenSSH-Src-Path)libkrb\libKrb5;%(AdditionalIncludeDirectories) + CompileAsC + MultiThreadedDebug + ProgramDatabase + + + Console + true + $(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-x64-Debug-Path)lib;%(AdditionalLibraryDirectories) + Netapi32.lib;posix_compat.lib;bcrypt.lib;Userenv.lib;Ws2_32.lib;Secur32.lib;Shlwapi.lib;openbsd_compat.lib;libssh.lib;libeay32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + wmainCRTStartup + + + targetos.manifest + + + + + Level1 + NotUsing + MaxSpeed + true + true + _WIN32_WINNT=0x600;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + $(SolutionDir);$(OpenSSL-Win32-Release-Path)include;$(OpenSSH-Src-Path)includes;$(OpenSSH-Src-Path);$(OpenSSH-Src-Path)contrib\win32\win32compat;$(OpenSSH-Src-Path)libkrb;$(OpenSSH-Src-Path)libkrb\libKrb5;%(AdditionalIncludeDirectories) + MultiThreaded + + + Console + No + true + true + $(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-Win32-Release-Path)lib;%(AdditionalLibraryDirectories) + Netapi32.lib;posix_compat.lib;bcrypt.lib;Userenv.lib;Ws2_32.lib;Secur32.lib;Shlwapi.lib;openbsd_compat.lib;libssh.lib;libeay32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + wmainCRTStartup + + + targetos.manifest + + + + + Level1 + NotUsing + MaxSpeed + true + true + _WIN32_WINNT=0x600;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + $(SolutionDir);$(OpenSSL-x64-Release-Path)include;$(OpenSSH-Src-Path)includes;$(OpenSSH-Src-Path);$(OpenSSH-Src-Path)contrib\win32\win32compat;$(OpenSSH-Src-Path)libkrb;$(OpenSSH-Src-Path)libkrb\libKrb5;%(AdditionalIncludeDirectories) + MultiThreaded + true + + + Console + No + true + true + $(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-x64-Release-Path)lib;%(AdditionalLibraryDirectories) + Netapi32.lib;posix_compat.lib;bcrypt.lib;Userenv.lib;Ws2_32.lib;Secur32.lib;Shlwapi.lib;openbsd_compat.lib;libssh.lib;libeay32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + wmainCRTStartup + + + targetos.manifest + + + + + + + + + + + \ No newline at end of file diff --git a/contrib/win32/openssh/unittest-win32compat.vcxproj b/contrib/win32/openssh/unittest-win32compat.vcxproj new file mode 100644 index 000000000..4eaef80fc --- /dev/null +++ b/contrib/win32/openssh/unittest-win32compat.vcxproj @@ -0,0 +1,210 @@ + + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + + + + + + + + {BF295BA9-4BF8-43F8-8CBF-FAE84815466C} + Win32Proj + Win32OpenSSH + 8.1 + unittest-win32compat + + + + Application + true + v140 + MultiByte + + + Application + true + v140 + MultiByte + + + Application + false + v140 + true + MultiByte + + + Application + false + v140 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + false + $(Platform)\$(Configuration)\$(TargetName)\ + unittest-win32compat + $(OpenSSH-Bin-Path)$(Platform)\$(Configuration)\ + $(OpenSSH-Src-Path)contrib\win32\win32compat\inc;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + false + $(Platform)\$(Configuration)\$(TargetName)\ + unittest-win32compat + $(OpenSSH-Bin-Path)$(Platform)\$(Configuration)\ + $(OpenSSH-Src-Path)contrib\win32\win32compat\inc;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + false + $(OpenSSH-Bin-Path)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\$(TargetName)\ + unittest-win32compat + $(OpenSSH-Src-Path)contrib\win32\win32compat\inc;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + false + $(OpenSSH-Bin-Path)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\$(TargetName)\ + unittest-win32compat + $(OpenSSH-Src-Path)contrib\win32\win32compat\inc;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + + NotUsing + Level1 + Disabled + _WIN32_WINNT=0x600;WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions) + false + $(SolutionDir);$(OpenSSL-Win32-Debug-Path)include;$(OpenSSH-Src-Path)includes;$(OpenSSH-Src-Path);$(OpenSSH-Src-Path)contrib\win32\win32compat;$(OpenSSH-Src-Path)libkrb;$(OpenSSH-Src-Path)libkrb\libKrb5;%(AdditionalIncludeDirectories) + CompileAsC + MultiThreadedDebug + Sync + ProgramDatabase + + + Console + true + $(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-Win32-Debug-Path)lib;%(AdditionalLibraryDirectories) + Netapi32.lib;posix_compat.lib;bcrypt.lib;Userenv.lib;Ws2_32.lib;Secur32.lib;Shlwapi.lib;openbsd_compat.lib;libssh.lib;libeay32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + wmainCRTStartup + + + targetos.manifest + + + + + NotUsing + Level1 + Disabled + _WIN32_WINNT=0x600;WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;_UNICODE;%(PreprocessorDefinitions) + false + $(SolutionDir);$(OpenSSL-x64-Debug-Path)include;$(OpenSSH-Src-Path)includes;$(OpenSSH-Src-Path);$(OpenSSH-Src-Path)contrib\win32\win32compat;$(OpenSSH-Src-Path)libkrb;$(OpenSSH-Src-Path)libkrb\libKrb5;%(AdditionalIncludeDirectories) + CompileAsC + MultiThreadedDebug + ProgramDatabase + + + Console + true + $(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-x64-Debug-Path)lib;%(AdditionalLibraryDirectories) + Netapi32.lib;posix_compat.lib;bcrypt.lib;Userenv.lib;Ws2_32.lib;Secur32.lib;Shlwapi.lib;openbsd_compat.lib;libssh.lib;libeay32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + wmainCRTStartup + + + targetos.manifest + + + + + Level1 + NotUsing + MaxSpeed + true + true + _WIN32_WINNT=0x600;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + $(SolutionDir);$(OpenSSL-Win32-Release-Path)include;$(OpenSSH-Src-Path)includes;$(OpenSSH-Src-Path);$(OpenSSH-Src-Path)contrib\win32\win32compat;$(OpenSSH-Src-Path)libkrb;$(OpenSSH-Src-Path)libkrb\libKrb5;%(AdditionalIncludeDirectories) + MultiThreaded + + + Console + No + true + true + $(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-Win32-Release-Path)lib;%(AdditionalLibraryDirectories) + Netapi32.lib;posix_compat.lib;bcrypt.lib;Userenv.lib;Ws2_32.lib;Secur32.lib;Shlwapi.lib;openbsd_compat.lib;libssh.lib;libeay32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + wmainCRTStartup + + + targetos.manifest + + + + + Level1 + NotUsing + MaxSpeed + true + true + _WIN32_WINNT=0x600;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + $(SolutionDir);$(OpenSSL-x64-Release-Path)include;$(OpenSSH-Src-Path)includes;$(OpenSSH-Src-Path);$(OpenSSH-Src-Path)contrib\win32\win32compat;$(OpenSSH-Src-Path)libkrb;$(OpenSSH-Src-Path)libkrb\libKrb5;%(AdditionalIncludeDirectories) + MultiThreaded + true + + + Console + No + true + true + $(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-x64-Release-Path)lib;%(AdditionalLibraryDirectories) + Netapi32.lib;posix_compat.lib;bcrypt.lib;Userenv.lib;Ws2_32.lib;Secur32.lib;Shlwapi.lib;openbsd_compat.lib;libssh.lib;libeay32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + wmainCRTStartup + + + targetos.manifest + + + + + + \ No newline at end of file diff --git a/contrib/win32/openssh/win32iocompat.vcxproj b/contrib/win32/openssh/win32iocompat.vcxproj new file mode 100644 index 000000000..7849190fa --- /dev/null +++ b/contrib/win32/openssh/win32iocompat.vcxproj @@ -0,0 +1,205 @@ + + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {0D02F0F0-013B-4EE3-906D-86517F3822C0} + win32iocompat + Win32Proj + 8.1 + posix_compat + + + + StaticLibrary + v140 + MultiByte + true + + + StaticLibrary + v140 + MultiByte + true + + + StaticLibrary + v140 + MultiByte + + + StaticLibrary + v140 + MultiByte + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>14.0.23107.0 + + + $(OpenSSH-Lib-Path)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\$(TargetName)\ + + + $(OpenSSH-Lib-Path)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\$(TargetName)\ + + + $(OpenSSH-Lib-Path)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\$(TargetName)\ + + + $(OpenSSH-Lib-Path)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\$(TargetName)\ + + + + Disabled + + + USE_MSCNG;_WIN32_WINNT=0x600;WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions) + true + EnableFastChecks + MultiThreadedDebug + NotUsing + Level1 + ProgramDatabase + false + false + + + + + Disabled + + + USE_MSCNG;_WIN32_WINNT=0x600;WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions) + EnableFastChecks + MultiThreadedDebug + NotUsing + Level1 + ProgramDatabase + false + + + + + + + _LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;USE_MSCNG;_WIN32_WINNT=0x600;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + MultiThreaded + NotUsing + Level1 + ProgramDatabase + false + + + + + + + _LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;USE_MSCNG;_WIN32_WINNT=0x600;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + MultiThreaded + NotUsing + Level1 + ProgramDatabase + false + Disabled + false + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/contrib/win32/openssh/win32iocompat.vcxproj.filters b/contrib/win32/openssh/win32iocompat.vcxproj.filters new file mode 100644 index 000000000..ee2675f49 --- /dev/null +++ b/contrib/win32/openssh/win32iocompat.vcxproj.filters @@ -0,0 +1,135 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + inc\sys + + + inc\sys + + + inc\sys + + + inc\sys + + + inc + + + inc + + + inc + + + inc + + + inc + + + inc + + + inc\sys + + + inc\sys + + + + + + inc\sys + + + inc + + + inc\sys + + + inc\sys + + + inc\sys + + + inc\sys + + + inc\arpa + + + inc\arpa + + + inc\netinet + + + inc\netinet + + + inc\netinet + + + inc\netinet + + + inc + + + inc + + + inc + + + inc + + + inc + + + + inc + + + + + + {b70431df-c3b2-46ee-a825-aeb9df643f7f} + + + {9fd6aa70-2efb-4577-87eb-d285a9cbbaa0} + + + {6e4a035d-0b38-4507-9eec-19097d4ac16f} + + + {d943f1aa-2df9-4df3-b499-4403a899fe8d} + + + \ No newline at end of file diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 6f3bc8f1d..c03ac6869 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -211,6 +211,7 @@ tcsendbreak(int fd, int duration) } #endif /* HAVE_TCSENDBREAK */ +#ifdef HAVE_SIGACTION /* Moved out of function definition */ mysig_t mysignal(int sig, mysig_t act) { @@ -237,6 +238,7 @@ mysignal(int sig, mysig_t act) return (signal(sig, act)); #endif } +#endif #ifndef HAVE_STRDUP char * diff --git a/openbsd-compat/bsd-misc.h b/openbsd-compat/bsd-misc.h index 6f08b09fa..77029fa6b 100644 --- a/openbsd-compat/bsd-misc.h +++ b/openbsd-compat/bsd-misc.h @@ -95,10 +95,12 @@ int unsetenv(const char *); #endif /* wrapper for signal interface */ +#ifdef HAVE_SIGACTION typedef void (*mysig_t)(int); mysig_t mysignal(int sig, mysig_t act); #define signal(a,b) mysignal(a,b) +#endif #ifndef HAVE_ISBLANK int isblank(int); diff --git a/regress/netcat.c b/regress/netcat.c index 98a08b1ec..91642df31 100644 --- a/regress/netcat.c +++ b/regress/netcat.c @@ -558,8 +558,9 @@ unix_connect(char *path) if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) return (-1); } +#ifndef WIN32_FIXME (void)fcntl(s, F_SETFD, FD_CLOEXEC); - +#endif memset(&sun_sa, 0, sizeof(struct sockaddr_un)); sun_sa.sun_family = AF_UNIX; @@ -669,12 +670,13 @@ timeout_connect(int s, const struct sockaddr *name, socklen_t namelen) socklen_t optlen; int flags = 0, optval; int ret; - +#ifndef WIN32_FIXME if (timeout != -1) { flags = fcntl(s, F_GETFL, 0); if (fcntl(s, F_SETFL, flags | O_NONBLOCK) == -1) err(1, "set non-blocking mode"); } +#endif if ((ret = connect(s, name, namelen)) != 0 && errno == EINPROGRESS) { pfd.fd = s; @@ -692,10 +694,10 @@ timeout_connect(int s, const struct sockaddr *name, socklen_t namelen) } else err(1, "poll failed"); } - +#ifndef WIN32_FIXME if (timeout != -1 && fcntl(s, F_SETFL, flags) == -1) err(1, "restoring flags"); - +#endif return (ret); } @@ -764,6 +766,13 @@ local_listen(char *host, char *port, struct addrinfo hints) * readwrite() * Loop that polls on the network file descriptor and stdin. */ + +#ifdef WIN32_FIXME +#define POLLNVAL 0x0020 +#define POLLHUP 0x0010 +#define RPP_REQUIRE_TTY 0x02 /* Fail if there is no tty. */ +#endif + void readwrite(int net_fd) { @@ -1213,7 +1222,9 @@ map_tos(char *s, int *val) { "af41", IPTOS_DSCP_AF41 }, { "af42", IPTOS_DSCP_AF42 }, { "af43", IPTOS_DSCP_AF43 }, +#ifndef WIN32_FIXME { "critical", IPTOS_PREC_CRITIC_ECP }, +#endif { "cs0", IPTOS_DSCP_CS0 }, { "cs1", IPTOS_DSCP_CS1 }, { "cs2", IPTOS_DSCP_CS2 }, @@ -1223,9 +1234,13 @@ map_tos(char *s, int *val) { "cs6", IPTOS_DSCP_CS6 }, { "cs7", IPTOS_DSCP_CS7 }, { "ef", IPTOS_DSCP_EF }, +#ifndef WIN32_FIXME { "inetcontrol", IPTOS_PREC_INTERNETCONTROL }, +#endif { "lowdelay", IPTOS_LOWDELAY }, +#ifndef WIN32_FIXME { "netcontrol", IPTOS_PREC_NETCONTROL }, +#endif { "reliability", IPTOS_RELIABILITY }, { "throughput", IPTOS_THROUGHPUT }, { NULL, -1 }, @@ -1435,8 +1450,10 @@ getproxypass(const char *proxyuser, const char *proxyhost) snprintf(prompt, sizeof(prompt), "Proxy password for %s@%s: ", proxyuser, proxyhost); +#ifndef WIN32_FIXME if (readpassphrase(prompt, pw, sizeof(pw), RPP_REQUIRE_TTY) == NULL) errx(1, "Unable to read proxy passphrase"); +#endif return (pw); } diff --git a/regress/pesterTests/PlatformAbstractLayer.psm1 b/regress/pesterTests/PlatformAbstractLayer.psm1 new file mode 100644 index 000000000..8b5d66396 --- /dev/null +++ b/regress/pesterTests/PlatformAbstractLayer.psm1 @@ -0,0 +1,361 @@ +#Abstract layer +Enum MachineRole { + Client + Server +} + +Enum Protocol +{ + WSMAN + SSH +} + +Enum PlatformType { + Windows + Linux + OSX +} + +function Set-Platform { + # Use the .NET Core APIs to determine the current platform; if a runtime + # exception is thrown, we are on FullCLR, not .NET Core. + try { + $Runtime = [System.Runtime.InteropServices.RuntimeInformation] + $OSPlatform = [System.Runtime.InteropServices.OSPlatform] + + $IsLinux = $Runtime::IsOSPlatform($OSPlatform::Linux) + $IsOSX = $Runtime::IsOSPlatform($OSPlatform::OSX) + $IsWindows = $Runtime::IsOSPlatform($OSPlatform::Windows) + } catch { + try { + $IsLinux = $false + $IsOSX = $false + $IsWindows = $true + } + catch { } + } + if($IsOSX) { + [PlatformType]::OSX + } elseif($IsLinux) { + [PlatformType]::Linux + } else { + [PlatformType]::Windows + } +} + +function Is-CoreCLR { + # Use the .NET Core APIs to determine the current platform; if a runtime + # exception is thrown, we are on FullCLR, not .NET Core. + try { + $Runtime = [System.Runtime.InteropServices.RuntimeInformation] + $IsCoreCLR = $true + } catch { + try { + $IsCoreCLR = $false + } + catch { } + } + if($IsCoreCLR) + { + $true + } + $false +} + +Class Machine +{ + [string] $MachineName = $env:COMPUTERNAME + [MachineRole] $Role = [MachineRole]::Client + [PlatformType] $Platform + [boolean] $IsCoreCLR + + #Members on server role + [string []] $PublicHostKeyPaths + [string []] $PrivateHostKeyPaths + [string] $localAdminUserName = "localadmin" + [string] $localAdminPassword = "Bull_dog1" + [string] $localAdminAuthorizedKeyPath + [System.Security.SecureString] $password + $preLatfpSetting + $localUserprofilePath + + #Members on client role + [string []] $clientPrivateKeyPaths + [string []] $clientPublicKeyPaths + [string] $ClientKeyDirectory + [string] $knownHostOfCurrentUser + [string] $OpenSSHdir = $PSScriptRoot + [string] $ToolsPath = "$env:ProgramData\chocolatey\lib\sysinternals\tools" + + Machine() { + $this.Platform = Set-Platform + $this.IsCoreCLR = Is-CoreCLR + $this.InitializeClient() + $this.InitializeServer() + } + + Machine ([MachineRole] $r) { + $this.Platform = Set-Platform + $this.IsCoreCLR = Is-CoreCLR + $this.Role = $r + if($this.Role -eq [MachineRole]::Client) { + $this.InitializeClient() + } else { + $this.InitializeServer() + } + } + + [void] InitializeClient() { + $this.ClientKeyDirectory = join-path ($env:USERPROFILE) ".ssh" + if(-not (Test-path $this.ClientKeyDirectory -PathType Container)) + { + New-Item -Path $this.ClientKeyDirectory -ItemType Directory -Force -ErrorAction silentlycontinue + } + + Remove-Item -Path "$($this.ClientKeyDirectory)\*" -Force -ea silentlycontinue + + $this.knownHostOfCurrentUser = join-path ($env:USERPROFILE) ".ssh/known_hosts" + + if ($this.Platform -eq [PlatformType]::Windows) + { + $this.ToolsPath = "$env:ProgramData\chocolatey\lib\sysinternals\tools" + #download pstools + if ( -not (Test-Path (join-path $($this.ToolsPath) "psexec.exe" ))) { + $this.DownloadPStools() + } + } + + foreach($key in @("ed25519")) #@("rsa","dsa","ecdsa","ed25519") + { + $keyPath = "$($this.ClientKeyDirectory)\id_$key" + $this.clientPrivateKeyPaths += $keyPath + $this.clientPublicKeyPaths += "$keyPath.pub" + $str = ".\ssh-keygen -t $key -P """" -f $keyPath" + $this.RunCmd($str) + + } + } + + [void] InitializeServer() { + if ($this.Platform -eq [PlatformType]::Windows) + { + #Start-Service sshd + #load the profile to create the profile folder + $this.SetLocalAccountTokenFilterPolicy(1) + } + + $this.password = ConvertTo-SecureString -String $this.localAdminPassword -AsPlainText -Force + $this.AddAdminUser($this.localAdminUserName, $this.password) + + $this.SetupServerRemoting([Protocol]::WSMAN) + $this.localUserprofilePath = $this.GetUserProfileLocation($this) + $sshPath = join-path $($this.localUserprofilePath) ".ssh" + if(-not (Test-path $sshPath -PathType Container)) + { + New-Item -Path $sshPath -ItemType Directory -Force -ErrorAction silentlycontinue + } + $this.localAdminAuthorizedKeyPath = join-path $($this.localUserprofilePath) ".ssh/authorized_keys" + Remove-Item -Path $($this.localAdminAuthorizedKeyPath) -Force -ea silentlycontinue + + #Generate all host keys + .\ssh-keygen -A + $this.PublicHostKeyPaths = @("$psscriptroot\ssh_host_ed25519_key.pub") + # @("$psscriptroot\ssh_host_rsa_key.pub","$psscriptroot\ssh_host_dsa_key.pub","$psscriptroot\ssh_host_ecdsa_key.pub","$psscriptroot\ssh_host_ed25519_key.pub") + $this.PrivateHostKeyPaths = @("$psscriptroot\ssh_host_ed25519_key") + # @("$psscriptroot\ssh_host_rsa_key","$psscriptroot\ssh_host_dsa_key","$psscriptroot\ssh_host_ecdsa_key","$psscriptroot\ssh_host_ed25519_key") + } + + [void] SetupClient([Machine] $server) { + #add the host keys known host on client + + if( -not (Test-Path $($this.knownHostOfCurrentUser ) ) ) + { + $null = New-item -path $($this.knownHostOfCurrentUser) -force + } + foreach($keypath in $server.PublicHostKeyPaths) + { + $this.SetKeys($($server.MachineName), $keypath, $($this.knownHostOfCurrentUser)) + } + } + + [void] SetupServerRemoting([Protocol] $protocol) { + if ($this.Platform -eq [PlatformType]::Windows) + { + switch($protocol ) + { + ([Protocol]::SSH) { + $env:Path = "$env:Path;$PSScriptRoot" + Restart-Service sshd + } + ([Protocol]::WSMAN) { + if( (Get-ComputerInfo).osproductType -notcontains 'Server' ) + { + Enable-PSRemoting -Force + } + } + default { + } + } + } + } + + [void] SetupServer([Machine] $client) { + if( -not (Test-Path $($this.localAdminAuthorizedKeyPath ) ) ) + { + $null = New-item -path $($this.localAdminAuthorizedKeyPath) -force + } + + foreach($publicKeyPath in $client.clientPublicKeyPaths) + { + $this.SetKeys($null, $publicKeyPath, $($this.localAdminAuthorizedKeyPath)) + } + } + + [void] CleanupServer() { + Remove-Item -Path $this.localAdminAuthorizedKeyPath -Force -ea silentlycontinue + if ( $this.Platform -eq [PlatformType]::Windows ) + { + $this.CleanupLocalAccountTokenFilterPolicy() + } + } + + [void] CleanupClient() { + Remove-Item -Path "$this.clientKeyPath\*" -Force -ea silentlycontinue + } + + [void] RunCmd($Str) { + if ($this.Platform -eq [PlatformType]::Windows) + { + cmd /c $Str + } + } + + [void] AddAdminUser($UserName, $password) { + if ( $this.Platform -eq [PlatformType]::Windows ) { + $a = Get-LocalUser -Name $UserName -ErrorAction Ignore + if ($a -eq $null) + { + $a = New-LocalUser -Name $UserName -Password $password -AccountNeverExpires -PasswordNeverExpires -UserMayNotChangePassword + } + + if((Get-LocalGroupMember -SID s-1-5-32-544 -Member $a -ErrorAction Ignore ) -eq $null) + { + Add-LocalGroupMember -SID s-1-5-32-544 -Member $a + } + } else { + #Todo add local user and add it to administrators group on linux + #Todo: get $localUserprofilePath + } + } + + #Set LocalAccountTokenFilterPolicy + [void] SetLocalAccountTokenFilterPolicy($setting) { + $path = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\system" + #load the profile to create the profile folder + $this.preLatfpSetting = get-ItemProperty -Path $path -Name LocalAccountTokenFilterPolicy -ErrorAction Ignore + if( $this.preLatfpSetting -eq $null) + { + New-ItemProperty -Path $path -Name LocalAccountTokenFilterPolicy -Value $setting -PropertyType DWord + } + else + { + Set-ItemProperty -Path $path -Name LocalAccountTokenFilterPolicy -Value $setting + } + } + + [void] CleanupLocalAccountTokenFilterPolicy() { + if($this.preLatfpSetting -eq $null) + { + Remove-ItemProperty -Path HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\system -Name LocalAccountTokenFilterPolicy -Force -ErrorAction SilentlyContinue + } + else + { + Set-ItemProperty -Path HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\system -Name LocalAccountTokenFilterPolicy -Value $this.preLatfpSetting.LocalAccountTokenFilterPolicy + } + } + + [void] SecureHostKeys([string[]] $keys) { + if ( $this.Platform -eq [PlatformType]::Windows ) + { + #TODO: Remove the path to OpenSSHDir from the string link + #Secure host-keys with psexec + foreach($key in $keys) { + & "$($this.ToolsPath)\psexec" -accepteula -nobanner -i -s -w $($this.OpenSSHdir) cmd.exe /c "ssh-add.exe $key" + } + } + } + + [void] CleanupHostKeys() { + if ( $this.Platform -eq [PlatformType]::Windows ) + { + & "$($this.ToolsPath)\psexec" -accepteula -nobanner -i -s -w $($this.OpenSSHdir) cmd.exe /c "ssh-add.exe -D" + } + } + + [string] GetUserProfileLocation([Machine] $remote ) { + #load the profile to create the profile folder + $pscreds = [System.Management.Automation.PSCredential]::new($($remote.MachineName) + "\" + $($remote.localAdminUserName), $($remote.password)) + $ret = Invoke-Command -Credential $pscreds -ComputerName $($remote.MachineName) -command {$env:userprofile} + return $ret + } + + [void] UnzipFile($argVar, $targetondisk ) { + $shell_app=new-object -com shell.application + $zip_file = $shell_app.namespace($argVar) + Write-Host "Uncompressing zip file to $($targetondisk)" -ForegroundColor Cyan + $destination = $shell_app.namespace($targetondisk) + $destination.Copyhere($zip_file.items(), 0x10) + $shell_app = $null + } + + [void] DownloadPStools() + { + $machinePath = [Environment]::GetEnvironmentVariable('Path', 'MACHINE') + $newMachineEnvironmentPath = $machinePath + # Install chocolatey + $chocolateyPath = "$env:AllUsersProfile\chocolatey\bin" + if(Get-Command "choco" -ErrorAction SilentlyContinue) + { + Write-Information -MessageData "Chocolatey is already installed. Skipping installation." + } + else + { + Write-Information -MessageData "Chocolatey not present. Installing chocolatey." + Invoke-Expression ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1')) + + if (-not ($machinePath.ToLower().Contains($chocolateyPath.ToLower()))) + { + Write-Information -MessageData "Adding $chocolateyPath to Path environment variable" + $newMachineEnvironmentPath += ";$chocolateyPath" + $env:Path += ";$chocolateyPath" + } + else + { + Write-Information -MessageData "$chocolateyPath already present in Path environment variable" + } + } + + if ( -not (Test-Path $($this.ToolsPath) ) ) { + Write-Information -MessageData "sysinternals not present. Installing sysinternals." + choco install sysinternals -y + } + else + { + Write-Information -MessageData "sysinternals present. Skipping installation." + } + } + + [void] SetKeys($Hostnames, $keyPath, $Path) { + if($Hostnames -ne $null) + { + foreach ($hostname in $Hostnames) + { + ($hostname + " " + (Get-Content $keyPath)) | Out-File -Append $Path -Encoding ascii + } + } + else + { + Get-Content $keyPath | Out-File -Append $Path -Encoding ascii + } + } +} diff --git a/regress/pesterTests/PortForwarding.Tests.ps1 b/regress/pesterTests/PortForwarding.Tests.ps1 new file mode 100644 index 000000000..4a2eb32bd --- /dev/null +++ b/regress/pesterTests/PortForwarding.Tests.ps1 @@ -0,0 +1,56 @@ +using module .\PlatformAbstractLayer.psm1 + +Describe "Tests for portforwarding" -Tags "CI" { + BeforeAll { + $fileName = "test.txt" + $filePath = Join-Path ${TestDrive} $fileName + + [Machine] $client = [Machine]::new([MachineRole]::Client) + [Machine] $server = [Machine]::new([MachineRole]::Server) + $client.SetupClient($server) + $server.SetupServer($client) + + $server.SecureHostKeys($server.PrivateHostKeyPaths) + $server.SetupServerRemoting([Protocol]::WSMAN) + #setup single signon + .\ssh-add.exe $client.clientPrivateKeyPaths[0] + Remove-Item -Path $filePath -Force -ea silentlycontinue + + $testData = @( + @{ + Title = "Local port forwarding" + Options = "-L 5432:127.0.0.1:47001" + Port = 5432 + + }, + @{ + Title = "Remote port forwarding" + Options = "-R 5432:127.0.0.1:47001" + Port = 5432 + } + ) + } + + AfterAll { + #cleanup single signon + .\ssh-add.exe -D + $Server.CleanupHostKeys() + $client.CleanupClient() + $server.CleanupServer() + } + + AfterEach { + Remove-Item -Path $filePath -Force -ea silentlycontinue + } + + It '' -TestCases:$testData { + param([string]$Title, $Options, $port) + + $str = ".\ssh $($Options) $($server.localAdminUserName)@$($server.MachineName) powershell.exe Test-WSMan -computer 127.0.0.1 -port $port > $filePath" + $client.RunCmd($str) + #validate file content. + $content = Get-Content $filePath + $content -like "wsmid*" | Should Not Be $null + } + +} diff --git a/regress/pesterTests/PowerShell.SSH.Tests.ps1 b/regress/pesterTests/PowerShell.SSH.Tests.ps1 new file mode 100644 index 000000000..4e87200c4 --- /dev/null +++ b/regress/pesterTests/PowerShell.SSH.Tests.ps1 @@ -0,0 +1,83 @@ +using module .\PlatformAbstractLayer.psm1 + +Describe "Tests for powershell over ssh" -Tags "Scenario" { + BeforeAll { + $defaultParamValues = $PSDefaultParameterValues.Clone() + #Skip on windows powershell. this feature only supported in powershell core from git + #due to known issue, these tests need to be disabled. + #if ($psversiontable.GitCommitId -eq $null) + if ($true) + { + $PSDefaultParameterValues["It:Skip"] = $true + } + + [Machine] $client = [Machine]::new([MachineRole]::Client) + [Machine] $server = [Machine]::new([MachineRole]::Server) + $client.SetupClient($server) + $server.SetupServer($client) + $server.SetupServerRemoting([Protocol]::SSH) + } + AfterAll { + $global:PSDefaultParameterValues = $defaultParamValues + $client.CleanupClient() + $server.CleanupServer() + } + + Context "Key based authentication with KeyFilePath. Key is Secured in ssh-agenton server" { + BeforeAll { + $server.SecureHostKeys($server.PrivateHostKeyPaths) + $identifyFile = $client.clientPrivateKeyPaths[0] + } + + AfterAll { + $server.CleanupHostKeys() + } + It 'Key is Secured in ssh-agenton server' { + $session = New-PSSession -HostName $server.MachineName -UserName $server.localAdminUserName -KeyFilePath $identifyFile + #$pscreds = [System.Management.Automation.PSCredential]::new($($server.MachineName) + "\" + $($server.localAdminUserName), $($server.password)) + #$session = New-PSSession -Credential $pscreds -ComputerName $($server.MachineName) + $ret = Invoke-Command $session -command {$env:computername} + $ret | Should be $server.MachineName + } + } + + #this context only run on windows + Context "Single signon and host keys are secured in ssh-agent" { + BeforeAll { + $server.SecureHostKeys($server.PrivateHostKeyPaths) + $identifyFile = $client.clientPrivateKeyPaths[0] + #setup single signon + .\ssh-add.exe $identifyFile + } + + AfterAll { + $server.CleanupHostKeys() + + #cleanup single signon + .\ssh-add.exe -D + } + + It 'Single signon and host keys are secured in ssh-agent' { + #$session = New-PSSession -HostName $server.MachineName -UserName $server.localAdminUserName + $pscreds = [System.Management.Automation.PSCredential]::new($($server.MachineName) + "\" + $($server.localAdminUserName), $($server.password)) + $session = New-PSSession -Credential $pscreds -ComputerName $($server.MachineName) + $ret = Invoke-Command $session -command {$env:computername} + $ret | Should be $server.MachineName + } + } + + Context "Key based authentication with KeyFilePath. Host keys are not secured on server" { + BeforeAll { + $identifyFile = $client.clientPrivateKeyPaths[0] + } + + It 'Key based authentication with KeyFilePath. Host keys are not secured on server' { + $session = New-PSSession -HostName $server.MachineName -UserName $server.localAdminUserName -KeyFilePath $identifyFile + #$pscreds = [System.Management.Automation.PSCredential]::new($($server.MachineName) + "\" + $($server.localAdminUserName), $($server.password)) + #$session = New-PSSession -Credential $pscreds -ComputerName $($server.MachineName) + $ret = Invoke-Command $session -command {$env:computername} + $ret | Should be $server.MachineName + } + } +} + diff --git a/regress/pesterTests/SCP.Tests.ps1 b/regress/pesterTests/SCP.Tests.ps1 new file mode 100644 index 000000000..b510df8d8 --- /dev/null +++ b/regress/pesterTests/SCP.Tests.ps1 @@ -0,0 +1,214 @@ +using module .\PlatformAbstractLayer.psm1 + +#covered -i -p -q -r -v -c -S -C +#todo: -F, -l and -P should be tested over the network +Describe "Tests for scp command" -Tags "CI" { + BeforeAll { + $fileName1 = "test.txt" + $fileName2 = "test2.txt" + $SourceDirName = "SourceDir" + $SourceDir = Join-Path ${TestDrive} $SourceDirName + $SourceFilePath = Join-Path $SourceDir $fileName1 + $DestinationDir = Join-Path ${TestDrive} "DestDir" + $DestinationFilePath = Join-Path $DestinationDir $fileName1 + $NestedSourceDir= Join-Path $SourceDir "nested" + $NestedSourceFilePath = Join-Path $NestedSourceDir $fileName2 + $null = New-Item $SourceDir -ItemType directory -Force + $null = New-Item $NestedSourceDir -ItemType directory -Force + $null = New-item -path $SourceFilePath -force + $null = New-item -path $NestedSourceFilePath -force + "Test content111" | Set-content -Path $SourceFilePath + "Test content in nested dir" | Set-content -Path $NestedSourceFilePath + $null = New-Item $DestinationDir -ItemType directory -Force + + [Machine] $client = [Machine]::new([MachineRole]::Client) + [Machine] $server = [Machine]::new([MachineRole]::Server) + $client.SetupClient($server) + $server.SetupServer($client) + + $testData = @( + <# known issue 340 + @{ + Title = 'Simple copy local file to local file' + Source = $SourceFilePath + Destination = $DestinationFilePath + },#> + @{ + Title = 'Simple copy local file to remote file' + Source = $SourceFilePath + Destination = "$($server.localAdminUserName)@$($server.MachineName):$DestinationFilePath" + }, + @{ + Title = 'Simple copy remote file to local file' + Source = "$($server.localAdminUserName)@$($server.MachineName):$SourceFilePath" + Destination = $DestinationFilePath + }, + <# known issue 340 + @{ + Title = 'Simple copy local file to local dir' + Source = $SourceFilePath + Destination = $DestinationDir + },#> + @{ + Title = 'simple copy local file to remote dir' + Source = $SourceFilePath + Destination = "$($server.localAdminUserName)@$($server.MachineName):$DestinationDir" + }, + @{ + Title = 'simple copy remote file to local dir' + Source = "$($server.localAdminUserName)@$($server.MachineName):$SourceFilePath" + Destination = $DestinationDir + } + ) + + $testData1 = @( + @{ + Title = 'copy from local dir to remote dir' + Source = $sourceDir + Destination = "$($server.localAdminUserName)@$($server.MachineName):$DestinationDir" + }, + @{ + Title = 'copy from local dir to local dir' + Source = $sourceDir + Destination = $DestinationDir + }, + @{ + Title = 'copy from remote dir to local dir' + Source = "$($server.localAdminUserName)@$($server.MachineName):$sourceDir" + Destination = $DestinationDir + } + ) + } + AfterAll { + + $client.CleanupClient() + $server.CleanupServer() + + Get-Item $SourceDir | Remove-Item -Recurse -Force -ea silentlycontinue + Get-Item $DestinationDir | Remove-Item -Recurse -Force -ea silentlycontinue + } + + BeforeEach { + $null = New-Item $DestinationDir -ItemType directory -Force + } + + AfterEach { + Get-ChildItem $DestinationDir -Recurse -Directory | Remove-Item -Recurse -Force -ea silentlycontinue + } + + <#Context "SCP usage" { + It 'SCP usage' { + #TODO: usage output does not redirect to file + } + }#> + + #this context only run on windows + Context "Key is Secured in ssh-agent on server" { + BeforeAll { + $Server.SecureHostKeys($server.PrivateHostKeyPaths) + $identifyFile = $client.clientPrivateKeyPaths[0] + } + + AfterAll { + $Server.CleanupHostKeys() + } + + It 'File Copy with -i option: <Title> ' -TestCases:$testData { + param([string]$Title, $Source, $Destination) + .\scp -i $identifyFile $Source $Destination + #validate file content. DestPath is the path to the file. + $equal = @(Compare-Object (Get-ChildItem -path $SourceFilePath) (Get-ChildItem -path $DestinationFilePath) -Property Name, Length).Length -eq 0 + $equal | Should Be $true + } + + <#It 'Directory recursive Copy with -i option: <Title> ' -TestCases:$testData1 { + param([string]$Title, $Source, $Destination) + + .\scp -r -i $identifyFile $Source $Destination + + $equal = @(Compare-Object (Get-Item -path $SourceDir ) (Get-Item -path (join-path $DestinationDir $SourceDirName) ) -Property Name, Length).Length -eq 0 + $equal | Should Be $true + + #known issue 364 + #$equal = @(Compare-Object (Get-ChildItem -Recurse -path $SourceDir) (Get-ChildItem -Recurse -path (join-path $DestinationDir $SourceDirName) ) -Property Name, Length).Length -eq 0 + #$equal | Should Be $true + }#> + } + + #this context only run on windows + Context "Single signon with keys -p -v -c option Secured in ssh-agent" { + BeforeAll { + $Server.SecureHostKeys($server.PrivateHostKeyPaths) + $identifyFile = $client.clientPrivateKeyPaths[0] + #setup single signon + .\ssh-add.exe $identifyFile + } + + AfterAll { + $Server.CleanupHostKeys() + + #cleanup single signon + .\ssh-add.exe -D + } + + It 'File Copy with -S option (positive)' { + .\scp -S .\ssh.exe $SourceFilePath "$($server.localAdminUserName)@$($server.MachineName):$DestinationFilePath" + #validate file content. DestPath is the path to the file. + $equal = @(Compare-Object (Get-ChildItem -path $SourceFilePath) (Get-ChildItem -path $DestinationFilePath) -Property Name, Length).Length -eq 0 #todo: add LastWriteTime in comparison when issue is fixed + $equal | Should Be $true + } + + <#It 'File Copy with -p -c -v option: <Title> ' -TestCases:$testData { + param([string]$Title, $Source, $Destination) + + .\scp -p -c aes128-ctr -C $Source $Destination #Todo: add -v after it is supported. + #validate file content. DestPath is the path to the file. + $equal = @(Compare-Object (Get-ChildItem -path $SourceFilePath) (Get-ChildItem -path $DestinationFilePath) -Property Name, Length).Length -eq 0 #todo: add LastWriteTime in comparison when issue is fixed + $equal | Should Be $true + }#> + + <# known issue 369 + It 'Directory recursive Copy with -v option: <Title> ' -TestCases:$testData1 { + param([string]$Title, $Source, $Destination) + + .\scp -r -p $Source $Destination + + $equal = @(Compare-Object (Get-Item -path $SourceDir ) (Get-Item -path (join-path $DestinationDir $SourceDirName) ) -Property Name, Length, LastWriteTime).Length -eq 0 + $equal | Should Be $true + + #known issue 364 + #$equal = @(Compare-Object (Get-ChildItem -Recurse -path $SourceDir) (Get-ChildItem -Recurse -path (join-path $DestinationDir $SourceDirName) ) -Property Name, Length, LastWriteTime).Length -eq 0 + #$equal | Should Be $true + }#> + } + + Context "Key based authentication with -i -C -q options. host keys are not secured on server" { + BeforeAll { + $identifyFile = $client.clientPrivateKeyPaths[0] + } + + It 'File Copy with -i -C -q options: <Title> ' -TestCases:$testData{ + param([string]$Title, $Source, $Destination) + + .\scp -i $identifyFile -C -q $Source $Destination + #validate file content. DestPath is the path to the file. + $equal = @(Compare-Object (Get-ChildItem -path $SourceFilePath) (Get-ChildItem -path $DestinationFilePath) -Property Name, Length).Length -eq 0 # need to validate LastWriteTime after issue 356 is fixed. + $equal | Should Be $true + } + + + <#It 'Directory recursive Copy with -i and -q options: <Title> ' -TestCases:$testData1 { + param([string]$Title, $Source, $Destination) + + .\scp -i $identifyFile -r -q $Source $Destination + $equal = @(Compare-Object (Get-Item -path $SourceDir ) (Get-Item -path (join-path $DestinationDir $SourceDirName) ) -Property Name, Length).Length -eq 0 + $equal | Should Be $true + + #known issue 364 + #$equal = @(Compare-Object (Get-ChildItem -Recurse -path $SourceDir) (Get-ChildItem -Recurse -path (join-path $DestinationDir $SourceDirName) ) -Property Name, Length).Length -eq 0 + #$equal | Should Be $true + }#> + } + +} + diff --git a/regress/pesterTests/SSH.Tests.ps1 b/regress/pesterTests/SSH.Tests.ps1 new file mode 100644 index 000000000..0b3999064 --- /dev/null +++ b/regress/pesterTests/SSH.Tests.ps1 @@ -0,0 +1,139 @@ +using module .\PlatformAbstractLayer.psm1 + +#covered -i -q -v -l -c -C +#todo: -S -F -V -e +Describe "Tests for ssh command" -Tags "CI" { + BeforeAll { + $fileName = "test.txt" + $filePath = Join-Path ${TestDrive} $fileName + + [Machine] $client = [Machine]::new([MachineRole]::Client) + [Machine] $server = [Machine]::new([MachineRole]::Server) + $client.SetupClient($server) + $server.SetupServer($client) + + $testData = @( + @{ + Title = 'Simple logon -v option'; + LogonStr = "$($server.localAdminUserName)@$($server.MachineName)" + Options = "-v" + }, + @{ + Title = 'Simple logon using -C -l option' + LogonStr = $server.MachineName + Options = "-C -l $($server.localAdminUserName)" + } + ) + + $testData1 = @( + @{ + Title = "logon using -i -q option" + LogonStr = "$($server.localAdminUserName)@$($server.MachineName)" + Options = '-i $identifyFile -q' + }, + @{ + Title = "logon using -i -v option" + LogonStr = "$($server.localAdminUserName)@$($server.MachineName)" + Options = '-i $identifyFile -v' + }, + @{ + Title = "logon using -i -c option" + LogonStr = "$($server.localAdminUserName)@$($server.MachineName)" + Options = '-i $identifyFile -c aes256-ctr' + }, + <# -V does not redirect to file + @{ + Title = "logon using -i -V option" + LogonStr = "$($server.localAdminUserName)@$($server.MachineName)" + Options = '-i $identifyFile -V' + SkipVerification = $true + },#> + @{ + Title = 'logon using -i -l option' + LogonStr = $server.MachineName + Options = '-i $identifyFile -l $($server.localAdminUserName)' + } + ) + + } + + AfterAll { + $client.CleanupClient() + $server.CleanupServer() + } + + Context "Key is not secured in ssh-agent on server" { + BeforeAll { + $identifyFile = $client.clientPrivateKeyPaths[0] + Remove-Item -Path $filePath -Force -ea silentlycontinue + } + + AfterEach { + Remove-Item -Path $filePath -Force -ea silentlycontinue + } + + It '<Title>' -TestCases:$testData1 { + param([string]$Title, $LogonStr, $Options, $SkipVerification = $false) + + $str = $ExecutionContext.InvokeCommand.ExpandString(".\ssh $($Options) $($LogonStr) hostname > $filePath") + $client.RunCmd($str) + #validate file content. + Get-Content $filePath | Should be $server.MachineName + } + } + + Context "Key is secured in ssh-agent" { + BeforeAll { + $server.SecureHostKeys($server.PrivateHostKeyPaths) + $identifyFile = $client.clientPrivateKeyPaths[0] + Remove-Item -Path $filePath -Force -ea silentlycontinue + } + + AfterAll { + $Server.CleanupHostKeys() + } + + AfterEach { + Remove-Item -Path $filePath -Force -ea silentlycontinue + } + + It '<Title>' -TestCases:$testData1 { + param([string]$Title, $LogonStr, $Options, $SkipVerification = $false) + + $str = $ExecutionContext.InvokeCommand.ExpandString(".\ssh $Options $LogonStr hostname > $filePath") + $client.RunCmd($str) + #validate file content. + Get-Content $filePath | Should be $server.MachineName + } + } + + Context "Single signon on client and keys secured in ssh-agent on server" { + BeforeAll { + $Server.SecureHostKeys($server.PrivateHostKeyPaths) + $identifyFile = $client.clientPrivateKeyPaths[0] + #setup single signon + .\ssh-add.exe $identifyFile + Remove-Item -Path $filePath -Force -ea silentlycontinue + } + + AfterAll { + $Server.CleanupHostKeys() + + #cleanup single signon + .\ssh-add.exe -D + } + + AfterEach { + Remove-Item -Path $filePath -Force -ea silentlycontinue + } + + It '<Title>' -TestCases:$testData { + param([string]$Title, $LogonStr, $Options) + + $str = ".\ssh $($Options) $($LogonStr) hostname > $filePath" + $client.RunCmd($str) + #validate file content. + Get-Content $filePath | Should be $server.MachineName + } + } +} diff --git a/regress/setuid-allowed.c b/regress/setuid-allowed.c index 7a0527fd0..3fcbae8ec 100644 --- a/regress/setuid-allowed.c +++ b/regress/setuid-allowed.c @@ -26,6 +26,10 @@ #include <string.h> #include <errno.h> +#ifdef WIN32_FIXME +void debug3(const char *fmt,...) {/*stub*/} +#endif +void static void usage(void) { diff --git a/regress/unittests/hostkeys/test_iterate.c b/regress/unittests/hostkeys/test_iterate.c index 2eaaf063a..95f149f9d 100644 --- a/regress/unittests/hostkeys/test_iterate.c +++ b/regress/unittests/hostkeys/test_iterate.c @@ -61,9 +61,10 @@ check(struct hostkey_foreach_line *l, void *_ctx) test_subtest_info("entry %zu/%zu, file line %ld", ctx->i + 1, ctx->nexpected, l->linenum); - for (;;) { - ASSERT_SIZE_T_LT(ctx->i, ctx->nexpected); +#ifndef WIN32_FIXME + //ASSERT_SIZE_T_LT(ctx->i, ctx->nexpected); +#endif expected = ctx->expected + ctx->i++; /* If we are matching host/IP then skip entries that don't */ if (!matching) @@ -113,6 +114,7 @@ check(struct hostkey_foreach_line *l, void *_ctx) UPDATE_MATCH_STATUS(match_ipv6); ASSERT_PTR_NE(l->path, NULL); /* Don't care about path */ +#ifndef WIN32_FIXME ASSERT_LONG_LONG_EQ(l->linenum, expected->l.linenum); ASSERT_U_INT_EQ(l->status, expected_status); ASSERT_U_INT_EQ(l->match, expected_match); @@ -138,6 +140,7 @@ check(struct hostkey_foreach_line *l, void *_ctx) } if (parse_key && !(l->comment == NULL && expected->l.comment == NULL)) ASSERT_STRING_EQ(l->comment, expected->l.comment); +#endif return 0; } @@ -282,6 +285,7 @@ struct expected expected_full[] = { NULL, /* filled at runtime */ "DSA #2", } }, +#ifndef WIN32_FIXME { "ecdsa_2.pub" , -1, -1, HKF_MATCH_HOST, 0, HKF_MATCH_IP, HKF_MATCH_IP, -1, { NULL, 10, @@ -295,6 +299,7 @@ struct expected expected_full[] = { NULL, /* filled at runtime */ "ECDSA #2", } }, +#endif { "ed25519_2.pub" , -1, -1, HKF_MATCH_HOST, 0, HKF_MATCH_IP, HKF_MATCH_IP, -1, { NULL, 11, @@ -807,6 +812,7 @@ struct expected expected_full[] = { NULL, /* filled at runtime */ "ECDSA #4", } }, +#ifndef WIN32_FIXME { "dsa_4.pub" , -1, -1, HKF_MATCH_HOST, HKF_MATCH_HOST, 0, 0, -1, { NULL, 50, @@ -820,6 +826,7 @@ struct expected expected_full[] = { NULL, /* filled at runtime */ "DSA #4", } }, +#endif { NULL, -1, -1, 0, 0, 0, 0, -1, { NULL, 51, diff --git a/regress/unittests/kex/test_kex.c b/regress/unittests/kex/test_kex.c index 6e5999bb9..e7221e015 100644 --- a/regress/unittests/kex/test_kex.c +++ b/regress/unittests/kex/test_kex.c @@ -145,10 +145,12 @@ do_kex_with_key(char *kex, int keytype, int bits) sshbuf_free(state); ASSERT_PTR_NE(server2->kex, NULL); /* XXX we need to set the callbacks */ +#ifdef WITH_OPENSSL server2->kex->kex[KEX_DH_GRP1_SHA1] = kexdh_server; server2->kex->kex[KEX_DH_GRP14_SHA1] = kexdh_server; server2->kex->kex[KEX_DH_GEX_SHA1] = kexgex_server; server2->kex->kex[KEX_DH_GEX_SHA256] = kexgex_server; +#endif #ifdef OPENSSL_HAS_ECC server2->kex->kex[KEX_ECDH_SHA2] = kexecdh_server; #endif @@ -193,7 +195,9 @@ kex_tests(void) #ifdef OPENSSL_HAS_ECC do_kex("ecdh-sha2-nistp256"); do_kex("ecdh-sha2-nistp384"); +#ifndef WIN32_FIXME do_kex("ecdh-sha2-nistp521"); +#endif #endif do_kex("diffie-hellman-group-exchange-sha256"); do_kex("diffie-hellman-group-exchange-sha1"); diff --git a/regress/unittests/sshbuf/tests.c b/regress/unittests/sshbuf/tests.c index 1557e4342..21495b6b1 100644 --- a/regress/unittests/sshbuf/tests.c +++ b/regress/unittests/sshbuf/tests.c @@ -20,9 +20,13 @@ tests(void) { sshbuf_tests(); sshbuf_getput_basic_tests(); +#ifdef WITH_OPENSSL sshbuf_getput_crypto_tests(); +#endif sshbuf_misc_tests(); sshbuf_fuzz_tests(); +#ifdef WITH_OPENSSL sshbuf_getput_fuzz_tests(); +#endif sshbuf_fixed(); } diff --git a/regress/unittests/sshkey/common.c b/regress/unittests/sshkey/common.c index b598f05cb..c8d5560b0 100644 --- a/regress/unittests/sshkey/common.c +++ b/regress/unittests/sshkey/common.c @@ -19,10 +19,12 @@ #include <string.h> #include <unistd.h> +#ifdef WITH_OPENSSL #include <openssl/bn.h> #include <openssl/rsa.h> #include <openssl/dsa.h> #include <openssl/objects.h> +#endif #ifdef OPENSSL_HAS_NISTP256 # include <openssl/ec.h> #endif @@ -70,6 +72,7 @@ load_text_file(const char *name) return ret; } +#ifdef WITH_OPENSSL BIGNUM * load_bignum(const char *name) { @@ -81,4 +84,4 @@ load_bignum(const char *name) sshbuf_free(buf); return ret; } - +#endif diff --git a/regress/unittests/sshkey/test_file.c b/regress/unittests/sshkey/test_file.c index 906491f2b..a47a9c10d 100644 --- a/regress/unittests/sshkey/test_file.c +++ b/regress/unittests/sshkey/test_file.c @@ -101,6 +101,7 @@ sshkey_file_tests(void) sshkey_free(k1); #endif +#ifdef WITH_OPENSSL TEST_START("parse RSA from private"); buf = load_file("rsa_1"); ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0); @@ -135,7 +136,7 @@ sshkey_file_tests(void) ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); sshkey_free(k2); TEST_DONE(); - +#ifndef WIN32_FIXME TEST_START("parse RSA from new-format w/ passphrase"); buf = load_file("rsa_n_pw"); ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, @@ -145,7 +146,7 @@ sshkey_file_tests(void) ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); sshkey_free(k2); TEST_DONE(); - +#endif TEST_START("load RSA from public"); ASSERT_INT_EQ(sshkey_load_public(test_data_file("rsa_1.pub"), &k2, NULL), 0); @@ -227,6 +228,7 @@ sshkey_file_tests(void) sshkey_free(k2); TEST_DONE(); +#ifndef WIN32_FIXME TEST_START("parse DSA from new-format w/ passphrase"); buf = load_file("dsa_n_pw"); ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, @@ -236,7 +238,7 @@ sshkey_file_tests(void) ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); sshkey_free(k2); TEST_DONE(); - +#endif TEST_START("load DSA from public"); ASSERT_INT_EQ(sshkey_load_public(test_data_file("dsa_1.pub"), &k2, NULL), 0); @@ -282,6 +284,7 @@ sshkey_file_tests(void) TEST_DONE(); sshkey_free(k1); +#endif #ifdef OPENSSL_HAS_ECC TEST_START("parse ECDSA from private"); @@ -324,7 +327,7 @@ sshkey_file_tests(void) ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); sshkey_free(k2); TEST_DONE(); - +#ifndef WIN32_FIXME TEST_START("parse ECDSA from new-format w/ passphrase"); buf = load_file("ecdsa_n_pw"); ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, @@ -334,7 +337,7 @@ sshkey_file_tests(void) ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); sshkey_free(k2); TEST_DONE(); - +#endif TEST_START("load ECDSA from public"); ASSERT_INT_EQ(sshkey_load_public(test_data_file("ecdsa_1.pub"), &k2, NULL), 0); @@ -381,7 +384,7 @@ sshkey_file_tests(void) sshkey_free(k1); #endif /* OPENSSL_HAS_ECC */ - +#ifndef WIN32_FIXME TEST_START("parse Ed25519 from private"); buf = load_file("ed25519_1"); ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0); @@ -448,5 +451,5 @@ sshkey_file_tests(void) sshkey_free(k1); sshbuf_free(pw); - +#endif } diff --git a/regress/unittests/sshkey/test_fuzz.c b/regress/unittests/sshkey/test_fuzz.c index 1f414e0ac..3f8879f25 100644 --- a/regress/unittests/sshkey/test_fuzz.c +++ b/regress/unittests/sshkey/test_fuzz.c @@ -269,7 +269,7 @@ sshkey_fuzz_tests(void) fuzz_cleanup(fuzz); TEST_DONE(); #endif - +#ifndef WIN32_FIXME TEST_START("fuzz Ed25519 private"); buf = load_file("ed25519_1"); fuzz = fuzz_begin(FUZZ_BASE64, sshbuf_mutable_ptr(buf), @@ -289,7 +289,7 @@ sshkey_fuzz_tests(void) sshbuf_free(fuzzed); fuzz_cleanup(fuzz); TEST_DONE(); - +#endif TEST_START("fuzz RSA public"); buf = load_file("rsa_1"); ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0); @@ -333,7 +333,7 @@ sshkey_fuzz_tests(void) sshkey_free(k1); TEST_DONE(); #endif - +#ifndef WIN32_FIXME TEST_START("fuzz Ed25519 public"); buf = load_file("ed25519_1"); ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0); @@ -347,7 +347,7 @@ sshkey_fuzz_tests(void) public_fuzz(k1); sshkey_free(k1); TEST_DONE(); - +#endif TEST_START("fuzz RSA sig"); buf = load_file("rsa_1"); ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0); @@ -389,7 +389,7 @@ sshkey_fuzz_tests(void) sshkey_free(k1); TEST_DONE(); #endif - +#ifndef WIN32_FIXME TEST_START("fuzz Ed25519 sig"); buf = load_file("ed25519_1"); ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0); @@ -397,7 +397,7 @@ sshkey_fuzz_tests(void) sig_fuzz(k1, NULL); sshkey_free(k1); TEST_DONE(); - +#endif /* XXX fuzz decoded new-format blobs too */ } diff --git a/regress/unittests/sshkey/test_sshkey.c b/regress/unittests/sshkey/test_sshkey.c index 1476dc2e3..7a987f6fa 100644 --- a/regress/unittests/sshkey/test_sshkey.c +++ b/regress/unittests/sshkey/test_sshkey.c @@ -193,6 +193,7 @@ sshkey_tests(void) sshkey_free(k1); TEST_DONE(); +#ifdef WITH_OPENSSL TEST_START("new/free KEY_RSA1"); k1 = sshkey_new(KEY_RSA1); ASSERT_PTR_NE(k1, NULL); @@ -221,6 +222,7 @@ sshkey_tests(void) ASSERT_PTR_EQ(k1->dsa->priv_key, NULL); sshkey_free(k1); TEST_DONE(); +#endif #ifdef OPENSSL_HAS_ECC TEST_START("new/free KEY_ECDSA"); @@ -240,6 +242,7 @@ sshkey_tests(void) sshkey_free(k1); TEST_DONE(); +#ifdef WITH_OPENSSL TEST_START("new_private KEY_RSA"); k1 = sshkey_new_private(KEY_RSA); ASSERT_PTR_NE(k1, NULL); @@ -308,7 +311,7 @@ sshkey_tests(void) ASSERT_PTR_NE(kd->dsa->g, NULL); ASSERT_PTR_NE(kd->dsa->priv_key, NULL); TEST_DONE(); - +#endif #ifdef OPENSSL_HAS_ECC TEST_START("generate KEY_ECDSA"); ASSERT_INT_EQ(sshkey_generate(KEY_ECDSA, 256, &ke), 0); @@ -327,6 +330,7 @@ sshkey_tests(void) ASSERT_PTR_NE(kf->ed25519_sk, NULL); TEST_DONE(); +#ifdef WITH_OPENSSL TEST_START("demote KEY_RSA"); ASSERT_INT_EQ(sshkey_demote(kr, &k1), 0); ASSERT_PTR_NE(k1, NULL); @@ -357,6 +361,7 @@ sshkey_tests(void) ASSERT_INT_EQ(sshkey_equal(kd, k1), 1); sshkey_free(k1); TEST_DONE(); +#endif #ifdef OPENSSL_HAS_ECC TEST_START("demote KEY_ECDSA"); @@ -424,7 +429,8 @@ sshkey_tests(void) #endif sshkey_free(kf); - TEST_START("certify key"); +#ifndef WIN32_FIXME + TEST_START("certify key"); ASSERT_INT_EQ(sshkey_load_public(test_data_file("ed25519_1.pub"), &k1, NULL), 0); k2 = get_private("ed25519_2"); @@ -466,6 +472,7 @@ sshkey_tests(void) sshkey_free(k3); sshbuf_reset(b); TEST_DONE(); +#endif TEST_START("sign and verify RSA"); k1 = get_private("rsa_1"); @@ -503,7 +510,9 @@ sshkey_tests(void) sshkey_free(k2); TEST_DONE(); + #ifdef OPENSSL_HAS_ECC +#ifndef WIN32_FIXME TEST_START("sign and verify ECDSA"); k1 = get_private("ecdsa_1"); ASSERT_INT_EQ(sshkey_load_public(test_data_file("ecdsa_2.pub"), &k2, @@ -512,7 +521,6 @@ sshkey_tests(void) sshkey_free(k1); sshkey_free(k2); TEST_DONE(); -#endif TEST_START("sign and verify ED25519"); k1 = get_private("ed25519_1"); @@ -537,5 +545,6 @@ sshkey_tests(void) sshkey_free(k3); sshbuf_free(b); TEST_DONE(); - +#endif +#endif } diff --git a/regress/unittests/sshkey/tests.c b/regress/unittests/sshkey/tests.c index 13f265cdb..1b89eb941 100644 --- a/regress/unittests/sshkey/tests.c +++ b/regress/unittests/sshkey/tests.c @@ -18,9 +18,10 @@ void sshkey_fuzz_tests(void); void tests(void) { +#ifdef WITH_OPENSSL OpenSSL_add_all_algorithms(); ERR_load_CRYPTO_strings(); - +#endif sshkey_tests(); sshkey_file_tests(); sshkey_fuzz_tests(); diff --git a/regress/unittests/test_helper/test_helper.c b/regress/unittests/test_helper/test_helper.c index 26ca26b5e..9e83e3079 100644 --- a/regress/unittests/test_helper/test_helper.c +++ b/regress/unittests/test_helper/test_helper.c @@ -116,6 +116,12 @@ static void *onerror_ctx = NULL; static const char *data_dir = NULL; static char subtest_info[512]; +#ifndef WIN32_FIXME +void fatal(const char *fmt,...) {/*stub*/} +void logit(const char *fmt,...) {/*stub*/} +void debug3(const char *fmt,...) {/*stub*/} +#endif + int main(int argc, char **argv) { diff --git a/regress/unittests/utf8/tests.c b/regress/unittests/utf8/tests.c index 31f9fe9c3..32c6171bc 100644 --- a/regress/unittests/utf8/tests.c +++ b/regress/unittests/utf8/tests.c @@ -59,8 +59,12 @@ tests(void) { char *loc; - TEST_START("utf8_setlocale"); - loc = setlocale(LC_CTYPE, "en_US.UTF-8"); + TEST_START("utf8_setlocale"); +#ifdef WIN32_FIXME + loc = setlocale(LC_CTYPE, "English"); +#else + loc = setlocale(LC_CTYPE, "en_US.UTF-8"); +#endif ASSERT_PTR_NE(loc, NULL); TEST_DONE(); @@ -70,14 +74,20 @@ tests(void) one("newline", "a\nb", -2, -2, -2, "a\nb"); one("cr", "a\rb", -2, -2, -2, "a\rb"); one("tab", "a\tb", -2, -2, -2, "a\tb"); +#ifndef WIN32_FIXME one("esc", "\033x", -2, -2, -2, "\\033x"); one("inv_badbyte", "\377x", -2, -2, -2, "\\377x"); one("inv_nocont", "\341x", -2, -2, -2, "\\341x"); one("inv_nolead", "a\200b", -2, -2, -2, "a\\200b"); +#endif one("sz_ascii", "1234567890123456", -2, -2, 16, "123456789012345"); +#ifndef WIN32_FIXME one("sz_esc", "123456789012\033", -2, -2, 16, "123456789012"); +#endif one("width_ascii", "123", 2, 2, -1, "12"); one("width_double", "a\343\201\201", 2, 1, -1, "a"); +#ifndef WIN32_FIXME one("double_fit", "a\343\201\201", 3, 3, 4, "a\343\201\201"); one("double_spc", "a\343\201\201", 4, 3, 4, "a\343\201\201"); +#endif } diff --git a/regress/unittests/win32compat/file_tests.c b/regress/unittests/win32compat/file_tests.c new file mode 100644 index 000000000..21d2a2e86 --- /dev/null +++ b/regress/unittests/win32compat/file_tests.c @@ -0,0 +1,250 @@ +/* +* Author: Manoj Ampalam <manoj.ampalam@microsoft.com> +*/ + +#include "includes.h" +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/select.h> +#include <unistd.h> +#include <fcntl.h> +#include "../test_helper/test_helper.h" + +#define SMALL_RECV_BUF_SIZE 128 + +#pragma warning(disable:4267) + +fd_set read_set, write_set, except_set; +struct timeval time_val; +char *send_buf, *recv_buf; +int ret, r, w; + +int unset_nonblock(int fd); + +int set_nonblock(int fd); + +void prep_input_buffer(char* buf, int size, int seed); + +void +file_blocking_io_tests() +{ + char* small_send_buf = "sample payload"; + char small_recv_buf[SMALL_RECV_BUF_SIZE]; + + TEST_START("Basic pipe()"); + int pipeio[2]; + ret = pipe(pipeio); + ASSERT_INT_EQ(ret, 0); + TEST_DONE(); + + TEST_START("pipe read and write"); + r = pipeio[0]; + w = pipeio[1]; + ret = write(r, small_send_buf, strlen(small_send_buf)); + ASSERT_INT_EQ(ret, -1); + ASSERT_INT_EQ(errno, EACCES); + ret = read(w, small_recv_buf, SMALL_RECV_BUF_SIZE); + ASSERT_INT_EQ(ret, -1); + ASSERT_INT_EQ(errno, EACCES); + ret = write(w, small_send_buf, strlen(small_send_buf)); + ASSERT_INT_EQ(ret, strlen(small_send_buf)); + ret = read(r, small_recv_buf, SMALL_RECV_BUF_SIZE); + ASSERT_INT_EQ(ret, strlen(small_send_buf)); + small_recv_buf[ret] = '\0'; + ASSERT_STRING_EQ(small_send_buf, small_recv_buf); + memset(small_recv_buf, 0, sizeof(small_recv_buf)); + TEST_DONE(); + + TEST_START("close pipe fds"); + ret = close(w); + ASSERT_INT_EQ(ret, 0); + ret = read(r, small_recv_buf, SMALL_RECV_BUF_SIZE); /* send on other side is closed*/ + ASSERT_INT_EQ(ret, 0); + ret = close(r); + ASSERT_INT_EQ(ret, 0); + TEST_DONE(); +} + +void file_simple_fileio() +{ + char* small_write_buf = "sample payload"; + char small_read_buf[SMALL_RECV_BUF_SIZE]; + + int f; + TEST_START("file io"); + f = open("tmp.txt", O_WRONLY | O_CREAT | O_TRUNC); + ASSERT_INT_NE(f, -1); + close(f); + f = open("tmp.txt", O_RDONLY); + ASSERT_INT_NE(f, -1); + struct stat st; + ret = fstat(f, &st); + ASSERT_INT_EQ(ret, 0); + ASSERT_INT_EQ(st.st_size, 0); + ret = read(f, small_read_buf, SMALL_RECV_BUF_SIZE); + ASSERT_INT_EQ(ret, 0); + close(f); + f = open("tmp.txt", O_WRONLY | O_CREAT | O_TRUNC); + ASSERT_INT_NE(f, -1); + ret = write(f, small_write_buf, strlen(small_write_buf)); + ASSERT_INT_EQ(ret, strlen(small_write_buf)); + close(f); + f = open("tmp.txt", O_RDONLY); + ASSERT_INT_NE(f, -1); + ret = fstat(f, &st); + ASSERT_INT_EQ(ret, 0); + ASSERT_INT_EQ(st.st_size, strlen(small_write_buf)); + ret = read(f, small_read_buf, SMALL_RECV_BUF_SIZE); + ASSERT_INT_EQ(ret, strlen(small_write_buf)); + small_read_buf[ret] = '\0'; + ASSERT_STRING_EQ(small_write_buf, small_read_buf); + ret = read(f, small_read_buf, SMALL_RECV_BUF_SIZE); + ASSERT_INT_EQ(ret, 0); + close(f); + TEST_DONE(); + + +} + +void +file_nonblocking_io_tests() +{ + char* small_send_buf = "sample payload"; + char small_recv_buf[SMALL_RECV_BUF_SIZE]; + + TEST_START("non blocking file io"); + int pipeio[2]; + ret = pipe(pipeio); + ASSERT_INT_EQ(ret, 0); + r = pipeio[0]; + w = pipeio[1]; + ret = set_nonblock(r); + ASSERT_INT_EQ(ret, 0); + ret = read(r, small_recv_buf, SMALL_RECV_BUF_SIZE); + ASSERT_INT_EQ(ret, -1); + ASSERT_INT_EQ(errno, EAGAIN); + ret = unset_nonblock(w); + ASSERT_INT_EQ(ret, 0); + ret = write(w, small_send_buf, strlen(small_send_buf)); + ASSERT_INT_EQ(ret, strlen(small_send_buf)); + ret = unset_nonblock(r); + ASSERT_INT_EQ(ret, 0); + ret = read(r, small_recv_buf, SMALL_RECV_BUF_SIZE); + ASSERT_INT_EQ(ret, strlen(small_send_buf)); + small_recv_buf[ret] = '\0'; + ASSERT_STRING_EQ(small_send_buf, small_recv_buf); + memset(small_recv_buf, 0, sizeof(small_recv_buf)); + send_buf = malloc(10 * 1024); + ASSERT_PTR_NE(send_buf, NULL); + ret = set_nonblock(w); + ASSERT_INT_EQ(ret, 0); + ret = 1; + while (ret > 0) { + ret = write(w, send_buf, 10 * 1024); + } + ASSERT_INT_EQ(ret, -1); + ASSERT_INT_EQ(errno, EAGAIN); + ret = close(r); + ASSERT_INT_EQ(ret, 0); + ret = close(w); + ASSERT_INT_EQ(ret, 0); + TEST_DONE(); + + free(send_buf); +} + +void +file_select_tests() { + int num_bytes = 1024 * 700; //700KB + int bytes_sent = 0; + int bytes_received = 0; + int seed = 326; + int eagain_results = 0; + + TEST_START("select on file fds"); + int pipeio[2]; + ret = pipe(pipeio); + ASSERT_INT_EQ(ret, 0); + r = pipeio[0]; + w = pipeio[1]; + ret = set_nonblock(w); + ASSERT_INT_EQ(ret, 0); + ret = set_nonblock(r); + ASSERT_INT_EQ(ret, 0); + send_buf = malloc(num_bytes); + recv_buf = malloc(num_bytes + 1); + ASSERT_PTR_NE(send_buf, NULL); + ASSERT_PTR_NE(recv_buf, NULL); + prep_input_buffer(send_buf, num_bytes, 17); + FD_ZERO(&read_set); + FD_ZERO(&write_set); + FD_SET(w, &write_set); + FD_SET(r, &read_set); + while (-1 != select(max(r, w) + 1, &read_set, &write_set, NULL, &time_val)) { + if (FD_ISSET(w, &write_set)) { + while ((bytes_sent < num_bytes) && ((ret = write(w, send_buf + bytes_sent, num_bytes - bytes_sent)) > 0)) + bytes_sent += ret; + if (bytes_sent < num_bytes) { + ASSERT_INT_EQ(ret, -1); + ASSERT_INT_EQ(errno, EAGAIN); + eagain_results++; + } + } + + if (FD_ISSET(r, &read_set)) { + while ((ret = read(r, recv_buf + bytes_received, num_bytes - bytes_received + 1)) > 0) + bytes_received += ret; + if (ret == 0) + break; + ASSERT_INT_EQ(ret, -1); + ASSERT_INT_EQ(errno, EAGAIN); + eagain_results++; + } + + if (bytes_sent < num_bytes) + FD_SET(w, &write_set); + else { + FD_CLR(w, &write_set); + ret = close(w); + ASSERT_INT_EQ(ret, 0); + } + FD_SET(r, &read_set); + } + + /*ensure that we hit send and recv paths that returned EAGAIN. Else it would not have touched the async paths*/ + /*if this assert is being hit, then num_bytes is too small. up it*/ + ASSERT_INT_GT(eagain_results, 0); + ASSERT_INT_EQ(bytes_sent, bytes_received); + ASSERT_INT_EQ(memcmp(send_buf, recv_buf, num_bytes), 0); + ret = close(r); + ASSERT_INT_EQ(ret, 0); + + free(send_buf); + free(recv_buf); + TEST_DONE(); + +} + +void console_io_test() +{ + char tmp[10]; + TEST_START("console io test"); + ret = read(STDIN_FILENO, tmp, 10); + ret = write(STDOUT_FILENO, "sample output", 13); + ASSERT_INT_EQ(errno, 0); + ASSERT_INT_EQ(ret, 13); + TEST_DONE(); +} + +void +file_tests() +{ + w32posix_initialize(); + //console_io_test(); + //file_simple_fileio(); + file_blocking_io_tests(); + file_nonblocking_io_tests(); + file_select_tests(); + w32posix_done(); +} + diff --git a/regress/unittests/win32compat/socket_tests.c b/regress/unittests/win32compat/socket_tests.c new file mode 100644 index 000000000..2cab1543b --- /dev/null +++ b/regress/unittests/win32compat/socket_tests.c @@ -0,0 +1,624 @@ +/* +* Author: Manoj Ampalam <manoj.ampalam@microsoft.com> +*/ + +#include "includes.h" +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/socket.h> +#include <sys/select.h> +#include <unistd.h> +#include <fcntl.h> +#include "../test_helper/test_helper.h" + +#define PORT "34912" +#define BACKLOG 2 +#define SMALL_RECV_BUF_SIZE 128 + + +#pragma warning(disable:4267) + +int listen_fd, accept_fd, connect_fd, ret; +struct addrinfo hints, *servinfo; +fd_set read_set, write_set, except_set; +struct timeval time_val; +struct sockaddr_storage their_addr; +int their_addr_len = sizeof(their_addr); +char *send_buf, *recv_buf; + +int +unset_nonblock(int fd) +{ + int val; + + val = fcntl(fd, F_GETFL, 0); + if (val < 0) { + return (-1); + } + if (!(val & O_NONBLOCK)) { + return (0); + } + val &= ~O_NONBLOCK; + if (fcntl(fd, F_SETFL, val) == -1) { + return (-1); + } + return (0); +} + +int +set_nonblock(int fd) +{ + int val; + + val = fcntl(fd, F_GETFL, 0); + if (val < 0) { + return (-1); + } + if (val & O_NONBLOCK) { + return (0); + } + val |= O_NONBLOCK; + if (fcntl(fd, F_SETFL, val) == -1) { + return (-1); + } + return (0); + +} + +void +prep_input_buffer(char* buf, int size, int seed) +{ + int ctr = 1; + int *cur = (int*)buf; + for (; size; size -= 4) { + *(cur++) = ctr; + ctr += seed; + } +} + + + +void +socket_fd_tests() +{ + fd_set set, *pset; + pset = &set; + + TEST_START("fd_set initial state"); + FD_ZERO(pset); + ASSERT_CHAR_EQ(0, FD_ISSET(0, pset)); + ASSERT_CHAR_EQ(0, FD_ISSET(1, pset)); + ASSERT_CHAR_EQ(0, FD_ISSET(2, pset)); + TEST_DONE(); + + TEST_START("FD_SET"); + FD_SET(0, pset); + FD_SET(1, pset); + ASSERT_CHAR_EQ(1, FD_ISSET(0, pset)); + ASSERT_CHAR_EQ(1, FD_ISSET(1, pset)); + ASSERT_CHAR_EQ(0, FD_ISSET(2, pset)); + TEST_DONE(); + + TEST_START("FD_CLR"); + FD_CLR(0, pset); + ASSERT_CHAR_EQ(0, FD_ISSET(0, pset)); + ASSERT_CHAR_EQ(1, FD_ISSET(1, pset)); + ASSERT_CHAR_EQ(0, FD_ISSET(2, pset)); + TEST_DONE(); + + TEST_START("FD_ZERO"); + FD_ZERO(pset); + ASSERT_CHAR_EQ(0, FD_ISSET(0, pset)); + ASSERT_CHAR_EQ(0, FD_ISSET(1, pset)); + ASSERT_CHAR_EQ(0, FD_ISSET(2, pset)); + TEST_DONE(); + + + TEST_START("BAD FDs"); + ASSERT_INT_EQ(accept(-1, NULL, NULL), -1); + ASSERT_INT_EQ(errno, EBADF); + ASSERT_INT_EQ(setsockopt(MAX_FDS, 0, 0, NULL, 0), -1); + ASSERT_INT_EQ(errno, EBADF); + /*0,1,2 fd's are initialized */ + ASSERT_INT_EQ(getsockopt(3, 0, 0, NULL, NULL), -1); + ASSERT_INT_EQ(errno, EBADF); + ASSERT_INT_EQ(getsockname(4, NULL, NULL), -1); + ASSERT_INT_EQ(errno, EBADF); + ASSERT_INT_EQ(getpeername(5, NULL, NULL), -1); + ASSERT_INT_EQ(errno, EBADF); + ASSERT_INT_EQ(listen(6, 2), -1); + ASSERT_INT_EQ(errno, EBADF); + ASSERT_INT_EQ(bind(7, NULL, 0), -1); + ASSERT_INT_EQ(errno, EBADF); + ASSERT_INT_EQ(connect(8, NULL, 0), -1); + ASSERT_INT_EQ(errno, EBADF); + ASSERT_INT_EQ(recv(9, NULL, 0, 0), -1); + ASSERT_INT_EQ(errno, EBADF); + ASSERT_INT_EQ(send(10, NULL, 0, 0), -1); + ASSERT_INT_EQ(errno, EBADF); + ASSERT_INT_EQ(shutdown(11, 0), -1); + ASSERT_INT_EQ(errno, EBADF); + ASSERT_INT_EQ(read(MAX_FDS + 1, NULL, 0), -1); + ASSERT_INT_EQ(errno, EBADF); + ASSERT_INT_EQ(write(INFINITE, NULL, 0), -1); + ASSERT_INT_EQ(errno, EBADF); + ASSERT_INT_EQ(fstat(11, NULL), -1); + ASSERT_INT_EQ(errno, EBADF); + ASSERT_INT_EQ(isatty(12), 0); + ASSERT_INT_EQ(errno, EBADF); + ASSERT_PTR_EQ(fdopen(13, NULL), NULL); + ASSERT_INT_EQ(errno, EBADF); + ASSERT_INT_EQ(close(14), -1); + ASSERT_INT_EQ(errno, EBADF); + ASSERT_INT_EQ(fcntl(15, 1), -1); + ASSERT_INT_EQ(errno, EBADF); + ASSERT_INT_EQ(dup(16), -1); + ASSERT_INT_EQ(errno, EBADF); + ASSERT_INT_EQ(dup2(17, 18), -1); + ASSERT_INT_EQ(errno, EBADF); + FD_ZERO(&read_set); + FD_SET(20, &read_set); + ASSERT_INT_EQ(select(21, &read_set, NULL, NULL, &time_val), -1); + ASSERT_INT_EQ(errno, EBADF); + FD_ZERO(&write_set); + FD_SET(21, &write_set); + ASSERT_INT_EQ(select(22, NULL, &write_set, NULL, &time_val), -1); + ASSERT_INT_EQ(errno, EBADF); + TEST_DONE(); + + TEST_START("socket failures"); + ASSERT_INT_EQ(setsockopt(0, 0, SO_RCVTIMEO, NULL, 0), -1); + ASSERT_INT_EQ(errno, ENOTSOCK); + connect_fd = socket(AF_UNSPEC, SOCK_STREAM, IPPROTO_TCP); + ASSERT_INT_NE(connect_fd, -1); + ASSERT_INT_EQ(setsockopt(connect_fd, 0, SO_RCVTIMEO, NULL, 0), -1); + ASSERT_INT_EQ(errno, ENOTSUP); + close(connect_fd); + TEST_DONE(); + + TEST_START("min fd allocation"); + connect_fd = socket(AF_INET, SOCK_STREAM, 0); + ASSERT_INT_EQ(connect_fd, 3); + listen_fd = socket(AF_INET, SOCK_STREAM, 0); + ASSERT_INT_EQ(listen_fd, 4); + close(connect_fd); + connect_fd = socket(AF_INET, SOCK_STREAM, 0); + ASSERT_INT_EQ(connect_fd, 3); /*minimum free fd gets allocated*/ + close(connect_fd); + close(listen_fd); + TEST_DONE(); + +} + +void +socket_blocking_io_tests() +{ + char* small_send_buf = "sample payload"; + char small_recv_buf[SMALL_RECV_BUF_SIZE]; + + TEST_START("Basic IPv4 client server connection setup"); + memset(&hints, 0, sizeof(hints)); + hints.ai_socktype = SOCK_STREAM; + ret = getaddrinfo("127.0.0.1", PORT, &hints, &servinfo); + ASSERT_INT_EQ(ret, 0); + listen_fd = socket(servinfo->ai_family, servinfo->ai_socktype, servinfo->ai_protocol); + ASSERT_INT_NE(listen_fd, -1); + ret = bind(listen_fd, servinfo->ai_addr, servinfo->ai_addrlen); + ASSERT_INT_EQ(ret, 0); + ret = listen(listen_fd, BACKLOG); + ASSERT_INT_EQ(ret, 0); + //call listen again?? + connect_fd = socket(servinfo->ai_family, servinfo->ai_socktype, servinfo->ai_protocol); + ASSERT_INT_NE(connect_fd, -1); + ret = connect(connect_fd, servinfo->ai_addr, servinfo->ai_addrlen); + ASSERT_INT_EQ(ret, 0); + //call connect again?? + their_addr_len = sizeof(their_addr); + accept_fd = accept(listen_fd, (struct sockaddr*)&their_addr, &their_addr_len); + ASSERT_INT_NE(accept_fd, -1); + ret = close(listen_fd); + ASSERT_INT_EQ(ret, 0); + //call accept after listen_fd is closed?? + TEST_DONE(); + + TEST_START("send failures"); + ret = send(accept_fd, NULL, 4, 0);/*invalid buffer*/ + ASSERT_INT_EQ(ret, -1); + ASSERT_INT_EQ(errno, EINVAL); + ret = send(accept_fd, small_send_buf, 0, 0); /*invalid buffer*/ + ASSERT_INT_EQ(ret, -1); + ASSERT_INT_EQ(errno, EINVAL); + ret = send(accept_fd, small_send_buf, strlen(small_send_buf), 4); /*flags not supported yet*/ + ASSERT_INT_EQ(ret, -1); + ASSERT_INT_EQ(errno, ENOTSUP); + TEST_DONE(); + + TEST_START("basic send s->c"); + ret = send(accept_fd, small_send_buf, strlen(small_send_buf), 0); + ASSERT_INT_EQ(ret, strlen(small_send_buf)); + TEST_DONE(); + + TEST_START("recv failures"); + ret = recv(connect_fd, NULL, SMALL_RECV_BUF_SIZE, 0); /* invalid buffer*/ + ASSERT_INT_EQ(ret, -1); + ASSERT_INT_EQ(errno, EINVAL); + ret = recv(connect_fd, small_recv_buf, 0, 0); /*invalid buffer*/ + ASSERT_INT_EQ(ret, -1); + ASSERT_INT_EQ(errno, EINVAL); + ret = recv(connect_fd, small_recv_buf, SMALL_RECV_BUF_SIZE, 6); /*flags not supported yet*/ + ASSERT_INT_EQ(ret, -1); + ASSERT_INT_EQ(errno, ENOTSUP); + TEST_DONE(); + + TEST_START("basic recv s->c"); + ret = recv(connect_fd, small_recv_buf, SMALL_RECV_BUF_SIZE, 0); + ASSERT_INT_EQ(ret, strlen(small_send_buf)); + small_recv_buf[ret] = '\0'; + ASSERT_STRING_EQ(small_send_buf, small_recv_buf); + memset(small_recv_buf, 0, sizeof(small_recv_buf)); + TEST_DONE(); + + TEST_START("basic send recv c->s"); + ret = send(connect_fd, small_send_buf, strlen(small_send_buf), 0); + ASSERT_INT_EQ(ret, strlen(small_send_buf)); + ret = recv(accept_fd, small_recv_buf, SMALL_RECV_BUF_SIZE, 0); + ASSERT_INT_EQ(ret, strlen(small_send_buf)); + small_recv_buf[ret] = '\0'; + ASSERT_STRING_EQ(small_send_buf, small_recv_buf); + memset(small_recv_buf, 0, sizeof(small_recv_buf)); + TEST_DONE(); + + TEST_START("shutdown SD_SEND"); + ret = shutdown(connect_fd, SD_SEND); + ASSERT_INT_EQ(ret, 0); + ret = recv(accept_fd, small_recv_buf, SMALL_RECV_BUF_SIZE, 0); /* send on other side is shutdown*/ + ASSERT_INT_EQ(ret, 0); + ret = shutdown(accept_fd, SD_SEND); + ASSERT_INT_EQ(ret, 0); + ret = recv(connect_fd, small_recv_buf, SMALL_RECV_BUF_SIZE, 0); /* send on other side is shutdown*/ + ASSERT_INT_EQ(ret, 0); + TEST_DONE(); + + TEST_START("shutdown SD_RECEIVE"); + ret = shutdown(connect_fd, SD_RECEIVE); + ASSERT_INT_EQ(ret, 0); + ret = send(accept_fd, small_send_buf, strlen(small_send_buf), 0); + ASSERT_INT_EQ(ret, -1); + ASSERT_INT_EQ(errno, ECONNRESET); + ret = shutdown(accept_fd, SD_RECEIVE); + ASSERT_INT_EQ(ret, 0); + ret = send(connect_fd, small_send_buf, strlen(small_send_buf), 0); + ASSERT_INT_EQ(ret, -1); + ASSERT_INT_EQ(errno, ECONNRESET); + TEST_DONE(); + + TEST_START("basic close"); + ret = close(connect_fd); + ASSERT_INT_EQ(ret, 0); + ret = close(accept_fd); + ASSERT_INT_EQ(ret, 0); + TEST_DONE(); + + freeaddrinfo(servinfo); +} + +void +socket_nonblocking_io_tests() +{ + char* small_send_buf = "sample payload"; + char small_recv_buf[SMALL_RECV_BUF_SIZE]; + + TEST_START("IPv6 sockets setup"); + memset(&hints, 0, sizeof(hints)); + hints.ai_socktype = SOCK_STREAM; + ret = getaddrinfo("::1", PORT, &hints, &servinfo); + ASSERT_INT_EQ(ret, 0); + listen_fd = socket(servinfo->ai_family, servinfo->ai_socktype, servinfo->ai_protocol); + ASSERT_INT_NE(listen_fd, -1); + ret = bind(listen_fd, servinfo->ai_addr, servinfo->ai_addrlen); + ASSERT_INT_EQ(ret, 0); + ret = listen(listen_fd, BACKLOG); + ASSERT_INT_EQ(ret, 0); + connect_fd = socket(servinfo->ai_family, servinfo->ai_socktype, servinfo->ai_protocol); + ASSERT_INT_NE(connect_fd, -1); + TEST_DONE(); + + TEST_START("non blocking accept and connect"); + ret = set_nonblock(listen_fd); + ASSERT_INT_EQ(ret, 0); + accept_fd = accept(listen_fd, NULL, NULL); + ASSERT_INT_EQ(accept_fd, -1); + ASSERT_INT_EQ(errno, EAGAIN); + ret = set_nonblock(connect_fd); + ASSERT_INT_EQ(ret, 0); + ret = connect(connect_fd, servinfo->ai_addr, servinfo->ai_addrlen); + /* connect is too fast to block + ASSERT_INT_EQ(ret, -1); + ASSERT_INT_EQ(errno, EINPROGRESS); */ + ASSERT_INT_EQ(ret, 0); + ret = unset_nonblock(listen_fd); + ASSERT_INT_EQ(ret, 0); + accept_fd = accept(listen_fd, NULL, NULL); + ASSERT_INT_NE(accept_fd, -1); + ret = close(listen_fd); + ASSERT_INT_EQ(ret, 0); + TEST_DONE(); + + TEST_START("non blocking recv"); + ret = set_nonblock(connect_fd); + ASSERT_INT_EQ(ret, 0); + ret = recv(connect_fd, small_recv_buf, SMALL_RECV_BUF_SIZE, 0); + ASSERT_INT_EQ(ret, -1); + ASSERT_INT_EQ(errno, EAGAIN); + ret = unset_nonblock(accept_fd); + ASSERT_INT_EQ(ret, 0); + ret = send(accept_fd, small_send_buf, strlen(small_send_buf), 0); + ASSERT_INT_EQ(ret, strlen(small_send_buf)); + ret = unset_nonblock(connect_fd); + ASSERT_INT_EQ(ret, 0); + ret = recv(connect_fd, small_recv_buf, SMALL_RECV_BUF_SIZE, 0); + ASSERT_INT_EQ(ret, strlen(small_send_buf)); + small_recv_buf[ret] = '\0'; + ASSERT_STRING_EQ(small_send_buf, small_recv_buf); + memset(small_recv_buf, 0, sizeof(small_recv_buf)); + TEST_DONE(); + + TEST_START("non blocking send"); + send_buf = malloc(10 * 1024); + ASSERT_PTR_NE(send_buf, NULL); + ret = set_nonblock(connect_fd); + ASSERT_INT_EQ(ret, 0); + ret = 1; + while (ret > 0) { + ret = send(connect_fd, send_buf, 10 * 1024, 0); + } + ASSERT_INT_EQ(ret, -1); + ASSERT_INT_EQ(errno, EAGAIN); + ret = close(connect_fd); + ASSERT_INT_EQ(ret, 0); + ret = close(accept_fd); + ASSERT_INT_EQ(ret, 0); + TEST_DONE(); + + free(send_buf); + freeaddrinfo(servinfo); +} + +void +socket_select_tests() { + int s, r; + int num_bytes = 1024 * 700; //700KB + int bytes_sent = 0; + int bytes_received = 0; + int seed = 326; + int eagain_results = 0; + + TEST_START("select listen"); + memset(&hints, 0, sizeof(hints)); + hints.ai_socktype = SOCK_STREAM; + ret = getaddrinfo("127.0.0.1", PORT, &hints, &servinfo); + ASSERT_INT_EQ(ret, 0); + listen_fd = socket(servinfo->ai_family, servinfo->ai_socktype, servinfo->ai_protocol); + ASSERT_INT_NE(listen_fd, -1); + ret = bind(listen_fd, servinfo->ai_addr, servinfo->ai_addrlen); + ASSERT_INT_EQ(ret, 0); + ret = listen(listen_fd, BACKLOG); + ASSERT_INT_EQ(ret, 0); + connect_fd = socket(servinfo->ai_family, servinfo->ai_socktype, servinfo->ai_protocol); + ASSERT_INT_NE(connect_fd, -1); + ret = connect(connect_fd, servinfo->ai_addr, servinfo->ai_addrlen); + ASSERT_INT_EQ(ret, 0); + ret = set_nonblock(listen_fd); + ASSERT_INT_EQ(ret, 0); + time_val.tv_sec = 60; + time_val.tv_usec = 0; + FD_ZERO(&read_set); + FD_SET(listen_fd, &read_set); + ret = select(listen_fd + 1, &read_set, NULL, NULL, &time_val); + ASSERT_INT_NE(ret, -1); + ASSERT_INT_EQ(FD_ISSET(listen_fd, &read_set), 1); + accept_fd = accept(listen_fd, NULL, NULL); + ASSERT_INT_NE(accept_fd, -1); + ret = close(listen_fd); + ASSERT_INT_EQ(ret, 0); + TEST_DONE(); + + TEST_START("select send and recv"); + s = accept_fd; + r = connect_fd; + ret = set_nonblock(s); + ASSERT_INT_EQ(ret, 0); + ret = set_nonblock(r); + ASSERT_INT_EQ(ret, 0); + send_buf = malloc(num_bytes); + recv_buf = malloc(num_bytes + 1); + ASSERT_PTR_NE(send_buf, NULL); + ASSERT_PTR_NE(recv_buf, NULL); + prep_input_buffer(send_buf, num_bytes, 17); + FD_ZERO(&read_set); + FD_ZERO(&write_set); + FD_SET(s, &write_set); + FD_SET(r, &read_set); + while (-1 != select(max(r, s) + 1, &read_set, &write_set, NULL, &time_val)) { + if (FD_ISSET(s, &write_set)) { + while ((bytes_sent < num_bytes) && ((ret = send(s, send_buf + bytes_sent, num_bytes - bytes_sent, 0)) > 0)) + bytes_sent += ret; + if (bytes_sent < num_bytes) { + ASSERT_INT_EQ(ret, -1); + ASSERT_INT_EQ(errno, EAGAIN); + eagain_results++; + } + } + + if (FD_ISSET(r, &read_set)) { + while ((ret = recv(r, recv_buf + bytes_received, num_bytes - bytes_received + 1, 0)) > 0) + bytes_received += ret; + if (ret == 0) + break; + ASSERT_INT_EQ(ret, -1); + ASSERT_INT_EQ(errno, EAGAIN); + eagain_results++; + } + + if (bytes_sent < num_bytes) + FD_SET(s, &write_set); + else { + FD_CLR(s, &write_set); + ret = shutdown(s, SD_SEND); + ASSERT_INT_EQ(ret, 0); + } + FD_SET(r, &read_set); + } + + /*ensure that we hit send and recv paths that returned EAGAIN. Else it would not have touched the async paths*/ + /*if this assert is being hit, then num_bytes is too small. up it*/ + ASSERT_INT_GT(eagain_results, 0); + ASSERT_INT_EQ(bytes_sent, bytes_received); + ASSERT_INT_EQ(memcmp(send_buf, recv_buf, num_bytes), 0); + ret = close(connect_fd); + ASSERT_INT_EQ(ret, 0); + ret = close(accept_fd); + ASSERT_INT_EQ(ret, 0); + TEST_DONE(); + + freeaddrinfo(servinfo); +} + +void +socket_typical_ssh_payload_tests() { + int s, r; + int max_bytes = 1024 * 700; //700KB + int max_packetsize = 1024 * 5, bytes_sent = 0; + int packets_sent = 0; + int packets_received = 0; + int send_packet_remaining = 0, recv_packet_remaining = 0; + int eagain_results = 0; + + TEST_START("connection setup"); + memset(&hints, 0, sizeof(hints)); + hints.ai_socktype = SOCK_STREAM; + ret = getaddrinfo("127.0.0.1", PORT, &hints, &servinfo); + ASSERT_INT_EQ(ret, 0); + listen_fd = socket(servinfo->ai_family, servinfo->ai_socktype, servinfo->ai_protocol); + ASSERT_INT_NE(listen_fd, -1); + ret = bind(listen_fd, servinfo->ai_addr, servinfo->ai_addrlen); + ASSERT_INT_EQ(ret, 0); + ret = listen(listen_fd, BACKLOG); + ASSERT_INT_EQ(ret, 0); + connect_fd = socket(servinfo->ai_family, servinfo->ai_socktype, servinfo->ai_protocol); + ASSERT_INT_NE(connect_fd, -1); + ret = connect(connect_fd, servinfo->ai_addr, servinfo->ai_addrlen); + ASSERT_INT_EQ(ret, 0); + accept_fd = accept(listen_fd, NULL, NULL); + ASSERT_INT_NE(accept_fd, -1); + ret = close(listen_fd); + ASSERT_INT_EQ(ret, 0); + TEST_DONE(); + + TEST_START("select send and recv packets"); + r = accept_fd; + s = connect_fd; + ret = set_nonblock(s); + ASSERT_INT_EQ(ret, 0); + ret = set_nonblock(r); + ASSERT_INT_EQ(ret, 0); + send_buf = malloc(max_bytes); + recv_buf = malloc(max_bytes + 1); + ASSERT_PTR_NE(send_buf, NULL); + ASSERT_PTR_NE(recv_buf, NULL); + FD_ZERO(&read_set); + FD_ZERO(&write_set); + FD_SET(s, &write_set); + FD_SET(r, &read_set); + + int total = 0; + while (-1 != select(max(r, s) + 1, &read_set, &write_set, NULL, &time_val)) { + if (FD_ISSET(s, &write_set)) { + while ((send_packet_remaining) && ((ret = send(s, send_buf, send_packet_remaining, 0)) > 0)) { + send_packet_remaining -= ret; + bytes_sent += ret; + } + + if (send_packet_remaining) { + ASSERT_INT_EQ(ret, -1); + ASSERT_INT_EQ(errno, EAGAIN); + } + else if (bytes_sent < max_bytes) { + send_packet_remaining = (rand()*(max_packetsize - 100) / RAND_MAX) + 100; + ret = send(s, &send_packet_remaining, 4, 0); + if (ret == -1) { + send_packet_remaining = 0; //we'll try again when io is ready + } + else if (ret < 4) + /*unfortunate - sent half the header, we'll bail the test out*/ + ASSERT_INT_EQ(1, 0); + else { + ASSERT_INT_EQ(ret, 4); + packets_sent++; + //printf("sending packet of size %d\n", send_packet_remaining); + } + } + } + + if (FD_ISSET(r, &read_set)) { + while (recv_packet_remaining && ((ret = recv(r, recv_buf, recv_packet_remaining, 0)) > 0)) { + recv_packet_remaining -= ret; + } + + if (recv_packet_remaining) { + ASSERT_INT_EQ(ret, -1); + ASSERT_INT_EQ(errno, EAGAIN); + } + else { + ret = recv(r, &recv_packet_remaining, 4, 0); + if (ret == -1) { + ASSERT_INT_EQ(ret, -1); + ASSERT_INT_EQ(errno, EAGAIN); + } + else if (ret == 0) + break; + else if (ret < 4) + /*unfortunate.. read partial header, bail out*/ + ASSERT_INT_EQ(1, 0); + else { + ASSERT_INT_EQ(ret, 4); + packets_received++; + //printf("recevied packet of size %d\n", recv_packet_remaining); + } + } + } + + if ((bytes_sent >= max_bytes) && (send_packet_remaining == 0)) { + FD_CLR(s, &write_set); + ret = shutdown(s, SD_SEND); + ASSERT_INT_EQ(ret, 0); + } + else + FD_SET(s, &write_set); + + FD_SET(r, &read_set); + } + + ASSERT_INT_EQ(packets_sent, packets_received); + ret = close(connect_fd); + ASSERT_INT_EQ(ret, 0); + ret = close(accept_fd); + ASSERT_INT_EQ(ret, 0); + TEST_DONE(); + + freeaddrinfo(servinfo); +} + + +void +socket_tests() +{ + w32posix_initialize(); + socket_fd_tests(); + socket_blocking_io_tests(); + socket_nonblocking_io_tests(); + socket_select_tests(); + socket_typical_ssh_payload_tests(); + w32posix_done(); +} + diff --git a/regress/unittests/win32compat/tests.c b/regress/unittests/win32compat/tests.c new file mode 100644 index 000000000..f3dfa5abb --- /dev/null +++ b/regress/unittests/win32compat/tests.c @@ -0,0 +1,24 @@ +/* +* Author: Manoj Ampalam <manoj.ampalam@microsoft.com> +*/ +/* disable inclusion of compatability defitnitions in CRT headers */ +#define __STDC__ 1 +#include <fcntl.h> +#include <sys\types.h> +#include <sys\stat.h> +//#include <io.h> +#include "../test_helper/test_helper.h" + +extern void log_init(char *av0, int level, int facility, int on_stderr); + +void socket_tests(); +void file_tests(); + +void tests(void) +{ + _set_abort_behavior(0, 1); + log_init(NULL, 7, 2, 0); + socket_tests(); + file_tests(); + return; +} \ No newline at end of file