Skip to content

Commit

Permalink
Merge pull request #711 from ejohnstown/sftp-symlink
Browse files Browse the repository at this point in the history
SFTP Symlink
  • Loading branch information
JacobBarthelmeh authored Jun 21, 2024
2 parents e2aadb1 + 9bfca14 commit 93853ae
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/wolfsftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2051,9 +2051,9 @@ int wolfSSH_SFTP_RecvOpen(WOLFSSH* ssh, int reqId, byte* data, word32 maxSz)
WS_SFTP_FILEATRB fileAtr;
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");
dir, &fileAtr, 0, ssh->ctx->heap) == WS_SUCCESS) {
if ((fileAtr.per & FILEATRB_PER_MASK_TYPE)
!= FILEATRB_PER_FILE) {
ssh->error = WS_SFTP_NOT_FILE_E;

res = naf;
Expand Down Expand Up @@ -2607,7 +2607,15 @@ static int SFTP_CreateLongName(WS_SFTPNAME* name)
word32 tmp = atr->per;

i = 0;
perm[i++] = (tmp & 0x4000)?'d':'-';
if (tmp & FILEATRB_PER_DIR) {
perm[i++] = 'd';
}
else if (tmp & FILEATRB_PER_LINK) {
perm[i++] = 'l';
}
else {
perm[i++] = '-';
}
perm[i++] = (tmp & 0x100)?'r':'-';
perm[i++] = (tmp & 0x080)?'w':'-';
perm[i++] = (tmp & 0x040)?'x':'-';
Expand Down Expand Up @@ -3153,7 +3161,7 @@ static int wolfSSH_SFTPNAME_readdir(WOLFSSH* ssh, WDIR* dir, WS_SFTPNAME* out,
return WS_FATAL_ERROR;
}

if (SFTP_GetAttributes(ssh->fs, s, &out->atrb, 0, ssh->ctx->heap)
if (SFTP_GetAttributes(ssh->fs, s, &out->atrb, 1, ssh->ctx->heap)
!= WS_SUCCESS) {
WLOG(WS_LOG_SFTP, "Unable to get attribute values for %s",
out->fName);
Expand Down Expand Up @@ -8592,8 +8600,8 @@ int wolfSSH_SFTP_Get(WOLFSSH* ssh, char* from,
NO_BREAK;

case STATE_GET_LSTAT:
WLOG(WS_LOG_SFTP, "SFTP GET STATE: LSTAT");
ret = wolfSSH_SFTP_LSTAT(ssh, from, &state->attrib);
WLOG(WS_LOG_SFTP, "SFTP GET STATE: STAT");
ret = wolfSSH_SFTP_STAT(ssh, from, &state->attrib);
if (ret != WS_SUCCESS) {
if (ssh->error == WS_WANT_READ ||
ssh->error == WS_WANT_WRITE)
Expand All @@ -8603,7 +8611,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;
Expand Down
1 change: 1 addition & 0 deletions wolfssh/wolfsftp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 93853ae

Please sign in to comment.