Skip to content

Fix include paths #770

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions regress/pesterTests/SSHDConfig.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
}
}
4 changes: 4 additions & 0 deletions servconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down