Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ide/IAR-EWARM/Projects/lib/myFilesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ static int SFTP_GetAttributes(void* fs, const char* fileName,
}

static int SFTP_GetAttributes_Handle(void* ssh, byte* handle, int handleSz,
void* atr) {
(void)ssh; (void)handle; (void)handleSz;
char* name, void* atr) {
(void)ssh; (void)handle; (void)handleSz; (void)name;

return 0;
}

#endif /* WOLFSSH_USER_FILESYSTEM */

#endif
#endif
4 changes: 2 additions & 2 deletions ide/STM32CUBE/myFilesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ static inline int SFTP_GetAttributes(void* fs, const char* fileName,
}

static inline int SFTP_GetAttributes_Handle(void* ssh, byte* handle, int handleSz,
void* atr) {
(void)ssh; (void)handle; (void)handleSz;
char* name, void* atr) {
(void)ssh; (void)handle; (void)handleSz; (void)name;

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ int wPread(WFD fd, unsigned char* buf, unsigned int sz,

#endif

#ifndef NO_FILESYSTEM
#if !defined(NO_FILESYSTEM) && !defined(WOLFSSH_USER_FILESYSTEM)
#if defined(MICROCHIP_MPLAB_HARMONY)
int wChmod(const char *path, int mode)
{
Expand Down
92 changes: 42 additions & 50 deletions src/wolfsftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -994,11 +994,11 @@ static INLINE int SFTP_GetSz(byte* buf, word32* sz,

#ifndef NO_WOLFSSH_SERVER

#ifndef WOLFSSH_USER_FILESYSTEM
#if !defined(WOLFSSH_USER_FILESYSTEM)
static int SFTP_GetAttributes(void* fs, const char* fileName,
WS_SFTP_FILEATRB* atr, byte noFollow, void* heap);
static int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
WS_SFTP_FILEATRB* atr);
char* name, WS_SFTP_FILEATRB* atr);
#endif

/* unique from other packets because the request ID is not also sent.
Expand Down Expand Up @@ -3135,7 +3135,9 @@ static int wolfSSH_SFTPNAME_readdir(WOLFSSH* ssh, WDIR* dir, WS_SFTPNAME* out,
}

#elif defined(MICROCHIP_MPLAB_HARMONY)
#ifndef WOLFSSH_USER_FILESYSTEM
int SFTP_GetAttributesStat(WS_SFTP_FILEATRB* atr, WSTAT_T* stats);
#endif

/* helper function that gets file information from reading directory
*
Expand Down Expand Up @@ -4416,7 +4418,10 @@ int SFTP_RemoveHandleNode(WOLFSSH* ssh, byte* handle, word32 handleSz)
#endif /* WOLFSSH_STOREHANDLE */


#ifdef WOLFSSL_NUCLEUS
#if defined(WOLFSSH_USER_FILESYSTEM)
/* User-defined I/O support */

#elif defined(WOLFSSL_NUCLEUS)

#ifndef NO_WOLFSSH_MKTIME

Expand Down Expand Up @@ -4539,22 +4544,15 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
* returns WS_SUCCESS on success
*/
int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
WS_SFTP_FILEATRB* atr)
char* name, WS_SFTP_FILEATRB* atr)
{
DSTAT stats;
WS_HANDLE_LIST* cur;

if (handle == NULL || atr == NULL) {
return WS_FATAL_ERROR;
}

cur = SFTP_GetHandleNode(ssh, handle, handleSz);
if (cur == NULL) {
WLOG(WS_LOG_SFTP, "Unknown handle");
return WS_BAD_FILE_E;
}

if (WSTAT(ssh->fs, cur->name, &stats) != NU_SUCCESS) {
if (WSTAT(ssh->fs, name, &stats) != NU_SUCCESS) {
return WS_FATAL_ERROR;
}

Expand Down Expand Up @@ -4708,10 +4706,9 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
* Fills out a WS_SFTP_FILEATRB structure
* returns WS_SUCCESS on success */
int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
WS_SFTP_FILEATRB* atr)
char* name, WS_SFTP_FILEATRB* atr)
{
int err;
WS_HANDLE_LIST* cur;
MQX_FILE_PTR mfs_ptr;
MFS_SEARCH_DATA search_data;
MFS_SEARCH_PARAM search;
Expand All @@ -4721,14 +4718,8 @@ int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
}
mfs_ptr = (MQX_FILE_PTR)ssh->fs;

