@@ -994,14 +994,11 @@ static INLINE int SFTP_GetSz(byte* buf, word32* sz,
994994
995995#ifndef NO_WOLFSSH_SERVER
996996
997- #if defined(MICROCHIP_MPLAB_HARMONY ) || defined(WOLFSSH_ZEPHYR ) || \
998- defined(WOLFSSH_FATFS ) || defined(FREESCALE_MQX ) || \
999- defined(USE_WINDOWS_API ) || defined(WOLFSSL_NUCLEUS ) || \
1000- !defined(WOLFSSH_USER_FILESYSTEM )
997+ #if !defined(WOLFSSH_USER_FILESYSTEM )
1001998static int SFTP_GetAttributes (void * fs , const char * fileName ,
1002999 WS_SFTP_FILEATRB * atr , byte noFollow , void * heap );
10031000static int SFTP_GetAttributes_Handle (WOLFSSH * ssh , byte * handle , int handleSz ,
1004- WS_SFTP_FILEATRB * atr );
1001+ char * name , WS_SFTP_FILEATRB * atr );
10051002#endif
10061003
10071004/* unique from other packets because the request ID is not also sent.
@@ -3138,7 +3135,9 @@ static int wolfSSH_SFTPNAME_readdir(WOLFSSH* ssh, WDIR* dir, WS_SFTPNAME* out,
31383135}
31393136
31403137#elif defined(MICROCHIP_MPLAB_HARMONY )
3138+ #ifndef WOLFSSH_USER_FILESYSTEM
31413139int SFTP_GetAttributesStat (WS_SFTP_FILEATRB * atr , WSTAT_T * stats );
3140+ #endif
31423141
31433142/* helper function that gets file information from reading directory
31443143 *
@@ -4419,7 +4418,10 @@ int SFTP_RemoveHandleNode(WOLFSSH* ssh, byte* handle, word32 handleSz)
44194418#endif /* WOLFSSH_STOREHANDLE */
44204419
44214420
4422- #ifdef WOLFSSL_NUCLEUS
4421+ #if defined(WOLFSSH_USER_FILESYSTEM )
4422+ /* User-defined I/O support */
4423+
4424+ #elif defined(WOLFSSL_NUCLEUS )
44234425
44244426#ifndef NO_WOLFSSH_MKTIME
44254427
@@ -4542,22 +4544,15 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
45424544 * returns WS_SUCCESS on success
45434545 */
45444546int SFTP_GetAttributes_Handle (WOLFSSH * ssh , byte * handle , int handleSz ,
4545- WS_SFTP_FILEATRB * atr )
4547+ char * name , WS_SFTP_FILEATRB * atr )
45464548{
45474549 DSTAT stats ;
4548- WS_HANDLE_LIST * cur ;
45494550
45504551 if (handle == NULL || atr == NULL ) {
45514552 return WS_FATAL_ERROR ;
45524553 }
45534554
4554- cur = SFTP_GetHandleNode (ssh , handle , handleSz );
4555- if (cur == NULL ) {
4556- WLOG (WS_LOG_SFTP , "Unknown handle" );
4557- return WS_BAD_FILE_E ;
4558- }
4559-
4560- if (WSTAT (ssh -> fs , cur -> name , & stats ) != NU_SUCCESS ) {
4555+ if (WSTAT (ssh -> fs , name , & stats ) != NU_SUCCESS ) {
45614556 return WS_FATAL_ERROR ;
45624557 }
45634558
@@ -4711,10 +4706,9 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
47114706 * Fills out a WS_SFTP_FILEATRB structure
47124707 * returns WS_SUCCESS on success */
47134708int SFTP_GetAttributes_Handle (WOLFSSH * ssh , byte * handle , int handleSz ,
4714- WS_SFTP_FILEATRB * atr )
4709+ char * name , WS_SFTP_FILEATRB * atr )
47154710{
47164711 int err ;
4717- WS_HANDLE_LIST * cur ;
47184712 MQX_FILE_PTR mfs_ptr ;
47194713 MFS_SEARCH_DATA search_data ;
47204714 MFS_SEARCH_PARAM search ;
@@ -4724,14 +4718,8 @@ int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
47244718 }
47254719 mfs_ptr = (MQX_FILE_PTR )ssh -> fs ;
47264720
4727- cur = SFTP_GetHandleNode (ssh , handle , handleSz );
4728- if (cur == NULL ) {
4729- WLOG (WS_LOG_SFTP , "Unknown handle" );
4730- return WS_BAD_FILE_E ;
4731- }
4732-
47334721 search .ATTRIBUTE = MFS_SEARCH_ANY ;
4734- search .WILDCARD = cur -> name ;
4722+ search .WILDCARD = name ;
47354723 search .SEARCH_DATA_PTR = & search_data ;
47364724
47374725 err = ioctl (mfs_ptr , IO_IOCTL_FIND_FIRST_FILE , (uint32_t * )& search );
@@ -4832,22 +4820,15 @@ static int SFTP_GetAttributes(void* fs, const char* fileName,
48324820}
48334821
48344822static int SFTP_GetAttributes_Handle (WOLFSSH * ssh , byte * handle , int handleSz ,
4835- WS_SFTP_FILEATRB * atr )
4823+ char * name , WS_SFTP_FILEATRB * atr )
48364824{
48374825 FILINFO info ;
4838- WS_HANDLE_LIST * cur ;
48394826
48404827 if (handle == NULL || atr == NULL ) {
48414828 return WS_FATAL_ERROR ;
48424829 }
48434830
4844- cur = SFTP_GetHandleNode (ssh , handle , handleSz );
4845- if (cur == NULL ) {
4846- WLOG (WS_LOG_SFTP , "Unknown handle" );
4847- return WS_BAD_FILE_E ;
4848- }
4849-
4850- if (f_stat (cur -> name , & info ) != FR_OK ) {
4831+ if (f_stat (name , & info ) != FR_OK ) {
48514832 return WS_FATAL_ERROR ;
48524833 }
48534834
@@ -4922,12 +4903,13 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
49224903}
49234904
49244905int SFTP_GetAttributes_Handle (WOLFSSH * ssh , byte * handle , int handleSz ,
4925- WS_SFTP_FILEATRB * atr )
4906+ char * name , WS_SFTP_FILEATRB * atr )
49264907{
49274908 WOLFSSH_UNUSED (ssh );
49284909 WOLFSSH_UNUSED (handle );
49294910 WOLFSSH_UNUSED (handleSz );
49304911 WOLFSSH_UNUSED (atr );
4912+ WOLFSSH_UNUSED (name );
49314913
49324914 WLOG (WS_LOG_SFTP , "SFTP_GetAttributes_Handle() not implemented yet" );
49334915 return WS_NOT_COMPILED ;
@@ -5020,26 +5002,11 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
50205002 * returns WS_SUCCESS on success
50215003 */
50225004int SFTP_GetAttributes_Handle (WOLFSSH * ssh , byte * handle , int handleSz ,
5023- WS_SFTP_FILEATRB * atr )
5005+ char * name , WS_SFTP_FILEATRB * atr )
50245006{
5025- WS_HANDLE_LIST * cur ;
5026-
5027- if (handleSz != sizeof (word32 )) {
5028- WLOG (WS_LOG_SFTP , "Unexpected handle size SFTP_GetAttributes_Handle()" );
5029- }
5030-
5031- cur = SFTP_GetHandleNode (ssh , handle , handleSz );
5032- if (cur == NULL ) {
5033- WLOG (WS_LOG_SFTP , "Unknown handle" );
5034- return WS_BAD_FILE_E ;
5035- }
5036-
50375007 return SFTP_GetAttributesHelper (atr , cur -> name );
50385008}
50395009
5040- #elif defined(WOLFSSH_USER_FILESYSTEM )
5041- /* User-defined I/O support */
5042-
50435010#else
50445011
50455012/* NOTE: if atr->flags is set to a value of 0 then no attributes are set.
@@ -5098,7 +5065,7 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
50985065 * returns WS_SUCCESS on success
50995066 */
51005067int SFTP_GetAttributes_Handle (WOLFSSH * ssh , byte * handle , int handleSz ,
5101- WS_SFTP_FILEATRB * atr )
5068+ char * name , WS_SFTP_FILEATRB * atr )
51025069{
51035070 struct stat stats ;
51045071
@@ -5132,6 +5099,7 @@ int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
51325099 /* @TODO handle attribute extensions */
51335100
51345101 WOLFSSH_UNUSED (ssh );
5102+ WOLFSSH_UNUSED (name );
51355103 return WS_SUCCESS ;
51365104}
51375105#endif
@@ -5149,6 +5117,7 @@ int wolfSSH_SFTP_RecvFSTAT(WOLFSSH* ssh, int reqId, byte* data, word32 maxSz)
51495117 byte * handle ;
51505118 word32 idx = 0 ;
51515119 int ret = WS_SUCCESS ;
5120+ char * name = NULL ;
51525121
51535122 byte * out = NULL ;
51545123 word32 outSz = 0 ;
@@ -5170,9 +5139,27 @@ int wolfSSH_SFTP_RecvFSTAT(WOLFSSH* ssh, int reqId, byte* data, word32 maxSz)
51705139 }
51715140 handle = data + idx ;
51725141
5142+ #ifdef WOLFSSH_STOREHANDLE
5143+ if (handleSz != sizeof (word32 )) {
5144+ WLOG (WS_LOG_SFTP , "Unexpected handle size for stored handles" );
5145+ }
5146+ else {
5147+ WS_HANDLE_LIST * cur ;
5148+
5149+ cur = SFTP_GetHandleNode (ssh , handle , handleSz );
5150+
5151+ if (cur == NULL ) {
5152+ WLOG (WS_LOG_SFTP , "Unknown handle" );
5153+ return WS_BAD_FILE_E ;
5154+ }
5155+ name = cur -> name ;
5156+ }
5157+ #endif
5158+
51735159 /* try to get file attributes and send back to client */
51745160 WMEMSET ((byte * )& atr , 0 , sizeof (WS_SFTP_FILEATRB ));
5175- if (SFTP_GetAttributes_Handle (ssh , handle , handleSz , & atr ) != WS_SUCCESS ) {
5161+ if (SFTP_GetAttributes_Handle (ssh , handle , handleSz , name , & atr )
5162+ != WS_SUCCESS ) {
51765163 WLOG (WS_LOG_SFTP , "Unable to get fstat of file/directory" );
51775164 if (wolfSSH_SFTP_CreateStatus (ssh , WOLFSSH_FTP_FAILURE , reqId ,
51785165 "STAT error" , "English" , NULL , & outSz ) != WS_SIZE_ONLY ) {
0 commit comments