@@ -994,11 +994,11 @@ static INLINE int SFTP_GetSz(byte* buf, word32* sz,
994994
995995#ifndef NO_WOLFSSH_SERVER
996996
997- #ifndef WOLFSSH_USER_FILESYSTEM
997+ #if !defined( WOLFSSH_USER_FILESYSTEM )
998998static int SFTP_GetAttributes (void * fs , const char * fileName ,
999999 WS_SFTP_FILEATRB * atr , byte noFollow , void * heap );
10001000static int SFTP_GetAttributes_Handle (WOLFSSH * ssh , byte * handle , int handleSz ,
1001- WS_SFTP_FILEATRB * atr );
1001+ char * name , WS_SFTP_FILEATRB * atr );
10021002#endif
10031003
10041004/* unique from other packets because the request ID is not also sent.
@@ -3135,7 +3135,9 @@ static int wolfSSH_SFTPNAME_readdir(WOLFSSH* ssh, WDIR* dir, WS_SFTPNAME* out,
31353135}
31363136
31373137#elif defined(MICROCHIP_MPLAB_HARMONY )
3138+ #ifndef WOLFSSH_USER_FILESYSTEM
31383139int SFTP_GetAttributesStat (WS_SFTP_FILEATRB * atr , WSTAT_T * stats );
3140+ #endif
31393141
31403142/* helper function that gets file information from reading directory
31413143 *
@@ -4416,7 +4418,10 @@ int SFTP_RemoveHandleNode(WOLFSSH* ssh, byte* handle, word32 handleSz)
44164418#endif /* WOLFSSH_STOREHANDLE */
44174419
44184420
4419- #ifdef WOLFSSL_NUCLEUS
4421+ #if defined(WOLFSSH_USER_FILESYSTEM )
4422+ /* User-defined I/O support */
4423+
4424+ #elif defined(WOLFSSL_NUCLEUS )
44204425
44214426#ifndef NO_WOLFSSH_MKTIME
44224427
@@ -4539,22 +4544,15 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
45394544 * returns WS_SUCCESS on success
45404545 */
45414546int SFTP_GetAttributes_Handle (WOLFSSH * ssh , byte * handle , int handleSz ,
4542- WS_SFTP_FILEATRB * atr )
4547+ char * name , WS_SFTP_FILEATRB * atr )
45434548{
45444549 DSTAT stats ;
4545- WS_HANDLE_LIST * cur ;
45464550
45474551 if (handle == NULL || atr == NULL ) {
45484552 return WS_FATAL_ERROR ;
45494553 }
45504554
4551- cur = SFTP_GetHandleNode (ssh , handle , handleSz );
4552- if (cur == NULL ) {
4553- WLOG (WS_LOG_SFTP , "Unknown handle" );
4554- return WS_BAD_FILE_E ;
4555- }
4556-
4557- if (WSTAT (ssh -> fs , cur -> name , & stats ) != NU_SUCCESS ) {
4555+ if (WSTAT (ssh -> fs , name , & stats ) != NU_SUCCESS ) {
45584556 return WS_FATAL_ERROR ;
45594557 }
45604558
@@ -4708,10 +4706,9 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
47084706 * Fills out a WS_SFTP_FILEATRB structure
47094707 * returns WS_SUCCESS on success */
47104708int SFTP_GetAttributes_Handle (WOLFSSH * ssh , byte * handle , int handleSz ,
4711- WS_SFTP_FILEATRB * atr )
4709+ char * name , WS_SFTP_FILEATRB * atr )
47124710{
47134711 int err ;
4714- WS_HANDLE_LIST * cur ;
47154712 MQX_FILE_PTR mfs_ptr ;
47164713 MFS_SEARCH_DATA search_data ;
47174714 MFS_SEARCH_PARAM search ;
@@ -4721,14 +4718,8 @@ int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
47214718 }
47224719 mfs_ptr = (MQX_FILE_PTR )ssh -> fs ;
47234720
4724- cur = SFTP_GetHandleNode (ssh , handle , handleSz );
4725- if (cur == NULL ) {
4726- WLOG (WS_LOG_SFTP , "Unknown handle" );
4727- return WS_BAD_FILE_E ;
4728- }
4729-
47304721 search .ATTRIBUTE = MFS_SEARCH_ANY ;
4731- search .WILDCARD = cur -> name ;
4722+ search .WILDCARD = name ;
47324723 search .SEARCH_DATA_PTR = & search_data ;
47334724
47344725 err = ioctl (mfs_ptr , IO_IOCTL_FIND_FIRST_FILE , (uint32_t * )& search );
@@ -4829,22 +4820,15 @@ static int SFTP_GetAttributes(void* fs, const char* fileName,
48294820}
48304821
48314822static int SFTP_GetAttributes_Handle (WOLFSSH * ssh , byte * handle , int handleSz ,
4832- WS_SFTP_FILEATRB * atr )
4823+ char * name , WS_SFTP_FILEATRB * atr )
48334824{
48344825 FILINFO info ;
4835- WS_HANDLE_LIST * cur ;
48364826
48374827 if (handle == NULL || atr == NULL ) {
48384828 return WS_FATAL_ERROR ;
48394829 }
48404830
4841- cur = SFTP_GetHandleNode (ssh , handle , handleSz );
4842- if (cur == NULL ) {
4843- WLOG (WS_LOG_SFTP , "Unknown handle" );
4844- return WS_BAD_FILE_E ;
4845- }
4846-
4847- if (f_stat (cur -> name , & info ) != FR_OK ) {
4831+ if (f_stat (name , & info ) != FR_OK ) {
48484832 return WS_FATAL_ERROR ;
48494833 }
48504834
@@ -4877,6 +4861,9 @@ static int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
48774861 atr -> atime = info .ftime ;
48784862 atr -> mtime = info .ftime ;
48794863#endif /* NO_WOLFSSH_MKTIME */
4864+
4865+ WOLFSSH_UNUSED (ssh );
4866+ WOLFSSH_UNUSED (handleSz );
48804867 return WS_SUCCESS ;
48814868}
48824869
@@ -4919,21 +4906,18 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
49194906}
49204907
49214908int SFTP_GetAttributes_Handle (WOLFSSH * ssh , byte * handle , int handleSz ,
4922- WS_SFTP_FILEATRB * atr )
4909+ char * name , WS_SFTP_FILEATRB * atr )
49234910{
49244911 WOLFSSH_UNUSED (ssh );
49254912 WOLFSSH_UNUSED (handle );
49264913 WOLFSSH_UNUSED (handleSz );
49274914 WOLFSSH_UNUSED (atr );
4915+ WOLFSSH_UNUSED (name );
49284916
49294917 WLOG (WS_LOG_SFTP , "SFTP_GetAttributes_Handle() not implemented yet" );
49304918 return WS_NOT_COMPILED ;
49314919}
49324920
4933-
4934- #elif defined(WOLFSSH_USER_FILESYSTEM )
4935- /* User-defined I/O support */
4936-
49374921#elif defined(MICROCHIP_MPLAB_HARMONY )
49384922int SFTP_GetAttributesStat (WS_SFTP_FILEATRB * atr , WSTAT_T * stats )
49394923{
@@ -5021,20 +5005,8 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
50215005 * returns WS_SUCCESS on success
50225006 */
50235007int SFTP_GetAttributes_Handle (WOLFSSH * ssh , byte * handle , int handleSz ,
5024- WS_SFTP_FILEATRB * atr )
5008+ char * name , WS_SFTP_FILEATRB * atr )
50255009{
5026- WS_HANDLE_LIST * cur ;
5027-
5028- if (handleSz != sizeof (word32 )) {
5029- WLOG (WS_LOG_SFTP , "Unexpected handle size SFTP_GetAttributes_Handle()" );
5030- }
5031-
5032- cur = SFTP_GetHandleNode (ssh , handle , handleSz );
5033- if (cur == NULL ) {
5034- WLOG (WS_LOG_SFTP , "Unknown handle" );
5035- return WS_BAD_FILE_E ;
5036- }
5037-
50385010 return SFTP_GetAttributesHelper (atr , cur -> name );
50395011}
50405012
@@ -5096,7 +5068,7 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
50965068 * returns WS_SUCCESS on success
50975069 */
50985070int SFTP_GetAttributes_Handle (WOLFSSH * ssh , byte * handle , int handleSz ,
5099- WS_SFTP_FILEATRB * atr )
5071+ char * name , WS_SFTP_FILEATRB * atr )
51005072{
51015073 struct stat stats ;
51025074
@@ -5130,6 +5102,7 @@ int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
51305102 /* @TODO handle attribute extensions */
51315103
51325104 WOLFSSH_UNUSED (ssh );
5105+ WOLFSSH_UNUSED (name );
51335106 return WS_SUCCESS ;
51345107}
51355108#endif
@@ -5147,6 +5120,7 @@ int wolfSSH_SFTP_RecvFSTAT(WOLFSSH* ssh, int reqId, byte* data, word32 maxSz)
51475120 byte * handle ;
51485121 word32 idx = 0 ;
51495122 int ret = WS_SUCCESS ;
5123+ char * name = NULL ;
51505124
51515125 byte * out = NULL ;
51525126 word32 outSz = 0 ;
@@ -5168,9 +5142,27 @@ int wolfSSH_SFTP_RecvFSTAT(WOLFSSH* ssh, int reqId, byte* data, word32 maxSz)
51685142 }
51695143 handle = data + idx ;
51705144
5145+ #ifdef WOLFSSH_STOREHANDLE
5146+ if (handleSz != sizeof (word32 )) {
5147+ WLOG (WS_LOG_SFTP , "Unexpected handle size for stored handles" );
5148+ }
5149+ else {
5150+ WS_HANDLE_LIST * cur ;
5151+
5152+ cur = SFTP_GetHandleNode (ssh , handle , handleSz );
5153+
5154+ if (cur == NULL ) {
5155+ WLOG (WS_LOG_SFTP , "Unknown handle" );
5156+ return WS_BAD_FILE_E ;
5157+ }
5158+ name = cur -> name ;
5159+ }
5160+ #endif
5161+
51715162 /* try to get file attributes and send back to client */
51725163 WMEMSET ((byte * )& atr , 0 , sizeof (WS_SFTP_FILEATRB ));
5173- if (SFTP_GetAttributes_Handle (ssh , handle , handleSz , & atr ) != WS_SUCCESS ) {
5164+ if (SFTP_GetAttributes_Handle (ssh , handle , handleSz , name , & atr )
5165+ != WS_SUCCESS ) {
51745166 WLOG (WS_LOG_SFTP , "Unable to get fstat of file/directory" );
51755167 if (wolfSSH_SFTP_CreateStatus (ssh , WOLFSSH_FTP_FAILURE , reqId ,
51765168 "STAT error" , "English" , NULL , & outSz ) != WS_SIZE_ONLY ) {
0 commit comments