mirror of https://github.com/wolfSSL/wolfssh.git
WOLFSSH_FTP_FSETSTAT
parent
87caf4ad04
commit
3d6dfb3504
127
src/wolfsftp.c
127
src/wolfsftp.c
|
@ -1416,6 +1416,11 @@ int wolfSSH_SFTP_read(WOLFSSH* ssh)
|
||||||
wolfSSH_SFTP_buffer_data(&state->buffer),
|
wolfSSH_SFTP_buffer_data(&state->buffer),
|
||||||
wolfSSH_SFTP_buffer_size(&state->buffer));
|
wolfSSH_SFTP_buffer_size(&state->buffer));
|
||||||
break;
|
break;
|
||||||
|
case WOLFSSH_FTP_FSETSTAT:
|
||||||
|
ret = wolfSSH_SFTP_RecvFSetSTAT(ssh, state->reqId,
|
||||||
|
wolfSSH_SFTP_buffer_data(&state->buffer),
|
||||||
|
wolfSSH_SFTP_buffer_size(&state->buffer));
|
||||||
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef NO_WOLFSSH_DIR
|
#ifndef NO_WOLFSSH_DIR
|
||||||
|
@ -4856,8 +4861,10 @@ static int SFTP_SetFileAttributes(WOLFSSH* ssh, char* name, WS_SFTP_FILEATRB* at
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* check if time attribute present */
|
/* check if time attribute present */
|
||||||
if (atr->flags & WOLFSSH_FILEATRB_TIME) {
|
if (ret == WS_SUCCESS && (atr->flags & WOLFSSH_FILEATRB_TIME)) {
|
||||||
/* @TODO set time */
|
if (WSETTIME(ssh->fs, name, atr->atime, atr->mtime) != 0) {
|
||||||
|
ret = WS_BAD_FILE_E;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check if extended attributes are present */
|
/* check if extended attributes are present */
|
||||||
|
@ -4870,6 +4877,47 @@ static int SFTP_SetFileAttributes(WOLFSSH* ssh, char* name, WS_SFTP_FILEATRB* at
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* sets a files attributes
|
||||||
|
* returns WS_SUCCESS on success */
|
||||||
|
static int SFTP_SetFileAttributesHandle(WOLFSSH* ssh, WFD handle, WS_SFTP_FILEATRB* atr)
|
||||||
|
{
|
||||||
|
int ret = WS_SUCCESS;
|
||||||
|
|
||||||
|
/* check if size attribute present */
|
||||||
|
if (atr->flags & WOLFSSH_FILEATRB_SIZE) {
|
||||||
|
/* @TODO set file size */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* check if uid and gid attribute present */
|
||||||
|
if (atr->flags & WOLFSSH_FILEATRB_UIDGID) {
|
||||||
|
/* @TODO set group and user id */
|
||||||
|
}
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* check if time attribute present */
|
||||||
|
if (ret == WS_SUCCESS && (atr->flags & WOLFSSH_FILEATRB_TIME)) {
|
||||||
|
if (WFSETTIME(ssh->fs, handle, atr->atime, atr->mtime) != 0) {
|
||||||
|
ret = WS_BAD_FILE_E;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* check if extended attributes are present */
|
||||||
|
if (atr->flags & WOLFSSH_FILEATRB_EXT) {
|
||||||
|
/* @TODO handle extensions */
|
||||||
|
}
|
||||||
|
|
||||||
|
(void)ssh;
|
||||||
|
return ret ;
|
||||||
|
}
|
||||||
|
|
||||||
/* Handles a packet sent to set attributes of path
|
/* Handles a packet sent to set attributes of path
|
||||||
*
|
*
|
||||||
* returns WS_SUCCESS on success
|
* returns WS_SUCCESS on success
|
||||||
|
@ -4946,6 +4994,81 @@ int wolfSSH_SFTP_RecvSetSTAT(WOLFSSH* ssh, int reqId, byte* data, word32 maxSz)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Handles a packet sent to set attributes of file handle
|
||||||
|
*
|
||||||
|
* returns WS_SUCCESS on success
|
||||||
|
*/
|
||||||
|
int wolfSSH_SFTP_RecvFSetSTAT(WOLFSSH* ssh, int reqId, byte* data, word32 maxSz)
|
||||||
|
{
|
||||||
|
WS_SFTP_FILEATRB atr;
|
||||||
|
int ret = WS_SUCCESS;
|
||||||
|
|
||||||
|
WFD fd;
|
||||||
|
word32 sz;
|
||||||
|
word32 idx = 0;
|
||||||
|
|
||||||
|
byte* out = NULL;
|
||||||
|
word32 outSz = 0;
|
||||||
|
|
||||||
|
char suc[] = "Set Attirbutes";
|
||||||
|
char ser[] = "Unable to set attributes error";
|
||||||
|
char per[] = "Unable to parse attributes error";
|
||||||
|
char* res = suc;
|
||||||
|
byte type = WOLFSSH_FTP_OK;
|
||||||
|
|
||||||
|
if (ssh == NULL) {
|
||||||
|
return WS_BAD_ARGUMENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
WLOG(WS_LOG_SFTP, "Receiving WOLFSSH_FTP_FSETSTAT");
|
||||||
|
|
||||||
|
/* get file handle */
|
||||||
|
ato32(data + idx, &sz); idx += UINT32_SZ;
|
||||||
|
if (sz + idx > maxSz || sz > WOLFSSH_MAX_HANDLE) {
|
||||||
|
return WS_BUFFER_E;
|
||||||
|
}
|
||||||
|
WMEMSET((byte*)&fd, 0, sizeof(WFD));
|
||||||
|
WMEMCPY((byte*)&fd, data + idx, sz); idx += sz;
|
||||||
|
|
||||||
|
if (ret == WS_SUCCESS &&
|
||||||
|
SFTP_ParseAtributes_buffer(ssh, &atr, data, &idx, maxSz) != 0) {
|
||||||
|
type = WOLFSSH_FTP_FAILURE;
|
||||||
|
res = per;
|
||||||
|
ret = WS_BAD_FILE_E;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* try to set file attributes and send status back to client */
|
||||||
|
if (ret == WS_SUCCESS && (ret = SFTP_SetFileAttributesHandle(ssh, fd, &atr))
|
||||||
|
!= WS_SUCCESS) {
|
||||||
|
/* tell peer that was not ok */
|
||||||
|
WLOG(WS_LOG_SFTP, "Unable to get set attributes of open file");
|
||||||
|
type = WOLFSSH_FTP_FAILURE;
|
||||||
|
res = ser;
|
||||||
|
ret = WS_BAD_FILE_E;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wolfSSH_SFTP_CreateStatus(ssh, type, reqId, res, "English", NULL,
|
||||||
|
&outSz) != WS_SIZE_ONLY) {
|
||||||
|
return WS_FATAL_ERROR;
|
||||||
|
}
|
||||||
|
out = (byte*)WMALLOC(outSz, ssh->ctx->heap, DYNTYPE_BUFFER);
|
||||||
|
if (out == NULL) {
|
||||||
|
return WS_MEMORY_E;
|
||||||
|
}
|
||||||
|
if (wolfSSH_SFTP_CreateStatus(ssh, type, reqId, res, "English", out,
|
||||||
|
&outSz) != WS_SUCCESS) {
|
||||||
|
WFREE(out, ssh->ctx->heap, DYNTYPE_BUFFER);
|
||||||
|
return WS_FATAL_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* set send out buffer, "out" is taken by ssh */
|
||||||
|
wolfSSH_SFTP_RecvSetSend(ssh, out, outSz);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* _WIN32_WCE */
|
#endif /* _WIN32_WCE */
|
||||||
#endif /* !NO_WOLFSSH_SERVER */
|
#endif /* !NO_WOLFSSH_SERVER */
|
||||||
|
|
||||||
|
|
|
@ -364,6 +364,9 @@ extern "C" {
|
||||||
#define WREWIND(s) rewind((s))
|
#define WREWIND(s) rewind((s))
|
||||||
#define WSEEK_END SEEK_END
|
#define WSEEK_END SEEK_END
|
||||||
#define WBADFILE NULL
|
#define WBADFILE NULL
|
||||||
|
#define WSETTIME(fs,f,a,m) (0)
|
||||||
|
#define WFSETTIME(fs,fd,a,m) (0)
|
||||||
|
|
||||||
#ifdef WOLFSSL_VXWORKS
|
#ifdef WOLFSSL_VXWORKS
|
||||||
#define WUTIMES(f,t) (WS_SUCCESS)
|
#define WUTIMES(f,t) (WS_SUCCESS)
|
||||||
#else
|
#else
|
||||||
|
@ -372,8 +375,10 @@ extern "C" {
|
||||||
|
|
||||||
#ifndef USE_WINDOWS_API
|
#ifndef USE_WINDOWS_API
|
||||||
#define WCHMOD(fs,f,m) chmod((f),(m))
|
#define WCHMOD(fs,f,m) chmod((f),(m))
|
||||||
|
#define WFCHMOD(fs,fd,m) fchmod((fd),(m))
|
||||||
#else
|
#else
|
||||||
#define WCHMOD(fs,f,m) _chmod((f),(m))
|
#define WCHMOD(fs,f,m) _chmod((f),(m))
|
||||||
|
#define WFCHMOD(fs,fd,m) _fchmod((fd),(m))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (defined(WOLFSSH_SCP) || \
|
#if (defined(WOLFSSH_SCP) || \
|
||||||
|
|
|
@ -254,6 +254,8 @@ WOLFSSH_LOCAL int wolfSSH_SFTP_RecvSetSTAT(WOLFSSH* ssh, int reqId, byte* data,
|
||||||
word32 maxSz);
|
word32 maxSz);
|
||||||
WOLFSSH_LOCAL int wolfSSH_SFTP_RecvFSTAT(WOLFSSH* ssh, int reqId, byte* data,
|
WOLFSSH_LOCAL int wolfSSH_SFTP_RecvFSTAT(WOLFSSH* ssh, int reqId, byte* data,
|
||||||
word32 maxSz);
|
word32 maxSz);
|
||||||
|
WOLFSSH_API int wolfSSH_SFTP_RecvFSetSTAT(WOLFSSH* ssh, int reqId, byte* data,
|
||||||
|
word32 maxSz);
|
||||||
|
|
||||||
#ifndef NO_WOLFSSH_DIR
|
#ifndef NO_WOLFSSH_DIR
|
||||||
WOLFSSH_LOCAL int wolfSSH_SFTP_RecvOpenDir(WOLFSSH* ssh, int reqId, byte* data,
|
WOLFSSH_LOCAL int wolfSSH_SFTP_RecvOpenDir(WOLFSSH* ssh, int reqId, byte* data,
|
||||||
|
|
Loading…
Reference in New Issue