From 49bd9ad51874c7daee1d044016c790a01d0ecfd3 Mon Sep 17 00:00:00 2001 From: John Safranek Date: Wed, 8 Jul 2020 11:56:12 -0700 Subject: [PATCH] Shell Worker 1. Fixed issue with the testsuite failing when the shell is enabled. 2. Added option to echoserver to force the echo behavior instead of the shell when shell is enabled. --- examples/echoserver/echoserver.c | 16 ++++++++++++++-- tests/testsuite.c | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/examples/echoserver/echoserver.c b/examples/echoserver/echoserver.c index f1d3d9b..8403b41 100644 --- a/examples/echoserver/echoserver.c +++ b/examples/echoserver/echoserver.c @@ -87,6 +87,7 @@ typedef struct { WOLFSSH* ssh; SOCKET_T fd; word32 id; + int echo; char nonBlock; } thread_ctx_t; @@ -813,7 +814,7 @@ static THREAD_RETURN WOLFSSH_THREAD server_worker(void* vArgs) case WS_SUCCESS: #ifdef WOLFSSH_SHELL if (wolfSSH_GetSessionType(threadCtx->ssh) == - WOLFSSH_SESSION_SHELL) { + WOLFSSH_SESSION_SHELL && !threadCtx->echo) { ret = shell_worker(threadCtx); } else { @@ -1298,6 +1299,7 @@ static void ShowUsage(void) printf(" -1 exit after single (one) connection\n"); printf(" -e expect ECC public key from client\n"); printf(" -E use ECC private key\n"); + printf(" -f echo input\n"); printf(" -p port to connect on, default %d\n", wolfSshPort); printf(" -N use non-blocking sockets\n"); #ifdef WOLFSSH_SFTP @@ -1333,6 +1335,7 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args) int multipleConnections = 1; int userEcc = 0; int peerEcc = 0; + int echo = 0; int ch; word16 port = wolfSshPort; char* readyFile = NULL; @@ -1344,7 +1347,7 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args) serverArgs->return_code = 0; if (argc > 0) { - while ((ch = mygetopt(argc, argv, "?1d:eEp:R:N")) != -1) { + while ((ch = mygetopt(argc, argv, "?1d:efEp:R:N")) != -1) { switch (ch) { case '?' : ShowUsage(); @@ -1362,6 +1365,10 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args) peerEcc = 1; break; + case 'f': + echo = 1; + break; + case 'p': port = (word16)atoi(myoptarg); #if !defined(NO_MAIN_DRIVER) || defined(USE_WINDOWS_API) @@ -1397,6 +1404,10 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args) } #endif +#ifndef WOLFSSH_SHELL + echo = 0; +#endif + if (wolfSSH_Init() != WS_SUCCESS) { fprintf(stderr, "Couldn't initialize wolfSSH.\n"); exit(EXIT_FAILURE); @@ -1574,6 +1585,7 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args) threadCtx->fd = clientFd; threadCtx->id = threadCount++; threadCtx->nonBlock = nonBlock; + threadCtx->echo = echo; server_worker(threadCtx); diff --git a/tests/testsuite.c b/tests/testsuite.c index e34006a..a5a0751 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -111,6 +111,7 @@ int TestsuiteTest(int argc, char** argv) WSTRNCPY(serverArgv[serverArgc++], "echoserver", ARGLEN); WSTRNCPY(serverArgv[serverArgc++], "-1", ARGLEN); + WSTRNCPY(serverArgv[serverArgc++], "-f", ARGLEN); #ifndef USE_WINDOWS_API WSTRNCPY(serverArgv[serverArgc++], "-p", ARGLEN); WSTRNCPY(serverArgv[serverArgc++], "-0", ARGLEN);