Skip to content

Commit

Permalink
Merge pull request #375 from ejohnstown/stderr
Browse files Browse the repository at this point in the history
wolfSCP and STDERR
  • Loading branch information
JacobBarthelmeh committed Nov 4, 2021
2 parents bb6e6e2 + caedd53 commit ed97707
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/wolfscp.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
#include "src/misc.c"
#endif

#ifndef WOLFSSH_DEFAULT_EXTDATA_SZ
#define WOLFSSH_DEFAULT_EXTDATA_SZ 128
#endif

#ifndef NO_FILESYSTEM
static int ScpFileIsDir(ScpSendCtx* ctx);
static int ScpPushDir(ScpSendCtx* ctx, const char* path, void* heap);
Expand All @@ -56,6 +60,23 @@ static int ScpPopDir(ScpSendCtx* ctx, void* heap);
const char scpError[] = "scp error: %s, %d";
const char scpState[] = "scp state: %s";


static int _DumpExtendedData(WOLFSSH* ssh)
{
byte msg[WOLFSSH_DEFAULT_EXTDATA_SZ];
int msgSz;

msgSz = wolfSSH_extended_data_read(ssh, msg, WOLFSSH_DEFAULT_EXTDATA_SZ-1);
if (msgSz > 0) {
msg[WOLFSSH_DEFAULT_EXTDATA_SZ - 1] = 0;
fprintf(stderr, "%s", msg);
msgSz = WS_SUCCESS;
}

return msgSz;
}


int DoScpSink(WOLFSSH* ssh)
{
int ret = WS_SUCCESS;
Expand Down Expand Up @@ -584,6 +605,10 @@ int DoScpSource(WOLFSSH* ssh)
if (ret == WS_SUCCESS)
continue;
}
if (ret == WS_EXTDATA) {
_DumpExtendedData(ssh);
continue;
}
if (ret < 0) {
WLOG(WS_LOG_ERROR, scpError, "failed to send file", ret);
break;
Expand Down Expand Up @@ -1470,7 +1495,10 @@ int ReceiveScpConfirmation(WOLFSSH* ssh)
msgSz = wolfSSH_stream_read(ssh, msg, DEFAULT_SCP_MSG_SZ);

if (msgSz < 0) {
ret = msgSz;
if (wolfSSH_get_error(ssh) == WS_EXTDATA)
_DumpExtendedData(ssh);
else
ret = msgSz;
} else if (msgSz > 1) {
/* null terminate */
msg[msgSz] = 0x00;
Expand Down

0 comments on commit ed97707

Please sign in to comment.