Skip to content

Commit ba6bc66

Browse files
ejohnstownphilljj
authored andcommitted
portfwd: report the channel open response
wolfSSH_CTX_SetChannelOpenRespCb() had no caller anywhere in the tree, so the confirm and fail hooks had no worked example and a forwarding client had nothing to say which of its opens the peer refused. - register both arms and print the channel each one names - name our own id, not the peer's: a refused open never learns the peer's, and it is the id portfwd_worker() already tracks
1 parent 61fa771 commit ba6bc66

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

examples/portfwd/portfwd.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,43 @@ static int portfwdReqFailureCb(WOLFSSH* ssh, void* buf, word32 sz, void* ctx)
394394
}
395395

396396

397+
/* Reports one open response. The id is our own: a failed open never learns
398+
* the peer's, and it is the id portfwd_worker() tracks. */
399+
static int wsChannelOpenRespCb(WOLFSSH_CHANNEL* channel, void* ctx,
400+
const char* result)
401+
{
402+
word32 id = 0;
403+
const char* str;
404+
405+
if (ctx != NULL) {
406+
str = (const char*)ctx;
407+
}
408+
else {
409+
str = "<BAD CONTEXT>";
410+
}
411+
if (wolfSSH_ChannelGetId(channel, &id, WS_CHANNEL_ID_SELF)
412+
!= WS_SUCCESS) {
413+
printf("Channel for %s, unknown id open %s.\n", str, result);
414+
}
415+
else {
416+
printf("Channel for %s, %u open %s.\n", str, id, result);
417+
}
418+
return WS_SUCCESS;
419+
}
420+
421+
422+
static int wsChannelOpenConfCb(WOLFSSH_CHANNEL* channel, void* ctx)
423+
{
424+
return wsChannelOpenRespCb(channel, ctx, "confirmed");
425+
}
426+
427+
428+
static int wsChannelOpenFailCb(WOLFSSH_CHANNEL* channel, void* ctx)
429+
{
430+
return wsChannelOpenRespCb(channel, ctx, "failed");
431+
}
432+
433+
397434
/*
398435
* fwdFromHost - address to bind the local listener socket to (default: any)
399436
* fwdFromHostPort - port number to bind the local listener socket to
@@ -583,6 +620,9 @@ THREAD_RETURN WOLFSSH_THREAD portfwd_worker(void* args)
583620

584621
wolfSSH_CTX_SetPublicKeyCheck(ctx, wsPublicKeyCheck);
585622
wolfSSH_SetPublicKeyCheckCtx(ssh, (void*)"You've been sampled.");
623+
wolfSSH_CTX_SetChannelOpenRespCb(ctx,
624+
wsChannelOpenConfCb, wsChannelOpenFailCb);
625+
wolfSSH_SetChannelOpenCtx(ssh, (void*)"port forward");
586626

587627
ret = wolfSSH_SetUsername(ssh, username);
588628
if (ret != WS_SUCCESS)

0 commit comments

Comments
 (0)