Skip to content

Commit 265df19

Browse files
authored
Fix include paths (#770)
* fix Include abs path on Windows * add pester tests for Include directive * fix tests * fix typo
1 parent 348084c commit 265df19

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

regress/pesterTests/SSHDConfig.tests.ps1

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,20 @@ Match User matchuser
134134
}
135135
}
136136
}
137+
138+
function Set-SSHDConfigLine
139+
{
140+
param([string]$line, [string]$file)
141+
$sshdconfig_ori = Join-Path $Global:OpenSSHTestInfo["ServiceConfigDir"] sshd_config
142+
if (Test-Path $file) {
143+
Remove-Item $file -Force
144+
}
145+
Copy-Item $sshdconfig_ori $file
146+
get-acl $sshdconfig_ori | set-acl $file
147+
$content = Get-Content -Path $file
148+
$newContent = @($line) + $content
149+
Set-Content -Path $file -Value $newContent
150+
}
137151

138152
#skip when the task schedular (*-ScheduledTask) cmdlets does not exist
139153
$ts = (get-command get-ScheduledTask -ErrorAction SilentlyContinue)
@@ -365,4 +379,50 @@ Match User matchuser
365379
Remove-UserFromLocalGroup -UserName $matchuser -GroupName $allowGroup1
366380
}
367381
}
382+
383+
Context "Tests of Other SSHD Config Directives via -T" {
384+
BeforeAll {
385+
$tI=1
386+
$absoluteFilePath = Join-Path $testDir "includeFile"
387+
$relativeFilePath = "includeFile"
388+
$progDataPath = Join-Path $env:ProgramData $relativeFilePath
389+
# adding a line that would not be in a default sshd_config file
390+
$content = "loglevel DEBUG3"
391+
$content | Set-Content $absoluteFilePath
392+
$content | Set-Content $progDataPath
393+
$sshdconfig_custom = Join-Path $Global:OpenSSHTestInfo["ServiceConfigDir"] sshd_config_custom
394+
$binPath = Join-Path $($OpenSSHTestInfo['OpenSSHBinPath']) "sshd.exe"
395+
}
396+
397+
AfterAll {
398+
$tC++
399+
if (Test-Path $absoluteFilePath) {
400+
Remove-Item $absoluteFilePath -force
401+
}
402+
if (Test-Path $progDataPath) {
403+
Remove-Item $progDataPath -force
404+
}
405+
if (Test-Path $sshdconfig_custom) {
406+
Remove-Item $sshdconfig_custom -force
407+
}
408+
}
409+
410+
It "$tC.$tI - Include Directive with absolute path starting with forward slash" {
411+
Set-SSHDConfigLine -line "Include /$absoluteFilePath" -file $sshdconfig_custom
412+
$result = Invoke-Expression "$binPath -T -f '$sshdconfig_custom'"
413+
$result.Contains($content) | Should Be $true
414+
}
415+
416+
It "$tC.$tI - Include Directive with absolute path starting with drive" {
417+
Set-SSHDConfigLine -line "Include $absoluteFilePath" -file $sshdconfig_custom
418+
$result = Invoke-Expression "$binPath -T -f '$sshdconfig_custom'"
419+
$result.Contains($content) | Should Be $true
420+
}
421+
422+
It "$tC.$tI - Include Directive with filename, relative to ProgramData" {
423+
Set-SSHDConfigLine -line "Include $relativeFilePath" -file $sshdconfig_custom
424+
$result = Invoke-Expression "$binPath -T -f '$sshdconfig_custom'"
425+
$result.Contains($content) | Should Be $true
426+
}
427+
}
368428
}

servconf.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2319,7 +2319,11 @@ process_server_config_line_depth(ServerOptions *options, char *line,
23192319
}
23202320
value++;
23212321
found = 0;
2322+
#ifdef WINDOWS
2323+
if (!path_absolute(arg2) && *arg2 != '~') {
2324+
#else
23222325
if (*arg2 != '/' && *arg2 != '~') {
2326+
#endif
23232327
xasprintf(&arg, "%s/%s", SSHDIR, arg2);
23242328
} else
23252329
arg = xstrdup(arg2);

0 commit comments

Comments
 (0)