mirror of https://github.com/wolfSSL/wolfssh.git
wolfSCP: allow overriding GETHDR, disable functions that call snprinf
according to compile optionspull/324/head
parent
4e76f3dd72
commit
d7cd61d926
|
@ -235,6 +235,8 @@ static int ScpSourceInit(WOLFSSH* ssh)
|
||||||
return WS_SUCCESS;
|
return WS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef NO_SCP_TIMESTAMP
|
||||||
/* Sends timestamp information (access, modification) to peer.
|
/* Sends timestamp information (access, modification) to peer.
|
||||||
*
|
*
|
||||||
* T<modification_secs> 0 <access_secs> 0
|
* T<modification_secs> 0 <access_secs> 0
|
||||||
|
@ -271,6 +273,10 @@ static int SendScpTimestamp(WOLFSSH* ssh)
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Sends file header (mode, file name) to peer.
|
/* Sends file header (mode, file name) to peer.
|
||||||
*
|
*
|
||||||
|
@ -282,28 +288,33 @@ static int SendScpFileHeader(WOLFSSH* ssh)
|
||||||
{
|
{
|
||||||
int ret = WS_SUCCESS, bufSz;
|
int ret = WS_SUCCESS, bufSz;
|
||||||
char buf[DEFAULT_SCP_MSG_SZ];
|
char buf[DEFAULT_SCP_MSG_SZ];
|
||||||
|
char *filehdr;
|
||||||
|
|
||||||
if (ssh == NULL)
|
if (ssh == NULL)
|
||||||
return WS_BAD_ARGUMENT;
|
return WS_BAD_ARGUMENT;
|
||||||
|
|
||||||
|
#ifndef WSCPFILEHDR
|
||||||
WMEMSET(buf, 0, sizeof(buf));
|
WMEMSET(buf, 0, sizeof(buf));
|
||||||
|
|
||||||
WSNPRINTF(buf, sizeof(buf), "C%04o %u %s\n",
|
WSNPRINTF(buf, sizeof(buf), "C%04o %u %s\n",
|
||||||
ssh->scpFileMode, ssh->scpFileSz, ssh->scpFileName);
|
ssh->scpFileMode, ssh->scpFileSz, ssh->scpFileName);
|
||||||
|
filehdr = buf;
|
||||||
bufSz = (int)WSTRLEN(buf);
|
#else
|
||||||
|
filehdr = WSCPFILEHDR(ssh);
|
||||||
ret = wolfSSH_stream_send(ssh, (byte*)buf, bufSz);
|
if (!filehdr)
|
||||||
|
return WS_BAD_ARGUMENT;
|
||||||
|
#endif
|
||||||
|
bufSz = (int)WSTRLEN(filehdr);
|
||||||
|
ret = wolfSSH_stream_send(ssh, (byte*)filehdr, bufSz);
|
||||||
if (ret != bufSz) {
|
if (ret != bufSz) {
|
||||||
ret = WS_FATAL_ERROR;
|
ret = WS_FATAL_ERROR;
|
||||||
} else {
|
} else {
|
||||||
WLOG(WS_LOG_DEBUG, "scp: sent file header: %s", buf);
|
WLOG(WS_LOG_DEBUG, "scp: sent file header: %s", filehdr);
|
||||||
ret = WS_SUCCESS;
|
ret = WS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef NO_SCP_ENTER_DIRECTORY
|
||||||
/* Sends directory message to peer, length is ignored but must
|
/* Sends directory message to peer, length is ignored but must
|
||||||
* be present in message format (set to 0).
|
* be present in message format (set to 0).
|
||||||
*
|
*
|
||||||
|
@ -336,6 +347,7 @@ static int SendScpEnterDirectory(WOLFSSH* ssh)
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Sends end directory message to peer.
|
/* Sends end directory message to peer.
|
||||||
*
|
*
|
||||||
|
@ -507,6 +519,7 @@ int DoScpSource(WOLFSSH* ssh)
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
#ifndef NO_SCP_TIMESTAMP
|
||||||
case SCP_SEND_TIMESTAMP:
|
case SCP_SEND_TIMESTAMP:
|
||||||
WLOG(WS_LOG_DEBUG, scpState, "SCP_SEND_TIMESTAMP");
|
WLOG(WS_LOG_DEBUG, scpState, "SCP_SEND_TIMESTAMP");
|
||||||
|
|
||||||
|
@ -518,7 +531,9 @@ int DoScpSource(WOLFSSH* ssh)
|
||||||
ssh->scpState = SCP_RECEIVE_CONFIRMATION;
|
ssh->scpState = SCP_RECEIVE_CONFIRMATION;
|
||||||
ssh->scpNextState = SCP_SEND_FILE_HEADER;
|
ssh->scpNextState = SCP_SEND_FILE_HEADER;
|
||||||
continue;
|
continue;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef NO_SCP_ENTER_DIRECTORY
|
||||||
case SCP_SEND_ENTER_DIRECTORY:
|
case SCP_SEND_ENTER_DIRECTORY:
|
||||||
WLOG(WS_LOG_DEBUG, scpState, "SCP_SEND_ENTER_DIRECTORY");
|
WLOG(WS_LOG_DEBUG, scpState, "SCP_SEND_ENTER_DIRECTORY");
|
||||||
|
|
||||||
|
@ -530,6 +545,7 @@ int DoScpSource(WOLFSSH* ssh)
|
||||||
ssh->scpState = SCP_RECEIVE_CONFIRMATION;
|
ssh->scpState = SCP_RECEIVE_CONFIRMATION;
|
||||||
ssh->scpNextState = SCP_TRANSFER;
|
ssh->scpNextState = SCP_TRANSFER;
|
||||||
continue;
|
continue;
|
||||||
|
#endif
|
||||||
|
|
||||||
case SCP_SEND_EXIT_DIRECTORY:
|
case SCP_SEND_EXIT_DIRECTORY:
|
||||||
WLOG(WS_LOG_DEBUG, scpState, "SCP_SEND_EXIT_DIRECTORY");
|
WLOG(WS_LOG_DEBUG, scpState, "SCP_SEND_EXIT_DIRECTORY");
|
||||||
|
@ -554,7 +570,6 @@ int DoScpSource(WOLFSSH* ssh)
|
||||||
ssh->scpState = SCP_RECEIVE_CONFIRMATION;
|
ssh->scpState = SCP_RECEIVE_CONFIRMATION;
|
||||||
ssh->scpNextState = SCP_DONE;
|
ssh->scpNextState = SCP_DONE;
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
case SCP_SEND_FILE_HEADER:
|
case SCP_SEND_FILE_HEADER:
|
||||||
WLOG(WS_LOG_DEBUG, scpState, "SCP_SEND_FILE_HEADER");
|
WLOG(WS_LOG_DEBUG, scpState, "SCP_SEND_FILE_HEADER");
|
||||||
|
|
||||||
|
@ -879,7 +894,7 @@ static int GetScpFileSize(WOLFSSH* ssh, byte* buf, word32 bufSz,
|
||||||
if (ret == WS_SUCCESS) {
|
if (ret == WS_SUCCESS) {
|
||||||
/* replace space with newline for atoi */
|
/* replace space with newline for atoi */
|
||||||
buf[spaceIdx] = '\n';
|
buf[spaceIdx] = '\n';
|
||||||
ssh->scpFileSz = atoi((char*)(buf + idx));
|
ssh->scpFileSz = strtol((char *)(buf + idx), buf + spaceIdx, 10);
|
||||||
|
|
||||||
/* restore space, increment idx to space */
|
/* restore space, increment idx to space */
|
||||||
buf[spaceIdx] = ' ';
|
buf[spaceIdx] = ' ';
|
||||||
|
@ -985,7 +1000,7 @@ static int GetScpTimestamp(WOLFSSH* ssh, byte* buf, word32 bufSz,
|
||||||
if (ret == WS_SUCCESS) {
|
if (ret == WS_SUCCESS) {
|
||||||
/* replace space with newline for atoi */
|
/* replace space with newline for atoi */
|
||||||
buf[spaceIdx] = '\n';
|
buf[spaceIdx] = '\n';
|
||||||
ssh->scpMTime = atoi((char*)(buf + idx));
|
ssh->scpMTime = strtol((char*)(buf + idx), buf + spaceIdx, 10);
|
||||||
|
|
||||||
/* restore space, increment idx past it */
|
/* restore space, increment idx past it */
|
||||||
buf[spaceIdx] = ' ';
|
buf[spaceIdx] = ' ';
|
||||||
|
@ -1017,7 +1032,7 @@ static int GetScpTimestamp(WOLFSSH* ssh, byte* buf, word32 bufSz,
|
||||||
if (ret == WS_SUCCESS) {
|
if (ret == WS_SUCCESS) {
|
||||||
/* replace space with newline for atoi */
|
/* replace space with newline for atoi */
|
||||||
buf[spaceIdx] = '\n';
|
buf[spaceIdx] = '\n';
|
||||||
ssh->scpATime = atoi((char*)(buf + idx));
|
ssh->scpATime = strtol((char*)(buf + idx), buf + spaceIdx, 10);
|
||||||
|
|
||||||
/* restore space, increment idx past it */
|
/* restore space, increment idx past it */
|
||||||
buf[spaceIdx] = ' ';
|
buf[spaceIdx] = ' ';
|
||||||
|
@ -1035,7 +1050,7 @@ static int GetScpTimestamp(WOLFSSH* ssh, byte* buf, word32 bufSz,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef NO_FILESYSTEM
|
||||||
/* checks for if directory is being renamed in command
|
/* checks for if directory is being renamed in command
|
||||||
*
|
*
|
||||||
* returns WS_SUCCESS on success
|
* returns WS_SUCCESS on success
|
||||||
|
@ -1043,7 +1058,7 @@ static int GetScpTimestamp(WOLFSSH* ssh, byte* buf, word32 bufSz,
|
||||||
static int ScpCheckForRename(WOLFSSH* ssh, int cmdSz)
|
static int ScpCheckForRename(WOLFSSH* ssh, int cmdSz)
|
||||||
{
|
{
|
||||||
/* case of file, not directory */
|
/* case of file, not directory */
|
||||||
char buf[cmdSz + 4];
|
char buf[DEFAULT_SCP_MSG_SZ];
|
||||||
int sz = (int)WSTRLEN(ssh->scpBasePath);
|
int sz = (int)WSTRLEN(ssh->scpBasePath);
|
||||||
int idx;
|
int idx;
|
||||||
|
|
||||||
|
@ -1054,6 +1069,7 @@ static int ScpCheckForRename(WOLFSSH* ssh, int cmdSz)
|
||||||
WSTRNCPY(buf, ssh->scpBasePath, cmdSz);
|
WSTRNCPY(buf, ssh->scpBasePath, cmdSz);
|
||||||
buf[sz] = '\0';
|
buf[sz] = '\0';
|
||||||
WSTRNCAT(buf, "/..", sizeof("/.."));
|
WSTRNCAT(buf, "/..", sizeof("/.."));
|
||||||
|
|
||||||
idx = wolfSSH_CleanPath(ssh, buf);
|
idx = wolfSSH_CleanPath(ssh, buf);
|
||||||
if (idx < 0) {
|
if (idx < 0) {
|
||||||
return WS_FATAL_ERROR;
|
return WS_FATAL_ERROR;
|
||||||
|
@ -1110,16 +1126,15 @@ static int ScpCheckForRename(WOLFSSH* ssh, int cmdSz)
|
||||||
return WS_SUCCESS;
|
return WS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
/* helps with checking if the base path is a directory or file
|
/* helps with checking if the base path is a directory or file
|
||||||
* returns WS_SUCCESS on success */
|
* returns WS_SUCCESS on success */
|
||||||
static int ParseBasePathHelper(WOLFSSH* ssh, int cmdSz)
|
static int ParseBasePathHelper(WOLFSSH* ssh, int cmdSz)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret = 0;
|
||||||
|
|
||||||
ret = ScpCheckForRename(ssh, cmdSz);
|
|
||||||
|
|
||||||
#ifndef NO_FILESYSTEM
|
#ifndef NO_FILESYSTEM
|
||||||
|
ret = ScpCheckForRename(ssh, cmdSz);
|
||||||
{
|
{
|
||||||
ScpSendCtx ctx;
|
ScpSendCtx ctx;
|
||||||
|
|
||||||
|
@ -1569,7 +1584,7 @@ int wolfSSH_SCP_connect(WOLFSSH* ssh, byte* cmd)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef NO_WOLFSSH_CLIENT
|
||||||
static int wolfSSH_SCP_cmd(WOLFSSH* ssh, const char* localName,
|
static int wolfSSH_SCP_cmd(WOLFSSH* ssh, const char* localName,
|
||||||
const char* remoteName, byte dir)
|
const char* remoteName, byte dir)
|
||||||
{
|
{
|
||||||
|
@ -1635,6 +1650,7 @@ int wolfSSH_SCP_from(WOLFSSH* ssh, const char* src, const char* dst)
|
||||||
/* src is passed to the server in the scp -f command */
|
/* src is passed to the server in the scp -f command */
|
||||||
/* dst is used locally to fopen and write for copy from */
|
/* dst is used locally to fopen and write for copy from */
|
||||||
}
|
}
|
||||||
|
#endif /* ! NO_WOLFSSH_CLIENT */
|
||||||
|
|
||||||
|
|
||||||
#if !defined(WOLFSSH_SCP_USER_CALLBACKS)
|
#if !defined(WOLFSSH_SCP_USER_CALLBACKS)
|
||||||
|
|
Loading…
Reference in New Issue