cur = SFTP_GetHandleNode(ssh, handle, handleSz);
if (cur == NULL) {
WLOG(WS_LOG_SFTP, "Unknown handle");
return WS_BAD_FILE_E;
}

search.ATTRIBUTE = MFS_SEARCH_ANY;
search.WILDCARD = cur->name;
search.WILDCARD = name;
search.SEARCH_DATA_PTR = &search_data;

err = ioctl(mfs_ptr, IO_IOCTL_FIND_FIRST_FILE, (uint32_t*)&search);
Expand Down Expand Up @@ -4829,22 +4820,15 @@ static int SFTP_GetAttributes(void* fs, const char* fileName,
}

static int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
WS_SFTP_FILEATRB* atr)
char* name, WS_SFTP_FILEATRB* atr)
{
FILINFO info;
WS_HANDLE_LIST *cur;

if (handle == NULL || atr == NULL) {
return WS_FATAL_ERROR;
}

cur = SFTP_GetHandleNode(ssh, handle, handleSz);
if (cur == NULL) {
WLOG(WS_LOG_SFTP, "Unknown handle");
return WS_BAD_FILE_E;
}

if (f_stat(cur->name, &info) != FR_OK) {
if (f_stat(name, &info) != FR_OK) {
return WS_FATAL_ERROR;
}

Expand Down Expand Up @@ -4877,6 +4861,9 @@ static int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
atr->atime = info.ftime;
atr->mtime = info.ftime;
#endif /* NO_WOLFSSH_MKTIME */

WOLFSSH_UNUSED(ssh);
WOLFSSH_UNUSED(handleSz);
return WS_SUCCESS;
}

Expand Down Expand Up @@ -4919,21 +4906,18 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
}

int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
WS_SFTP_FILEATRB* atr)
char* name, WS_SFTP_FILEATRB* atr)
{
WOLFSSH_UNUSED(ssh);
WOLFSSH_UNUSED(handle);
WOLFSSH_UNUSED(handleSz);
WOLFSSH_UNUSED(atr);
WOLFSSH_UNUSED(name);

WLOG(WS_LOG_SFTP, "SFTP_GetAttributes_Handle() not implemented yet");
return WS_NOT_COMPILED;
}


#elif defined(WOLFSSH_USER_FILESYSTEM)
/* User-defined I/O support */

#elif defined(MICROCHIP_MPLAB_HARMONY)
int SFTP_GetAttributesStat(WS_SFTP_FILEATRB* atr, WSTAT_T* stats)
{
Expand Down Expand Up @@ -5021,20 +5005,8 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
* returns WS_SUCCESS on success
*/
int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
WS_SFTP_FILEATRB* atr)
char* name, WS_SFTP_FILEATRB* atr)
{
WS_HANDLE_LIST* cur;

if (handleSz != sizeof(word32)) {
WLOG(WS_LOG_SFTP, "Unexpected handle size SFTP_GetAttributes_Handle()");
}

cur = SFTP_GetHandleNode(ssh, handle, handleSz);
if (cur == NULL) {
WLOG(WS_LOG_SFTP, "Unknown handle");
return WS_BAD_FILE_E;
}

return SFTP_GetAttributesHelper(atr, cur->name);
}

