remove some trailing white space and initialize get current drive buffer

pull/790/head
JacobBarthelmeh 2025-03-18 15:13:48 +07:00
parent 7067b200b8
commit 4f9e6b5732
4 changed files with 48 additions and 35 deletions

View File

@ -1,6 +1,6 @@
/* wolfssh.c
*
* Copyright (C) 2014-2016 wolfSSL Inc.
* Copyright (C) 2014-2025 wolfSSL Inc.
*
* This file is part of wolfSSH.
*
@ -109,11 +109,16 @@ PwMapList pwMapList;
static const char echoserverBanner[] = "wolfSSH Example Echo Server\n";
/* These are example user:password strings. To update for an admin user
* a string could be added to the list with something like "admin:admin123\n"
*/
static const char samplePasswordBuffer[] =
"jill:upthehill\n"
"jack:fetchapail\n";
/* These are example public key authentication options. */
static const char samplePublicKeyEccBuffer[] =
"ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAA"
"BBBNkI5JTP6D0lF42tbxX19cE87hztUS6FSDoGvPfiU0CgeNSbI+aFdKIzTP5CQEJSvm25"
@ -386,7 +391,8 @@ static byte find_char(const byte* str, const byte* buf, word32 bufSz)
}
#if 1
#if 0
/* redirection of logging message to SYS_CONSOLE_PRINT instead of printf */
static void logCb(enum wolfSSH_LogLevel lvl, const char *const msg)
{
if ( wolfSSH_LogEnabled()
@ -407,7 +413,8 @@ void APP_Initialize ( void )
{
appData.state = APP_SSH_CTX_INIT;
wolfSSH_Init();
#if 1
#if 0
/* Used to enable debug messages and set logging callback */
SYS_CONSOLE_PRINT("Turning on wolfSSH debugging\n\r");
wolfSSH_Debugging_ON();
wolfSSH_SetLoggingCb(logCb);
@ -415,15 +422,16 @@ void APP_Initialize ( void )
}
#ifndef NO_FILESYSTEM
#define APP_MOUNT_NAME "/mnt/myDrive1/"
#define APP_DEVICE_NAME "/dev/nvma1"
#ifdef SYS_FS_LFS_MAX_SS
#define APP_FS_TYPE LITTLEFS
#elif defined(SYS_FS_FAT_MAX_SS)
#define APP_FS_TYPE FAT
#else
#error untested file system setup
#endif
#define APP_MOUNT_NAME "/mnt/myDrive1/"
#define APP_DEVICE_NAME "/dev/nvma1"
#ifdef SYS_FS_LFS_MAX_SS
#define APP_FS_TYPE LITTLEFS
#elif defined(SYS_FS_FAT_MAX_SS)
#define APP_FS_TYPE FAT
#else
#error untested file system setup
#endif
static void CreateTestFile(void)
{

View File

@ -124,6 +124,7 @@ int wfopen(WFILE** f, const char* filename, const char* mode)
defined(FREESCALE_MQX) || defined(WOLFSSH_ZEPHYR)
/* This is current inline in the source. */
#elif defined(MICROCHIP_MPLAB_HARMONY)
int wPwrite(WFD fd, unsigned char* buf, unsigned int sz,
const unsigned int* shortOffset)
@ -149,7 +150,7 @@ int wfopen(WFILE** f, const char* filename, const char* mode)
return ret;
}
#elif defined(WOLFSSH_LOCAL_PREAD_PWRITE)
int wPwrite(WFD fd, unsigned char* buf, unsigned int sz,

View File

@ -3520,7 +3520,6 @@ int wolfSSH_SFTP_RecvCloseDir(WOLFSSH* ssh, byte* handle, word32 handleSz)
}
#endif /* NO_WOLFSSH_DIR */
/* Handles packet to write a file
*
* returns WS_SUCCESS on success
@ -3589,7 +3588,6 @@ int wolfSSH_SFTP_RecvWrite(WOLFSSH* ssh, int reqId, byte* data, word32 maxSz)
ret = WS_INVALID_STATE_E;
}
else {
WLOG(WS_LOG_SFTP, "Wrote %d bytes to file", ret);
ret = WS_SUCCESS;
}
}
@ -3792,7 +3790,6 @@ int wolfSSH_SFTP_RecvRead(WOLFSSH* ssh, int reqId, byte* data, word32 maxSz)
if (outSz > sz) {
/* need to increase buffer size for holding status packet */
WFREE(out, ssh->ctx->heap, DYNTYPE_BUFFER);
WLOG(WS_LOG_SFTP, "Allocating a new buffer of size %d", outSz);
out = (byte*)WMALLOC(outSz, ssh->ctx->heap, DYNTYPE_BUFFER);
if (out == NULL) {
return WS_MEMORY_E;
@ -4966,15 +4963,15 @@ int SFTP_GetAttributesStat(WS_SFTP_FILEATRB* atr, WSTAT_T* stats)
return WS_SUCCESS;
}
static int SFTP_GetAttributesHelper(WS_SFTP_FILEATRB* atr, const char* fName)
{
WSTAT_T stats;
SYS_FS_RESULT res;
char buffer[255];
WMEMSET(&stats, 0, sizeof(WSTAT_T));
WMEMSET(atr, 0, sizeof(WS_SFTP_FILEATRB));
WMEMSET(buffer, 0, sizeof(buffer));
res = SYS_FS_CurrentDriveGet(buffer);
if (res == SYS_FS_RES_SUCCESS) {
if (WSTRCMP(fName, buffer) == 0) {
@ -5336,9 +5333,6 @@ int wolfSSH_SFTP_RecvLSTAT(WOLFSSH* ssh, int reqId, byte* data, word32 maxSz)
ret = WS_FATAL_ERROR;
}
WLOG(WS_LOG_SFTP, "SFTP default path = %s name after get and clean = %s",
ssh->sftpDefaultPath, name);
/* try to get file attributes and send back to client */
if (ret == WS_SUCCESS) {
WMEMSET((byte*)&atr, 0, sizeof(WS_SFTP_FILEATRB));
@ -9072,8 +9066,11 @@ int wolfSSH_SFTP_Put(WOLFSSH* ssh, char* from, char* to, byte resume,
}
}
}
//ret = WFOPEN(ssh->fs, &state->fl, from, "rb");
#if defined(MICROCHIP_MPLAB_HARMONY)
ret = WFOPEN(ssh->fs, &state->fl, from, WOLFSSH_O_RDONLY);
#else
ret = WFOPEN(ssh->fs, &state->fl, from, "rb");
#endif
if (ret != 0) {
WLOG(WS_LOG_SFTP, "Unable to open input file");
ssh->error = WS_SFTP_FILE_DNE;
@ -9224,7 +9221,7 @@ static int SFTP_FreeHandles(WOLFSSH* ssh)
/* go through and free handles and make sure files are closed */
while (cur != NULL) {
#ifdef MICROCHIP_MPLAB_HARMONY
//@TODO #warning todo clean handles
WFCLOSE(ssh->fs, ((WFILE*)cur->handle));
#else
WCLOSE(ssh->fs, *((WFD*)cur->handle));
#endif
@ -9234,9 +9231,8 @@ static int SFTP_FreeHandles(WOLFSSH* ssh)
}
cur = ssh->handleList;
}
return WS_SUCCESS;
}
#endif
@ -9245,7 +9241,7 @@ static int SFTP_FreeHandles(WOLFSSH* ssh)
int wolfSSH_SFTP_free(WOLFSSH* ssh)
{
int ret = WS_SUCCESS;
WOLFSSH_UNUSED(ssh);
#ifdef WOLFSSH_STOREHANDLE
ret = SFTP_FreeHandles(ssh);

View File

@ -394,7 +394,7 @@ extern "C" {
#include <stdio.h>
#include "system/fs/sys_fs.h"
#define WFFLUSH(s) SYS_FS_FileSync((s))
#define WFILE SYS_FS_HANDLE
@ -451,7 +451,7 @@ extern "C" {
#ifdef WOLFSSL_VXWORKS
#define WUTIMES(f,t) (WS_SUCCESS)
#elif defined(USE_WINDOWS_API)
#include <sys/utime.h>
#include <sys/utime.h>
#else
#define WUTIMES(f,t) utimes((f),(t))
#endif
@ -1385,14 +1385,23 @@ extern "C" {
static inline int wStat(const char* path, WSTAT_T* stat)
{
int ret = SYS_FS_FileStat(path, stat);
WLOG(WS_LOG_SFTP, "Return from SYS_FS_fileStat [%s] = %d, expecting %d",
int ret;
WMEMSET(stat, 0, sizeof(WSTAT_T));
ret = SYS_FS_FileStat(path, stat);
if (ret != SYS_FS_RES_SUCCESS) {
WLOG(WS_LOG_SFTP,
"Return from SYS_FS_fileStat [%s] = %d, expecting %d",
path, ret, SYS_FS_RES_SUCCESS);
WLOG(WS_LOG_SFTP, "SYS error reason = %d", SYS_FS_Error());
WLOG(WS_LOG_SFTP, "SYS error reason = %d", SYS_FS_Error());
return -1;
}
else {
return 0;
}
return 0;
}
static inline char *ff_getcwd(char *r, int rSz)
{
SYS_FS_RESULT ret;
@ -1413,8 +1422,7 @@ extern "C" {
#define WOLFSSH_O_EXCL 0
/* Our "file descriptor" wrapper */
//@TODO maybe this should be int or something to handle DIR to?
#define WFD SYS_FS_HANDLE
int wPwrite(WFD, unsigned char*, unsigned int, const unsigned int*);
int wPread(WFD, unsigned char*, unsigned int, const unsigned int*);