Skip to content

Commit fdf621c

Browse files
yosuke-wolfsslejohnstown
authored andcommitted
Add log for LoginGraceTime on windows, Add regress test and fix minor issues
1 parent b557998 commit fdf621c

2 files changed

Lines changed: 37 additions & 7 deletions

File tree

apps/wolfsshd/test/test_configuration.c

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,10 @@ static int RunTest(const TEST_CASE* tc)
156156

157157
ret = tc->func();
158158
if (ret != 0) {
159-
Log("%s FAILED.\n", tc->name);
159+
fprintf(stderr, "%s FAILED (ret=%d).\n", tc->name, ret);
160160
}
161161
else {
162-
Log("%s PASSED.\n", tc->name);
162+
fprintf(stderr, "%s PASSED.\n", tc->name);
163163
}
164164

165165
TestCleanup();
@@ -173,6 +173,32 @@ typedef struct {
173173
int shouldFail;
174174
} CONFIG_LINE_VECTOR;
175175

176+
static int test_ConfigDefaults(void)
177+
{
178+
int ret = WS_SUCCESS;
179+
WOLFSSHD_CONFIG* conf;
180+
181+
conf = wolfSSHD_ConfigNew(NULL);
182+
if (conf == NULL)
183+
ret = WS_MEMORY_E;
184+
185+
if (ret == WS_SUCCESS) {
186+
if (wolfSSHD_ConfigGetGraceTime(conf) != 120)
187+
ret = WS_FATAL_ERROR;
188+
}
189+
if (ret == WS_SUCCESS) {
190+
if (wolfSSHD_ConfigGetPort(conf) != 22)
191+
ret = WS_FATAL_ERROR;
192+
}
193+
if (ret == WS_SUCCESS) {
194+
if (wolfSSHD_ConfigGetPwAuth(conf) == 0)
195+
ret = WS_FATAL_ERROR;
196+
}
197+
198+
wolfSSHD_ConfigFree(conf);
199+
return ret;
200+
}
201+
176202
static int test_ParseConfigLine(void)
177203
{
178204
int ret = WS_SUCCESS;
@@ -277,16 +303,16 @@ static int test_ConfigCopy(void)
277303
ret = wolfSSHD_ConfigSetHostCertFile(head, "/etc/ssh/host_cert.pub");
278304
if (ret == WS_SUCCESS)
279305
ret = wolfSSHD_ConfigSetUserCAKeysFile(head, "/etc/ssh/ca.pub");
280-
if (ret == WS_SUCCESS)
281-
ret = wolfSSHD_ConfigSetAuthKeysFile(head, ".ssh/authorized_keys");
306+
/* AuthorizedKeysFile must go through PCL so authKeysFileSet flag is set */
307+
if (ret == WS_SUCCESS) ret = PCL("AuthorizedKeysFile .ssh/authorized_keys");
282308

283309
/* scalar fields */
284310
if (ret == WS_SUCCESS) ret = PCL("Port 2222");
285311
if (ret == WS_SUCCESS) ret = PCL("LoginGraceTime 30");
286312
if (ret == WS_SUCCESS) ret = PCL("PasswordAuthentication yes");
287313
if (ret == WS_SUCCESS) ret = PCL("PermitEmptyPasswords yes");
288314
if (ret == WS_SUCCESS) ret = PCL("PermitRootLogin yes");
289-
if (ret == WS_SUCCESS) ret = PCL("UsePrivilegeSeparation yes");
315+
if (ret == WS_SUCCESS) ret = PCL("UsePrivilegeSeparation sandbox");
290316

291317
/* trigger ConfigCopy via Match; conf advances to the new node */
292318
if (ret == WS_SUCCESS) ret = PCL("Match User testuser");
@@ -370,7 +396,7 @@ static int test_ConfigCopy(void)
370396
ret = WS_FATAL_ERROR;
371397
}
372398
if (ret == WS_SUCCESS) {
373-
if (wolfSSHD_ConfigGetPrivilegeSeparation(match) == 0)
399+
if (wolfSSHD_ConfigGetPrivilegeSeparation(match) != WOLFSSHD_PRIV_SANDBOX)
374400
ret = WS_FATAL_ERROR;
375401
}
376402

@@ -467,6 +493,7 @@ static int test_CheckPasswordHashUnix(void)
467493
#endif /* WOLFSSH_HAVE_LIBCRYPT || WOLFSSH_HAVE_LIBLOGIN */
468494

469495
const TEST_CASE testCases[] = {
496+
TEST_DECL(test_ConfigDefaults),
470497
TEST_DECL(test_ParseConfigLine),
471498
TEST_DECL(test_ConfigCopy),
472499
TEST_DECL(test_ConfigFree),

apps/wolfsshd/wolfsshd.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1851,7 +1851,10 @@ static void* HandleConnection(void* arg)
18511851
graceTime = wolfSSHD_AuthGetGraceTime(conn->auth);
18521852
if (graceTime > 0) {
18531853
#ifdef WIN32
1854-
/* @TODO SetTimer(NULL, NULL, graceTime, alarmCatch); */
1854+
/* LoginGraceTime enforcement is not yet implemented on Windows.
1855+
* @TODO implement via CreateWaitableTimer or similar. */
1856+
wolfSSH_Log(WS_LOG_WARN, "[SSHD] LoginGraceTime is set but "
1857+
"not enforced on this platform");
18551858
#else
18561859
signal(SIGALRM, alarmCatch);
18571860
alarm((unsigned int)graceTime);

0 commit comments

Comments
 (0)