Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/wolfSSL/wolfssh into comp…
Browse files Browse the repository at this point in the history
…onent-manager
  • Loading branch information
gojimmypi committed Jan 23, 2024
2 parents 1287608 + 406a7fc commit 0e65ef3
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 28 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
43 changes: 40 additions & 3 deletions autogen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,47 @@
#
# Create configure and makefile stuff...

# Check environment
if [ -n "$WSL_DISTRO_NAME" ]; then
# we found a non-blank WSL environment distro name
current_path="$(pwd)"
pattern="/mnt/?"
if [ "$(echo "$current_path" | grep -E "^$pattern")" ]; then
# if we are in WSL and shared Windows file system, 'ln' does not work.
no_links=true
else
no_links=
fi
fi

# Git hooks should come before autoreconf.
if test -d .git
then
mkdir -p .git/hooks && ln -sf ../../scripts/pre-commit.sh .git/hooks/pre-commit
if [ -d .git ]; then
if [ ! -d .git/hooks ]; then
mkdir .git/hooks || exit $?
fi

if [ -n "$no_links" ]; then
echo "Linux ln does not work on shared Windows file system in WSL."
if [ ! -e .git/hooks/pre-commit ]; then
echo "The pre-commit.sh file will not be copied to .git/hooks/pre-commit"
# shell scripts do not work on Windows; TODO create equivalent batch file
# cp ./pre-commit.sh .git/hooks/pre-commit || exit $?
fi
# unlike wolfssl, wolfssh is not using pre-push.sh at this time. Enable as needed:
# if [ ! -e .git/hooks/pre-push ]; then
# echo "The pre-push.sh file will not be copied to .git/hooks/pre-commit"
# # shell scripts do not work on Windows; TODO create equivalent batch file
# # cp ./pre-push.sh .git/hooks/pre-push || exit $?
# fi
else
if [ ! -e .git/hooks/pre-commit ]; then
ln -sf ../../scripts/pre-commit.sh .git/hooks/pre-commit || exit $?
fi
# unlike wolfssl, wolfssh is not using pre-push.sh at this time Enable as needed:
# if [ ! -e .git/hooks/pre-push ]; then
# ln -s ../../pre-push.sh .git/hooks/pre-push || exit $?
# fi
fi
fi

# If this is a source checkout then call autoreconf with error as well
Expand Down
8 changes: 7 additions & 1 deletion src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@
#include <wolfssh/misc.h>
#else
#define WOLFSSH_MISC_INCLUDED
#include "src/misc.c"
#if defined(WOLFSSL_NUCLEUS)
#include "src/wolfssh_misc.c"
#else
#include "src/misc.c"
#endif
#endif


Expand Down Expand Up @@ -14100,6 +14104,8 @@ int wolfSSH_CleanPath(WOLFSSH* ssh, char* in)
if (path[sz - 1] == ':') {
path[sz] = WS_DELIM;
path[sz + 1] = '\0';
in[sz] = WS_DELIM;
in[sz + 1] = '\0';
}

/* clean up any multiple drive listed i.e. A:/A: */
Expand Down
6 changes: 5 additions & 1 deletion src/ssh.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@
#include <wolfssh/misc.h>
#else
#define WOLFSSH_MISC_INCLUDED
#include "src/misc.c"
#if defined(WOLFSSL_NUCLEUS)
#include "src/wolfssh_misc.c"
#else
#include "src/misc.c"
#endif
#endif

#ifdef HAVE_FIPS
Expand Down
32 changes: 26 additions & 6 deletions src/wolfsftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@
#include <wolfssh/misc.h>
#else
#define WOLFSSH_MISC_INCLUDED
#include "src/misc.c"
#if defined(WOLFSSL_NUCLEUS)
#include "src/wolfssh_misc.c"
#else
#include "src/misc.c"
#endif
#endif

/* for XGMTIME if defined */
Expand Down Expand Up @@ -2731,6 +2735,15 @@ static int wolfSSH_SFTPNAME_readdir(WOLFSSH* ssh, WDIR* dir, WS_SFTPNAME* out,
ret = WS_NEXT_ERROR;
}

