From 9c4739e3b27d20d966d65daeb76c2801cba5c27a Mon Sep 17 00:00:00 2001 From: John Safranek Date: Wed, 8 Jul 2020 13:40:00 -0700 Subject: [PATCH] Shell Worker 1. Add the echoserver shell support as a configure option. 2. Added some header and function checks to configure. 3. Use the new header and function checks to select includes in the echoserver. --- configure.ac | 13 +++++++++++-- examples/echoserver/echoserver.c | 22 +++++++++++++--------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/configure.ac b/configure.ac index 84f35aa..9783470 100644 --- a/configure.ac +++ b/configure.ac @@ -53,8 +53,9 @@ AC_CHECK_SIZEOF([off_t]) # Check headers/libs AC_CHECK_FUNCS([gethostbyname getaddrinfo gettimeofday inet_ntoa memset socket]) -AC_CHECK_HEADERS([sys/time.h]) +AC_CHECK_HEADERS([sys/time.h pty.h util.h termios.h]) AC_CHECK_LIB([network],[socket]) +AC_CHECK_LIB([util],[forkpty]) AC_CHECK_LIB([wolfssl],[wolfCrypt_Init],,[AC_MSG_ERROR([libwolfssl is required for ${PACKAGE}. It can be obtained from https://www.wolfssl.com/download.html/ .])]) # DEBUG @@ -112,6 +113,11 @@ AC_ARG_ENABLE([term], [AS_HELP_STRING([--disable-term],[Disable pseudo-terminal support (default: enabled)])], [ENABLED_PTERM=$enableval],[ENABLED_PTERM=yes]) +# shell support +AC_ARG_ENABLE([shell], + [AS_HELP_STRING([--enable-shell],[Enable echoserver shell support (default: disabled)])], + [ENABLED_SHELL=$enableval],[ENABLED_SHELL=no]) + # Enable All AC_ARG_ENABLE([all], [AS_HELP_STRING([--enable-all],[Enable all wolfSSH features (default: disabled)])], @@ -125,7 +131,7 @@ AC_ARG_ENABLE([distro], AS_IF([test "x$ENABLED_DISTRO" = "xyes"], [ENABLED_ALL=yes; enable_shared=yes; enable_static=yes]) AS_IF([test "x$ENABLED_ALL" = "xyes"], - [ENABLED_KEYGEN=yes; ENABLED_SCP=yes; ENABLED_SFTP=yes; ENABLED_FWD=yes]) + [ENABLED_KEYGEN=yes; ENABLED_SCP=yes; ENABLED_SFTP=yes; ENABLED_FWD=yes; ENABLED_SHELL=yes]) AS_IF([test "x$ENABLED_INLINE" = "xno"], [AM_CPPFLAGS="$AM_CPPFLAGS -DNO_INLINE"]) AS_IF([test "x$ENABLED_KEYGEN" = "xyes"], @@ -138,6 +144,8 @@ AS_IF([test "x$ENABLED_FWD" = "xyes"], [AM_CPPFLAGS="$AM_CPPFLAGS -DWOLFSSH_FWD"]) AS_IF([test "x$ENABLED_PTERM" = "xyes"], [AM_CPPFLAGS="$AM_CPPFLAGS -DWOLFSSH_TERM"]) +AS_IF([test "x$ENABLED_SHELL" = "xyes"], + [AM_CPPFLAGS="$AM_CPPFLAGS -DWOLFSSH_SHELL"]) AM_CONDITIONAL([BUILD_EXAMPLE_SERVERS],[test "x$ENABLED_EXAMPLES" = "xyes"]) AM_CONDITIONAL([BUILD_EXAMPLE_CLIENTS],[test "x$ENABLED_EXAMPLES" = "xyes"]) @@ -193,6 +201,7 @@ AS_ECHO([" Features"]) AS_ECHO([" * Inline Code: $ENABLED_INLINE"]) AS_ECHO([" * keygen: $ENABLED_KEYGEN"]) AS_ECHO([" * psuedo-terminal: $ENABLED_PTERM"]) +AS_ECHO([" * echoserver shell support: $ENABLED_SHELL"]) AS_ECHO([" * scp: $ENABLED_SCP"]) AS_ECHO([" * sftp: $ENABLED_SFTP"]) AS_ECHO([" * TCP/IP Forwarding: $ENABLED_FWD"]) diff --git a/examples/echoserver/echoserver.c b/examples/echoserver/echoserver.c index 8403b41..2a91c0f 100644 --- a/examples/echoserver/echoserver.c +++ b/examples/echoserver/echoserver.c @@ -22,6 +22,10 @@ #define WOLFSSH_TEST_ECHOSERVER +#ifdef HAVE_CONFIG_H + #include +#endif + #ifdef WOLFSSL_USER_SETTINGS #include #else @@ -52,7 +56,15 @@ #endif #ifdef WOLFSSH_SHELL -// #include + #ifdef HAVE_PTY_H + #include + #endif + #ifdef HAVE_UTIL_H + #include + #endif + #ifdef HAVE_TERMIOS_H + #include + #endif #include #include #include @@ -62,8 +74,6 @@ #include #include #include - #include - #include #endif @@ -318,8 +328,6 @@ static int ssh_worker(thread_ctx_t* threadCtx) { #ifdef WOLFSSH_SHELL #define SE_BUF_SIZE 4096 -/* One can put any command to be run at startup in INIT_CMD1 */ -#define INIT_CMD1 " " typedef struct { @@ -498,10 +506,6 @@ static int shell_worker(thread_ctx_t* threadCtx) return WS_FATAL_ERROR; } - memcpy((void *)buf_rx.buf, (void *)INIT_CMD1, sizeof(INIT_CMD1)); - buf_rx.rdidx += sizeof(INIT_CMD1); - buf_rx.size += sizeof(INIT_CMD1); - /*set sock_fd to non-blocking; select() blocks even if socket is set to non-blocking*/ flags = fcntl(sock_fd, F_GETFL, 0);