From 8145ce25b18a3a95a06997c49edaae4269656d80 Mon Sep 17 00:00:00 2001 From: Tess Gauthier Date: Mon, 9 Dec 2024 17:20:40 -0500 Subject: [PATCH 1/4] fix Include abs path on Windows --- servconf.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/servconf.c b/servconf.c index 5affc02fae60..adae64b4cdf8 100644 --- a/servconf.c +++ b/servconf.c @@ -2319,7 +2319,11 @@ process_server_config_line_depth(ServerOptions *options, char *line, } value++; found = 0; +#ifdef WINDOWS + if (!path_absolute(arg2) && *arg2 != '~') { +#else if (*arg2 != '/' && *arg2 != '~') { +#endif xasprintf(&arg, "%s/%s", SSHDIR, arg2); } else arg = xstrdup(arg2); From 0c41cbf08650098d899dd05baf79599f1165f2ca Mon Sep 17 00:00:00 2001 From: Tess Gauthier Date: Mon, 9 Dec 2024 17:20:58 -0500 Subject: [PATCH 2/4] add pester tests for Include directive --- regress/pesterTests/SSHDConfig.tests.ps1 | 60 ++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/regress/pesterTests/SSHDConfig.tests.ps1 b/regress/pesterTests/SSHDConfig.tests.ps1 index 47a8259595fe..1f49cb326156 100644 --- a/regress/pesterTests/SSHDConfig.tests.ps1 +++ b/regress/pesterTests/SSHDConfig.tests.ps1 @@ -134,6 +134,20 @@ Match User matchuser } } } + + function Set-SSHDConfigLine + { + param([string]$line, [string]$file) + $sshdconfig_ori = Join-Path $Global:OpenSSHTestInfo["ServiceConfigDir"] sshd_config + if (Test-Path $file) { + Remove-Item $file -Force + } + Copy-Item $sshdconfig_ori $file + get-acl $sshdconfig_ori | set-acl $file + $content = Get-Content -Path $file + $newContent = @($line) + $content + Set-Content -Path $file -Value $newContent + } #skip when the task schedular (*-ScheduledTask) cmdlets does not exist $ts = (get-command get-ScheduledTask -ErrorAction SilentlyContinue) @@ -365,4 +379,50 @@ Match User matchuser Remove-UserFromLocalGroup -UserName $matchuser -GroupName $allowGroup1 } } + + Context "Tests of Other SSHD Config Directives via -T" { + BeforeAll { + $tI=1 + $absoluteFilePath = Join-Path $testDir "includeFile" + $relativeFilePath = "includeFile" + $progDataPath = Join-Path $env:ProgramData $relativeFilePath + # adding a line that would not be in a default sshd_config file + $content = "loglevel DEBUG3" + $content | Set-Content $absoluteFilePath + $content | Set-Content $progDataPath + $sshdconfig_custom = Join-Path $Global:OpenSSHTestInfo["ServiceConfigDir"] sshd_config_custom + $binPath = Join-Path $($OpenSSHTestInfo['OpenSSHBinPath']) "sshd.exe" + } + + AfterAll { + $tC++ + if (Test-Path $absoluteFilePath) { + Remove-Item $absoluteFilePath -force + } + if (Test-Path $progDataPath) { + Remove-Item $progDataPath -force + } + if (Test-Path $sshdconfig_custom) { + Remove-Item $sshd_config_custom -force + } + } + + It "$tC.$tI - Include Directive with absolute path starting with forward slash" { + Set-SSHDConfigLine -line "Include /$absoluteFilePath" -file $sshdconfig_custom + $result = Invoke-Expression "$binPath -T -f '$sshdconfig_custom'" + $result.Contains($content) | Should Be $true + } + + It "$tC.$tI - Include Directive with absolute path starting with drive" { + Set-SSHDConfigLine -line "Include $absoluteFilePath" + $result = Invoke-Expression "$binPath -T -f '$sshdconfig_custom'" + $result.Contains($content) | Should Be $true + } + + It "$tC.$tI - Include Directive with filename, relative to ProgramData" { + Set-SSHDConfigLine -line "Include $relativeFilePath" + $result = Invoke-Expression "$binPath -T -f '$sshdconfig_custom'" + $result.Contains($content) | Should Be $true + } + } } From b7254376e0349d73ba5895c8f244885612dfeefe Mon Sep 17 00:00:00 2001 From: Tess Gauthier Date: Tue, 10 Dec 2024 09:59:58 -0500 Subject: [PATCH 3/4] fix tests --- regress/pesterTests/SSHDConfig.tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/regress/pesterTests/SSHDConfig.tests.ps1 b/regress/pesterTests/SSHDConfig.tests.ps1 index 1f49cb326156..6cf77972962f 100644 --- a/regress/pesterTests/SSHDConfig.tests.ps1 +++ b/regress/pesterTests/SSHDConfig.tests.ps1 @@ -414,13 +414,13 @@ Match User matchuser } It "$tC.$tI - Include Directive with absolute path starting with drive" { - Set-SSHDConfigLine -line "Include $absoluteFilePath" + Set-SSHDConfigLine -line "Include $absoluteFilePath" -file $sshdconfig_custom $result = Invoke-Expression "$binPath -T -f '$sshdconfig_custom'" $result.Contains($content) | Should Be $true } It "$tC.$tI - Include Directive with filename, relative to ProgramData" { - Set-SSHDConfigLine -line "Include $relativeFilePath" + Set-SSHDConfigLine -line "Include $relativeFilePath" -file $sshdconfig_custom $result = Invoke-Expression "$binPath -T -f '$sshdconfig_custom'" $result.Contains($content) | Should Be $true } From ac53e792d38e4854d187977ca58127360c944aee Mon Sep 17 00:00:00 2001 From: Tess Gauthier Date: Tue, 10 Dec 2024 10:36:17 -0500 Subject: [PATCH 4/4] fix typo --- regress/pesterTests/SSHDConfig.tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/regress/pesterTests/SSHDConfig.tests.ps1 b/regress/pesterTests/SSHDConfig.tests.ps1 index 6cf77972962f..f05a8cc4f222 100644 --- a/regress/pesterTests/SSHDConfig.tests.ps1 +++ b/regress/pesterTests/SSHDConfig.tests.ps1 @@ -403,7 +403,7 @@ Match User matchuser Remove-Item $progDataPath -force } if (Test-Path $sshdconfig_custom) { - Remove-Item $sshd_config_custom -force + Remove-Item $sshdconfig_custom -force } }