Skip to content

Commit 5ea573d

Browse files
authored
Cranked version, Added Package-OpenSSH routine, updated install-sshd (#106)
1 parent 34a3f92 commit 5ea573d

File tree

3 files changed

+71
-8
lines changed

3 files changed

+71
-8
lines changed

contrib/win32/openssh/OpenSSHBuildHelper.psm1

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,68 @@ function Copy-OpenSSLSDK
290290
}
291291
}
292292

293+
function Package-OpenSSH
294+
{
295+
[CmdletBinding(SupportsShouldProcess=$false)]
296+
param
297+
(
298+
[ValidateSet('x86', 'x64')]
299+
[string]$NativeHostArch = "x64",
300+
301+
[ValidateSet('Debug', 'Release', '')]
302+
[string]$Configuration = "Release"
303+
)
304+
305+
[System.IO.DirectoryInfo] $repositoryRoot = Get-RepositoryRoot
306+
$repositoryRoot = Get-Item -Path $repositoryRoot.FullName
307+
$folderName = $NativeHostArch
308+
if($NativeHostArch -ieq 'x86')
309+
{
310+
$folderName = "Win32"
311+
}
312+
$buildDir = Join-Path $repositoryRoot ("bin\" + $folderName + "\" + $Configuration)
313+
$payload = "sshd.exe", "ssh.exe", "ssh-agent.exe", "ssh-add.exe", "sftp.exe"
314+
$payload += "sftp-server.exe", "scp.exe", "ssh-lsa.dll", "ssh-shellhost.exe", "ssh-keygen.exe"
315+
$payload += "sshd_config", "install-sshd.ps1", "uninstall-sshd.ps1"
316+
$payload += "install-sshlsa.ps1", "uninstall-sshlsa.ps1"
317+
318+
$packageName = "OpenSSH-Win64"
319+
if ($NativeHostArch -eq 'x86') {
320+
$packageName = "OpenSSH-Win32"
321+
}
322+
323+
$packageDir = Join-Path $buildDir $packageName
324+
Remove-Item $packageDir -Recurse -Force -ErrorAction SilentlyContinue
325+
New-Item $packageDir -Type Directory | Out-Null
326+
327+
$symbolsDir = Join-Path $buildDir ($packageName + '_Symbols')
328+
Remove-Item $symbolsDir -Recurse -Force -ErrorAction SilentlyContinue
329+
New-Item $symbolsDir -Type Directory | Out-Null
330+
331+
foreach ($file in $payload) {
332+
if ((-not(Test-Path (Join-Path $buildDir $file)))) {
333+
Throw "Cannot find $file under $buildDir. Did you run Build-OpenSSH?"
334+
}
335+
Copy-Item (Join-Path $buildDir $file) $packageDir
336+
if ($file.EndsWith(".exe")) {
337+
$pdb = $file.Replace(".exe", ".pdb")
338+
Copy-Item (Join-Path $buildDir $pdb) $symbolsDir
339+
}
340+
if ($file.EndsWith(".dll")) {
341+
$pdb = $file.Replace(".dll", ".pdb")
342+
Copy-Item (Join-Path $buildDir $pdb) $symbolsDir
343+
}
344+
}
345+
346+
Remove-Item ($packageDir + '.zip') -Force -ErrorAction SilentlyContinue
347+
Compress-Archive -Path $packageDir -DestinationPath ($packageDir + '.zip')
348+
Remove-Item $packageDir -Recurse -Force -ErrorAction SilentlyContinue
349+
350+
Remove-Item ($symbolsDir + '.zip') -Force -ErrorAction SilentlyContinue
351+
Compress-Archive -Path $symbolsDir -DestinationPath ($symbolsDir + '.zip')
352+
Remove-Item $symbolsDir -Recurse -Force -ErrorAction SilentlyContinue
353+
}
354+
293355
function Build-OpenSSH
294356
{
295357
[CmdletBinding(SupportsShouldProcess=$false)]
@@ -527,4 +589,4 @@ function UnInstall-OpenSSH
527589
}
528590

529591

530-
Export-ModuleMember -Function Build-OpenSSH, Get-BuildLogFile, Install-OpenSSH, UnInstall-OpenSSH
592+
Export-ModuleMember -Function Build-OpenSSH, Get-BuildLogFile, Install-OpenSSH, UnInstall-OpenSSH, Package-OpenSSH

contrib/win32/openssh/install-sshd.ps1

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# @manojampalam - authored initial script
22
# @friism - Fixed issue with invalid SDDL on Set-Acl
3+
# @manojampalam - removed ntrights.exe dependency
34

45
$scriptpath = $MyInvocation.MyCommand.Path
56
$scriptdir = Split-Path $scriptpath
@@ -8,7 +9,7 @@ $sshdpath = Join-Path $scriptdir "sshd.exe"
89
$sshagentpath = Join-Path $scriptdir "ssh-agent.exe"
910
$logsdir = Join-Path $scriptdir "logs"
1011

11-
$account = "NT SERVICE\SSHD"
12+
$sshdAccount = "NT SERVICE\SSHD"
1213

1314
#Idea borrowed from http://sqldbamusings.blogspot.com/2012/03/powershell-adding-accounts-to-local.html
1415
function Add-Privilege
@@ -44,7 +45,7 @@ function Add-Privilege
4445

4546
#Get Current policy settings
4647
$imported_settings = [System.IO.Path]::GetTempFileName()
47-
secedit.exe /export /areas USER_RIGHTS /cfg "$($imported_settings)"
48+
secedit.exe /export /areas USER_RIGHTS /cfg "$($imported_settings)" > $null
4849

4950
if (-not(Test-Path $imported_settings)) {
5051
Throw "Unable to import current security policy settings"
@@ -69,7 +70,7 @@ function Add-Privilege
6970
}
7071

7172
#export
72-
secedit.exe /configure /db "secedit.sdb" /cfg "$($settings_to_export)" /areas USER_RIGHTS
73+
secedit.exe /configure /db "secedit.sdb" /cfg "$($settings_to_export)" /areas USER_RIGHTS > $null
7374

7475
}
7576

