Skip to content

Commit

Permalink
Changing Channels
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ejohnstown committed Apr 9, 2024
1 parent d8009e4 commit bd3faf3
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()");

Expand Down Expand Up @@ -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;
}
Expand All @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit bd3faf3

Please sign in to comment.