From 03f82ab744bc919196809708efe405bf37172bbd Mon Sep 17 00:00:00 2001 From: Fabio <507164+falemagn@users.noreply.github.com> Date: Thu, 9 Nov 2023 12:00:49 +0100 Subject: [PATCH 1/3] Made setting file modes portable, by means of defining the WOLFSSH_SFTP_SETFILEMODE and WOLFSSH_SFTP_SETMODE macros, in which case the functions SFTP_SetMode and SFTP_SetFileMode will have to be externally defined for the platform the library is being ported to. --- src/wolfsftp.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/wolfsftp.c b/src/wolfsftp.c index d50792fd3..f7210cae3 100644 --- a/src/wolfsftp.c +++ b/src/wolfsftp.c @@ -5087,19 +5087,29 @@ int wolfSSH_SFTP_RecvLSTAT(WOLFSSH* ssh, int reqId, byte* data, word32 maxSz) return ret; } - -#if !defined(USE_WINDOWS_API) && !defined(WOLFSSH_ZEPHYR) +#if !defined(USE_WINDOWS_API) && !defined(WOLFSSH_ZEPHYR) && !defined(WOLFSSH_SFTP_SETMODE) /* Set the files mode * return WS_SUCCESS on success */ -static int SFTP_SetMode(WOLFSSH* ssh, char* name, word32 mode) { - WOLFSSH_UNUSED(ssh); - if (WCHMOD(ssh->fs, name, mode) != 0) { +static int SFTP_SetMode(void* fs, char* name, word32 mode) { + WOLFSSH_UNUSED(fs) + if (WCHMOD(fs, name, mode) != 0) { return WS_BAD_FILE_E; } return WS_SUCCESS; } #endif +#if !defined(USE_WINDOWS_API) && !defined(WOLFSSH_SFTP_SETMODEHANDLE) +/* Set the files mode + * return WS_SUCCESS on success */ +static int SFTP_SetModeHandle(void* fs, WFD handle, word32 mode) { + WOLFSSH_UNUSED(fs) + if (WFCHMOD(fs, handle, mode) != 0) { + return WS_BAD_FILE_E; + } + return WS_SUCCESS; +} +#endif #if !defined(_WIN32_WCE) && !defined(WOLFSSH_ZEPHYR) @@ -5122,7 +5132,7 @@ static int SFTP_SetFileAttributes(WOLFSSH* ssh, char* name, WS_SFTP_FILEATRB* at #if !defined(USE_WINDOWS_API) && !defined(WOLFSSH_ZEPHYR) /* check if permissions attribute present */ if (atr->flags & WOLFSSH_FILEATRB_PERM) { - ret = SFTP_SetMode(ssh, name, atr->per); + ret = SFTP_SetMode(ssh->fs, name, atr->per); } #endif @@ -5162,9 +5172,7 @@ static int SFTP_SetFileAttributesHandle(WOLFSSH* ssh, WFD handle, WS_SFTP_FILEAT #ifndef USE_WINDOWS_API /* check if permissions attribute present */ if (atr->flags & WOLFSSH_FILEATRB_PERM) { - if (WFCHMOD(ssh->fs, handle, atr->per) != 0) { - ret = WS_BAD_FILE_E; - } + ret = SFTP_SetModeHandle(ssh->fs, handle, atr->per); } #endif From 74c15231d977ad85ad1f8c599598ae529453d120 Mon Sep 17 00:00:00 2001 From: Fabio <507164+falemagn@users.noreply.github.com> Date: Thu, 9 Nov 2023 15:45:18 +0100 Subject: [PATCH 2/3] Don't compile SFTP_SetModeHandle on Zephyr. --- src/wolfsftp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wolfsftp.c b/src/wolfsftp.c index f7210cae3..a7d26fb99 100644 --- a/src/wolfsftp.c +++ b/src/wolfsftp.c @@ -5099,7 +5099,7 @@ static int SFTP_SetMode(void* fs, char* name, word32 mode) { } #endif -#if !defined(USE_WINDOWS_API) && !defined(WOLFSSH_SFTP_SETMODEHANDLE) +#if !defined(USE_WINDOWS_API) && !defined(WOLFSSH_ZEPHYR) && !defined(WOLFSSH_SFTP_SETMODEHANDLE) /* Set the files mode * return WS_SUCCESS on success */ static int SFTP_SetModeHandle(void* fs, WFD handle, word32 mode) { From a60df27e51df9d2a5d85df102d809d31d8d58ac6 Mon Sep 17 00:00:00 2001 From: Fabio <507164+falemagn@users.noreply.github.com> Date: Fri, 17 Nov 2023 17:34:22 +0100 Subject: [PATCH 3/3] Added missing semicolons. --- src/wolfsftp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wolfsftp.c b/src/wolfsftp.c index a7d26fb99..a3e933e6f 100644 --- a/src/wolfsftp.c +++ b/src/wolfsftp.c @@ -5091,7 +5091,7 @@ int wolfSSH_SFTP_RecvLSTAT(WOLFSSH* ssh, int reqId, byte* data, word32 maxSz) /* Set the files mode * return WS_SUCCESS on success */ static int SFTP_SetMode(void* fs, char* name, word32 mode) { - WOLFSSH_UNUSED(fs) + WOLFSSH_UNUSED(fs); if (WCHMOD(fs, name, mode) != 0) { return WS_BAD_FILE_E; } @@ -5103,7 +5103,7 @@ static int SFTP_SetMode(void* fs, char* name, word32 mode) { /* Set the files mode * return WS_SUCCESS on success */ static int SFTP_SetModeHandle(void* fs, WFD handle, word32 mode) { - WOLFSSH_UNUSED(fs) + WOLFSSH_UNUSED(fs); if (WFCHMOD(fs, handle, mode) != 0) { return WS_BAD_FILE_E; }