Expand Down Expand Up @@ -5096,7 +5068,7 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
* returns WS_SUCCESS on success
*/
int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
WS_SFTP_FILEATRB* atr)
char* name, WS_SFTP_FILEATRB* atr)
{
struct stat stats;

Expand Down Expand Up @@ -5130,6 +5102,7 @@ int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
/* @TODO handle attribute extensions */

WOLFSSH_UNUSED(ssh);
WOLFSSH_UNUSED(name);
return WS_SUCCESS;
}
#endif
Expand All @@ -5147,6 +5120,7 @@ int wolfSSH_SFTP_RecvFSTAT(WOLFSSH* ssh, int reqId, byte* data, word32 maxSz)
byte* handle;
word32 idx = 0;
int ret = WS_SUCCESS;
char* name = NULL;

byte* out = NULL;
word32 outSz = 0;
Expand All @@ -5168,9 +5142,27 @@ int wolfSSH_SFTP_RecvFSTAT(WOLFSSH* ssh, int reqId, byte* data, word32 maxSz)
}
handle = data + idx;

#ifdef WOLFSSH_STOREHANDLE
if (handleSz != sizeof(word32)) {
WLOG(WS_LOG_SFTP, "Unexpected handle size for stored handles");
}
else {
WS_HANDLE_LIST* cur;

cur = SFTP_GetHandleNode(ssh, handle, handleSz);

if (cur == NULL) {
WLOG(WS_LOG_SFTP, "Unknown handle");
return WS_BAD_FILE_E;
}
name = cur->name;
}
#endif

/* try to get file attributes and send back to client */
WMEMSET((byte*)&atr, 0, sizeof(WS_SFTP_FILEATRB));
if (SFTP_GetAttributes_Handle(ssh, handle, handleSz, &atr) != WS_SUCCESS) {
if (SFTP_GetAttributes_Handle(ssh, handle, handleSz, name, &atr)
!= WS_SUCCESS) {
WLOG(WS_LOG_SFTP, "Unable to get fstat of file/directory");
if (wolfSSH_SFTP_CreateStatus(ssh, WOLFSSH_FTP_FAILURE, reqId,
"STAT error", "English", NULL, &outSz) != WS_SIZE_ONLY) {
Expand Down
17 changes: 11 additions & 6 deletions wolfssh/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ extern "C" {

#if defined(NO_FILESYSTEM) && !defined(WOLFSSH_FATFS)
#define WS_DELIM '/'

#elif defined(WOLFSSH_USER_FILESYSTEM)
/* User-defined I/O support, this should be at the top of the ports list
* to override all */

#elif defined(WOLFSSL_NUCLEUS)
#include "storage/nu_storage.h"

Expand Down Expand Up @@ -427,8 +432,6 @@ extern "C" {
#define WFSETTIME(fs,fd,a,m) (0)
#define WCHDIR(fs,b) SYS_FS_DirectryChange((b))

#elif defined(WOLFSSH_USER_FILESYSTEM)
/* User-defined I/O support */
#else
#include <stdlib.h>
#if !defined(_WIN32_WCE) && !defined(FREESCALE_MQX)
Expand Down Expand Up @@ -636,7 +639,12 @@ extern "C" {
#endif
#endif

#ifdef WOLFSSL_NUCLEUS
#if defined(WOLFSSH_USER_FILESYSTEM)
/* User-defined I/O support, this should be at the top of the ports list
* to override all */
#include "myFilesystem.h"

#elif defined(WOLFSSL_NUCLEUS)
#define WSTAT_T struct stat
#define WRMDIR(fs,d) (NU_Remove_Dir((d)) == NU_SUCCESS)?0:1
#define WMKDIR(fs,d,m) (NU_Make_Dir((d)) == NU_SUCCESS)?0:1
Expand Down Expand Up @@ -1433,9 +1441,6 @@ extern "C" {
#define WPWRITE(fs,fd,b,s,o) wPwrite((fd),(b),(s),(o))
#define WPREAD(fs,fd,b,s,o) wPread((fd),(b),(s),(o))

#elif defined(WOLFSSH_USER_FILESYSTEM)
/* User-defined I/O support */
#include "myFilesystem.h"
#else

#include <unistd.h> /* used for rmdir */
Expand Down