Skip to content

Commit 9bfca14

Browse files
committed
SFTP Symlink
1. When the server tries to open a file, get the attributes following links. 2. Add decoding links from the file attributes when making a long name. 3. When the server gets a file attributes for the file list, do not follow links. 4. When the client tries to stat a file before getting it, it should use the stat that follows links.
1 parent e2aadb1 commit 9bfca14

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

src/wolfsftp.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2051,9 +2051,9 @@ int wolfSSH_SFTP_RecvOpen(WOLFSSH* ssh, int reqId, byte* data, word32 maxSz)
20512051
WS_SFTP_FILEATRB fileAtr;
20522052
WMEMSET(&fileAtr, 0, sizeof(fileAtr));
20532053
if (SFTP_GetAttributes(ssh->fs,
2054-
dir, &fileAtr, 1, ssh->ctx->heap) == WS_SUCCESS) {
2055-
if ((fileAtr.per & FILEATRB_PER_MASK_TYPE) != FILEATRB_PER_FILE) {
2056-
WLOG(WS_LOG_SFTP, "Not a file");
2054+
dir, &fileAtr, 0, ssh->ctx->heap) == WS_SUCCESS) {
2055+
if ((fileAtr.per & FILEATRB_PER_MASK_TYPE)
2056+
!= FILEATRB_PER_FILE) {
20572057
ssh->error = WS_SFTP_NOT_FILE_E;
20582058

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

26092609
i = 0;
2610-
perm[i++] = (tmp & 0x4000)?'d':'-';
2610+
if (tmp & FILEATRB_PER_DIR) {
2611+
perm[i++] = 'd';
2612+
}
2613+
else if (tmp & FILEATRB_PER_LINK) {
2614+
perm[i++] = 'l';
2615+
}
2616+
else {
2617+
perm[i++] = '-';
2618+
}
26112619
perm[i++] = (tmp & 0x100)?'r':'-';
26122620
perm[i++] = (tmp & 0x080)?'w':'-';
26132621
perm[i++] = (tmp & 0x040)?'x':'-';
@@ -3153,7 +3161,7 @@ static int wolfSSH_SFTPNAME_readdir(WOLFSSH* ssh, WDIR* dir, WS_SFTPNAME* out,
31533161
return WS_FATAL_ERROR;
31543162
}
31553163

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

85948602
case STATE_GET_LSTAT:
8595-
WLOG(WS_LOG_SFTP, "SFTP GET STATE: LSTAT");
8596-
ret = wolfSSH_SFTP_LSTAT(ssh, from, &state->attrib);
8603+
WLOG(WS_LOG_SFTP, "SFTP GET STATE: STAT");
8604+
ret = wolfSSH_SFTP_STAT(ssh, from, &state->attrib);
85978605
if (ret != WS_SUCCESS) {
85988606
if (ssh->error == WS_WANT_READ ||
85998607
ssh->error == WS_WANT_WRITE)
@@ -8603,7 +8611,9 @@ int wolfSSH_SFTP_Get(WOLFSSH* ssh, char* from,
86038611
continue;
86048612
}
86058613
if ((state->attrib.per & FILEATRB_PER_MASK_TYPE)
8606-
!= FILEATRB_PER_FILE) {
8614+
!= FILEATRB_PER_FILE
8615+
&& (state->attrib.per & FILEATRB_PER_MASK_TYPE)
8616+
!= FILEATRB_PER_LINK) {
86078617
WLOG(WS_LOG_SFTP, "Not a file");
86088618
ssh->error = WS_SFTP_NOT_FILE_E;
86098619
ret = WS_FATAL_ERROR;

wolfssh/wolfsftp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ struct WS_SFTP_FILEATRB_EX {
128128

129129
#define FILEATRB_PER_MASK_TYPE 0770000
130130
#define FILEATRB_PER_FILE 0100000
131+
#define FILEATRB_PER_LINK 0120000
131132
#define FILEATRB_PER_DEV_CHAR 0020000
132133
#define FILEATRB_PER_DIR 0040000
133134
#define FILEATRB_PER_DEV_BLOCK 0060000

0 commit comments

Comments
 (0)