diff --git a/regress/pesterTests/SSHDConfig.tests.ps1 b/regress/pesterTests/SSHDConfig.tests.ps1 index 47a8259595f..f05a8cc4f22 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 $sshdconfig_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" -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" -file $sshdconfig_custom + $result = Invoke-Expression "$binPath -T -f '$sshdconfig_custom'" + $result.Contains($content) | Should Be $true + } + } } diff --git a/servconf.c b/servconf.c index 5affc02fae6..adae64b4cdf 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);