From bd3faf3258b8c2e3e9fa0d229ec02d8acbf2766b Mon Sep 17 00:00:00 2001 From: John Safranek Date: Fri, 5 Apr 2024 12:01:49 -0700 Subject: [PATCH] Changing Channels 1. Treat any non-zero response from any of the channel request callback functions as a rejection of the channel request. 2. If a channel request reply is wanted, return the failure message if the callback function had rejected the request. --- src/internal.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/internal.c b/src/internal.c index d94037072..683f5097e 100644 --- a/src/internal.c +++ b/src/internal.c @@ -7767,7 +7767,7 @@ static int DoChannelRequest(WOLFSSH* ssh, word32 typeSz; char type[32]; byte wantReply; - int ret; + int ret, rej = 0; WLOG(WS_LOG_DEBUG, "Entering DoChannelRequest()"); @@ -7815,7 +7815,7 @@ static int DoChannelRequest(WOLFSSH* ssh, else if (WSTRNCMP(type, "shell", typeSz) == 0) { channel->sessionType = WOLFSSH_SESSION_SHELL; if (ssh->ctx->channelReqShellCb) { - ssh->ctx->channelReqShellCb(channel, ssh->channelReqCtx); + rej = ssh->ctx->channelReqShellCb(channel, ssh->channelReqCtx); } ssh->clientState = CLIENT_DONE; } @@ -7824,7 +7824,7 @@ static int DoChannelRequest(WOLFSSH* ssh, buf, len, &begin); channel->sessionType = WOLFSSH_SESSION_EXEC; if (ssh->ctx->channelReqExecCb) { - ssh->ctx->channelReqExecCb(channel, ssh->channelReqCtx); + rej = ssh->ctx->channelReqExecCb(channel, ssh->channelReqCtx); } ssh->clientState = CLIENT_DONE; @@ -7835,7 +7835,7 @@ static int DoChannelRequest(WOLFSSH* ssh, buf, len, &begin); channel->sessionType = WOLFSSH_SESSION_SUBSYSTEM; if (ssh->ctx->channelReqSubsysCb) { - ssh->ctx->channelReqSubsysCb(channel, ssh->channelReqCtx); + rej = ssh->ctx->channelReqSubsysCb(channel, ssh->channelReqCtx); } ssh->clientState = CLIENT_DONE; @@ -7971,7 +7971,11 @@ static int DoChannelRequest(WOLFSSH* ssh, if (wantReply) { int replyRet; - replyRet = SendChannelSuccess(ssh, channelId, (ret == WS_SUCCESS)); + if (rej) { + WLOG(WS_LOG_DEBUG, "Callback rejecting channel request."); + } + replyRet = SendChannelSuccess(ssh, channelId, + (ret == WS_SUCCESS && !rej)); if (replyRet != WS_SUCCESS) ret = replyRet; }