if (special) {
sz = WSTRLEN(out->fName);

if ((out->fName[sz - 1] == '/') || (out->fName[sz - 1] == WS_DELIM)) {
out->fName[sz - 1] = '\0';
out->fSz--;
}
}

/* Use attributes and fName to create long name */
if (SFTP_CreateLongName(out) != WS_SUCCESS) {
WLOG(WS_LOG_DEBUG, "Error creating long name for %s", out->fName);
Expand Down Expand Up @@ -4271,12 +4284,22 @@ int SFTP_RemoveHandleNode(WOLFSSH* ssh, byte* handle, word32 handleSz)
#ifndef NO_WOLFSSH_MKTIME

#define WS_GETDAY(d) ((d) & 0x001f)
#define WS_GETMON(d) (((d) >> 5) & 0x000f)
#define _GETMON(d) (((d) >> 5) & 0x000f)
/* number of years since 1900. year + 1980 - 1900 */
#define WS_GETYEAR(d) ((((d) >> 9) & 0x007f) + 80)
#define WS_GETHOUR(t) (((t) >> 11) & 0x001f)
#define _GETHOUR(t) (((t) >> 11) & 0x001f)
#define WS_GETMIN(t) (((t) >> 5 ) & 0x003f)
#define WS_GETSEC(t) (((t) << 1 ) & 0x003f)
#ifdef WOLFSSL_NUCLEUS
/* mktime() expects month from 0 to 11. Nucleus months
* are saved as 1 to 12. Hence 1 is being deducted to
* make it compatible with Unix time stamp. */
#define WS_GETMON(d) (_GETMON(d) - 5)
#define WS_GETHOUR(t) (_GETHOUR(t) - 1)
#else
#define WS_GETMON(d) _GETMON(d)
#define WS_GETHOUR(t) _GETHOUR(t)
#endif

/* convert nucleus date and time shorts to word32
* returns results in Unix time stamp */
Expand Down Expand Up @@ -7159,7 +7182,6 @@ int wolfSSH_SFTP_SendWritePacket(WOLFSSH* ssh, byte* handle, word32 handleSz,
ret = wolfSSH_worker(ssh, NULL);
continue; /* skip past rest and send more */
}

if (state->sentSz <= 0) {
ssh->error = state->sentSz;
ret = WS_FATAL_ERROR;
Expand Down Expand Up @@ -8901,7 +8923,6 @@ int wolfSSH_SFTP_Put(WOLFSSH* ssh, char* from, char* to, byte resume,
}
}


/* called when wolfSSH_free() is called
* return WS_SUCCESS on success */
int wolfSSH_SFTP_free(WOLFSSH* ssh)
Expand Down Expand Up @@ -8950,7 +8971,6 @@ int wolfSSH_SFTP_free(WOLFSSH* ssh)
return WS_SUCCESS;
}


#ifdef WOLFSSH_SHOW_SIZES

void wolfSSH_SFTP_ShowSizes(void)
Expand Down
14 changes: 7 additions & 7 deletions tests/sftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ static const char* cmds[] = {
"pwd",
"ls",
#ifdef WOLFSSH_ZEPHYR
"put " CONFIG_WOLFSSH_SFTP_DEFAULT_DIR "/configure",
"put " CONFIG_WOLFSSH_SFTP_DEFAULT_DIR "/configure.ac",
#else
"put configure",
"put configure.ac",
#endif
"ls",
#ifdef WOLFSSH_ZEPHYR
"get configure " CONFIG_WOLFSSH_SFTP_DEFAULT_DIR "/test-get",
"get configure.ac " CONFIG_WOLFSSH_SFTP_DEFAULT_DIR "/test-get",
#else
"get configure test-get",
"get configure.ac test-get",
#endif
"rm configure",
"rm configure.ac",
"cd ../",
"ls",
"rename test-get test-get-2",
Expand Down Expand Up @@ -116,8 +116,8 @@ static int Expected(int command)
}

