Skip to content

Commit

Permalink
print out log on fail and remove print out from alarm
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobBarthelmeh committed Jan 19, 2024
1 parent 47c7234 commit 80a21cc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 5 additions & 1 deletion apps/wolfsshd/test/sshd_login_grace_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,18 @@ if [ "$RESULT" != 0 ]; then
exit 1
fi

# attempt clearing out stdin from previous echo/grep
read -t 1 -n 1000 discard

# test grace login timeout by stalling on password prompt
timeout 7 "$TEST_CLIENT" -u "$USER" -h "$TEST_HOST" -p "$TEST_PORT" -t
timeout --foreground 7 "$TEST_CLIENT" -u "$USER" -h "$TEST_HOST" -p "$TEST_PORT" -t

popd
cat ./log.txt | grep "Failed login within grace period"
RESULT=$?
if [ "$RESULT" != 0 ]; then
echo "FAIL: Grace period not hit"
cat ./log.txt
exit 1
fi

Expand Down
12 changes: 9 additions & 3 deletions apps/wolfsshd/wolfsshd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1467,7 +1467,6 @@ static __thread int timeOut = 0;
#endif
static void alarmCatch(int signum)
{
wolfSSH_Log(WS_LOG_ERROR, "[SSHD] Failed login within grace period");
timeOut = 1;
(void)signum;
}
Expand Down Expand Up @@ -1553,7 +1552,14 @@ static void* HandleConnection(void* arg)
error = WS_FATAL_ERROR;
}

wolfSSH_Log(WS_LOG_ERROR,
"[SSHD] grace time = %ld timeout = %d", graceTime, timeOut);
if (graceTime > 0) {
if (timeOut) {
wolfSSH_Log(WS_LOG_ERROR,
"[SSHD] Failed login within grace period");
}

#ifdef WIN32
/* @TODO SetTimer(NULL, NULL, graceTime, alarmCatch); */
#else
Expand All @@ -1564,8 +1570,8 @@ static void* HandleConnection(void* arg)
if (ret != WS_SUCCESS && ret != WS_SFTP_COMPLETE &&
ret != WS_SCP_INIT) {
wolfSSH_Log(WS_LOG_ERROR,
"[SSHD] Failed to accept WOLFSSH connection from %s",
conn->ip);
"[SSHD] Failed to accept WOLFSSH connection from %s error %d",
conn->ip, ret);
}
}

Expand Down

0 comments on commit 80a21cc

Please sign in to comment.