From 4f834ae8e45d1c685569de18d52a835b7f066793 Mon Sep 17 00:00:00 2001 From: John Safranek Date: Thu, 13 Jun 2024 15:29:02 -0700 Subject: [PATCH] SFTP Symlink 1. When trying to get a symlink, treat it as a file. 2. When trying to put a symlink, treat it as a file. --- src/wolfsftp.c | 14 ++++++++++---- wolfssh/wolfsftp.h | 1 + 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/wolfsftp.c b/src/wolfsftp.c index 4bc6c8936..cd62a0cd4 100644 --- a/src/wolfsftp.c +++ b/src/wolfsftp.c @@ -2052,8 +2052,10 @@ int wolfSSH_SFTP_RecvOpen(WOLFSSH* ssh, int reqId, byte* data, word32 maxSz) WMEMSET(&fileAtr, 0, sizeof(fileAtr)); if (SFTP_GetAttributes(ssh->fs, dir, &fileAtr, 1, ssh->ctx->heap) == WS_SUCCESS) { - if ((fileAtr.per & FILEATRB_PER_MASK_TYPE) != FILEATRB_PER_FILE) { - WLOG(WS_LOG_SFTP, "Not a file"); + if ((fileAtr.per & FILEATRB_PER_MASK_TYPE) + != FILEATRB_PER_FILE + && (fileAtr.per & FILEATRB_PER_MASK_TYPE) + != FILEATRB_PER_LINK) { ssh->error = WS_SFTP_NOT_FILE_E; res = naf; @@ -8597,7 +8599,9 @@ int wolfSSH_SFTP_Get(WOLFSSH* ssh, char* from, continue; } if ((state->attrib.per & FILEATRB_PER_MASK_TYPE) - != FILEATRB_PER_FILE) { + != FILEATRB_PER_FILE + && (state->attrib.per & FILEATRB_PER_MASK_TYPE) + != FILEATRB_PER_LINK) { WLOG(WS_LOG_SFTP, "Not a file"); ssh->error = WS_SFTP_NOT_FILE_E; ret = WS_FATAL_ERROR; @@ -8844,7 +8848,9 @@ int wolfSSH_SFTP_Put(WOLFSSH* ssh, char* from, char* to, byte resume, from, &fileAtr, 1, ssh->ctx->heap) == WS_SUCCESS) { if ((fileAtr.per & FILEATRB_PER_MASK_TYPE) - != FILEATRB_PER_FILE) { + != FILEATRB_PER_FILE + && (fileAtr.per & FILEATRB_PER_MASK_TYPE) + != FILEATRB_PER_LINK) { WLOG(WS_LOG_SFTP, "Not a file"); ssh->error = WS_SFTP_NOT_FILE_E; ret = WS_FATAL_ERROR; diff --git a/wolfssh/wolfsftp.h b/wolfssh/wolfsftp.h index b5d4afcea..48dc90e4d 100644 --- a/wolfssh/wolfsftp.h +++ b/wolfssh/wolfsftp.h @@ -128,6 +128,7 @@ struct WS_SFTP_FILEATRB_EX { #define FILEATRB_PER_MASK_TYPE 0770000 #define FILEATRB_PER_FILE 0100000 +#define FILEATRB_PER_LINK 0120000 #define FILEATRB_PER_DEV_CHAR 0020000 #define FILEATRB_PER_DIR 0040000 #define FILEATRB_PER_DEV_BLOCK 0060000