From caedd5339ca2689583c41e2de568d341ed06e7c7 Mon Sep 17 00:00:00 2001 From: John Safranek Date: Thu, 4 Nov 2021 14:45:34 -0700 Subject: [PATCH] When scp receives a string in STDERR, print it out. --- src/wolfscp.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/wolfscp.c b/src/wolfscp.c index 732acd2d..b531b2a9 100644 --- a/src/wolfscp.c +++ b/src/wolfscp.c @@ -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); @@ -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; @@ -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; @@ -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;