case 6:
if (WSTRNSTR(inBuf, "configure", sizeof(inBuf)) == NULL) {
fprintf(stderr, "configure not found in %s\n", inBuf);
if (WSTRNSTR(inBuf, "configure.ac", sizeof(inBuf)) == NULL) {
fprintf(stderr, "configure.ac not found in %s\n", inBuf);
return 1;
}
else {
Expand Down
18 changes: 13 additions & 5 deletions wolfssh/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
#include <wolfssh/settings.h>
#include <wolfssh/log.h>

#ifdef WOLFSSL_NUCLEUS
#include "os/networking/utils/util_tp.h"
#endif

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -105,14 +109,16 @@ extern "C" {
#define WFILE int
WOLFSSH_API int wfopen(WFILE**, const char*, const char*);

#define WFOPEN(fs, f,fn,m) wfopen((f),(fn),(m))
#define WFOPEN(fs,f,fn,m) wfopen((f),(fn),(m))
#define WFCLOSE(fs,f) NU_Close(*(f))
#define WFWRITE(fs,b,x,s,f) ((s) != 0)? NU_Write(*(f),(const CHAR*)(b),(s)): 0
#define WFWRITE(fs,b,x,s,f) \
(((s) != 0) ? NU_Write(*(f),(const CHAR*)(b),(s)) : 0)
#define WFREAD(fs,b,x,s,f) NU_Read(*(f),(CHAR*)(b),(s))
#define WFSEEK(fs,s,o,w) NU_Seek(*(s),(o),(w))
#define WFTELL(fs,s) NU_Seek(*(s), 0, PSEEK_CUR)
#define WREWIND(fs,s) NU_Seek(*(s), 0, PSEEK_SET)
#define WSEEK_END PSEEK_END
#define WBADFILE NULL

#define WS_DELIM '\\'
#define WOLFSSH_O_RDWR PO_RDWR
Expand Down Expand Up @@ -561,6 +567,9 @@ extern "C" {
#elif defined(WOLFSSH_ZEPHYR)
#define WTIME time
#define WLOCALTIME(c,r) (gmtime_r((c),(r))!=NULL)
#elif defined(WOLFSSL_NUCLEUS)
#define WTIME time
#define WLOCALTIME(c,r) (localtime_s((c),(r))!=NULL)
#else
#define WTIME time
#define WLOCALTIME(c,r) (localtime_r((c),(r))!=NULL)
Expand Down Expand Up @@ -756,7 +765,7 @@ extern "C" {
if (NU_Get_Attributes(&atrib, dir) == NU_SUCCESS) {
if (atrib & ADIRENT) {
if (tmp[idx-1] != WS_DELIM) {
if (idx + 2 > sizeof(tmp)) {
if (idx + 2 > (int)sizeof(tmp)) {
/* not enough space */
return -1;
}
Expand All @@ -768,7 +777,7 @@ extern "C" {
}

if (tmp[idx - 1] == WS_DELIM) {
if (idx + 1 > sizeof(tmp)) {
if (idx + 1 > (int)sizeof(tmp)) {
/* not enough space */
return -1;
}
Expand Down Expand Up @@ -1316,7 +1325,6 @@ extern "C" {
#include <unistd.h> /* used for rmdir */
#include <sys/stat.h> /* used for mkdir, stat, and lstat */
#include <stdio.h> /* used for remove and rename */
#include <dirent.h> /* used for opening directory and reading */

#define WSTAT_T struct stat
#define WRMDIR(fs,d) rmdir((d))
Expand Down
2 changes: 1 addition & 1 deletion zephyr/samples/tests/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ int main(void)
/* Setup the necessary files for the sftp tests */
fs_file_t_init(&zfp);
snprintf(filename, sizeof(filename), "%s/%s",
CONFIG_WOLFSSH_SFTP_DEFAULT_DIR, "configure");
CONFIG_WOLFSSH_SFTP_DEFAULT_DIR, "configure.ac");
CHECK_TEST_RETURN(fs_open(&zfp, filename, FS_O_WRITE|FS_O_CREATE));
/* Write some random data to file */
for (i = 0; i < 10; i++)
Expand Down

0 comments on commit 0e65ef3

Please sign in to comment.