Skip to content

Commit de58d1d

Browse files
Add debug prints
1 parent 9a2fd8b commit de58d1d

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

apps/wolfsshd/test/sshd_login_grace_test.ps1

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,18 @@ AuthorizedKeysFile $authFile
4747
"" | Out-File -FilePath $authFile -Encoding ASCII
4848
if (Test-Path $logFile) { Remove-Item $logFile -Force }
4949

50+
# Capture the daemon's own stdout/stderr (where the [SSHD-DBG] diagnostics go)
51+
# so we can inspect them even if the -E log file mechanism is not writing.
52+
$stdoutFile = Join-Path $scriptDir "grace_stdout.txt"
53+
$stderrFile = Join-Path $scriptDir "grace_stderr.txt"
54+
5055
# Run wolfsshd in the foreground (-D) with debug logging to a file (-E). On
5156
# Windows, -D selects the non-service foreground path, which lets us read the
5257
# log just like the Unix test does.
5358
$sshd = Start-Process -FilePath $SshdExe `
5459
-ArgumentList "-D", "-d", "-E", "`"$logFile`"", "-f", "`"$confFile`"", "-p", "$Port" `
60+
-RedirectStandardOutput $stdoutFile `
61+
-RedirectStandardError $stderrFile `
5562
-NoNewWindow -PassThru
5663

5764
try {
@@ -104,6 +111,18 @@ try {
104111
}
105112
Write-Host "=== end of wolfsshd log ==="
106113

114+
# Dump the daemon's captured stdout/stderr (carries the [SSHD-DBG] lines).
115+
foreach ($f in @($stdoutFile, $stderrFile)) {
116+
Write-Host "=== daemon $(Split-Path -Leaf $f) ==="
117+
if ((Test-Path $f) -and ((Get-Item $f).Length -gt 0)) {
118+
Get-Content $f
119+
}
120+
else {
121+
Write-Host "(empty)"
122+
}
123+
Write-Host "=== end ==="
124+
}
125+
107126
if ((Test-Path $logFile) -and
108127
(Select-String -Path $logFile -Pattern "Failed login within grace period" -Quiet)) {
109128
Write-Host "PASS: unauthenticated connection dropped at login grace deadline"

apps/wolfsshd/wolfsshd.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,6 +1924,10 @@ static VOID CALLBACK GraceTimeoutCb(PTP_CALLBACK_INSTANCE instance, PVOID ctx,
19241924
{
19251925
WOLFSSHD_CONNECTION* conn = (WOLFSSHD_CONNECTION*)ctx;
19261926

1927+
/* TEMP DEBUG: confirm the threadpool timer actually fires */
1928+
fprintf(stderr, "[SSHD-DBG] grace timeout callback fired\n");
1929+
fflush(stderr);
1930+
19271931
if (conn != NULL) {
19281932
conn->timeOut = 1;
19291933
}
@@ -2030,6 +2034,10 @@ static void* HandleConnection(void* arg)
20302034
else {
20312035
SetThreadpoolTimer(conn->loginTimer, &due, 0, 0);
20322036
}
2037+
/* TEMP DEBUG: confirm the grace timer was armed */
2038+
fprintf(stderr, "[SSHD-DBG] grace timer armed graceTime=%ld timer=%p\n",
2039+
graceTime, (void*)conn->loginTimer);
2040+
fflush(stderr);
20332041
#else
20342042
signal(SIGALRM, alarmCatch);
20352043
loginGraceTimedOut = 0; /* clear any stale state before arming */
@@ -2064,6 +2072,11 @@ static void* HandleConnection(void* arg)
20642072
conn->timeOut = 1;
20652073
}
20662074
#endif
2075+
/* TEMP DEBUG: report how the accept loop ended */
2076+
fprintf(stderr,
2077+
"[SSHD-DBG] accept loop done ret=%d error=%d timeOut=%d "
2078+
"graceTime=%ld\n", ret, error, conn->timeOut, graceTime);
2079+
fflush(stderr);
20672080
wolfSSH_Log(WS_LOG_INFO,
20682081
"[SSHD] grace time = %ld timeout = %d", graceTime,
20692082
conn->timeOut);

0 commit comments

Comments
 (0)