Skip to content

Commit

Permalink
Channel Callbacks (Request Rejection)
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 Jun 21, 2024
1 parent 57f1451 commit 015ae84
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 @@ -8276,7 +8276,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 @@ -8324,7 +8324,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 @@ -8333,7 +8333,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 @@ -8344,7 +8344,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 @@ -8480,7 +8480,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 015ae84

Please sign in to comment.