@@ -94,17 +95,17 @@ New-Service -Name ssh-agent -BinaryPathName $sshagentpath -Description "SSH Agen
9495
cmd.exe /c 'sc.exe sdset ssh-agent D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWLOCRRC;;;IU)(A;;CCLCSWLOCRRC;;;SU)(A;;RP;;;AU)'
9596

9697
New-Service -Name sshd -BinaryPathName $sshdpath -Description "SSH Daemon" -StartupType Manual -DependsOn ssh-agent | Out-Null
97-
sc.exe config sshd obj= $account
98+
sc.exe config sshd obj= $sshdAccount
9899

99-
Add-Privilege -Account $account -Privilege SeAssignPrimaryTokenPrivilege
100-
Add-Privilege -Account $account -Privilege SeServiceLogonRight
100+
Add-Privilege -Account $sshdAccount -Privilege SeAssignPrimaryTokenPrivilege
101+
Add-Privilege -Account $sshdAccount -Privilege SeServiceLogonRight
101102

102103
if(-not (test-path $logsdir -PathType Container))
103104
{
104105
$null = New-Item $logsdir -ItemType Directory -Force -ErrorAction Stop
105106
}
106107
$rights = [System.Security.AccessControl.FileSystemRights]"Read, Write"
107-
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule($account, $rights, "ContainerInherit,ObjectInherit", "None", "Allow")
108+
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule($sshdAccount, $rights, "ContainerInherit,ObjectInherit", "None", "Allow")
108109
$acl = Get-Acl -Path $logsdir
109110
$Acl.SetAccessRule($accessRule)
110111
Set-Acl -Path $logsdir -AclObject $acl

contrib/win32/openssh/version.rc

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)