Skip to content

Commit 87eb3ad

Browse files
authored
Merge pull request #24 from ejohnstown/chan-success
Channel Success Message
2 parents ad80b4b + c2480eb commit 87eb3ad

2 files changed

Lines changed: 98 additions & 48 deletions

File tree

src/internal.c

Lines changed: 94 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2362,8 +2362,6 @@ static int DoChannelRequest(WOLFSSH* ssh,
23622362

23632363
WLOG(WS_LOG_DEBUG, "Entering DoChannelRequest()");
23642364

2365-
(void)ssh;
2366-
23672365
ret = GetUint32(&channelId, buf, len, &begin);
23682366

23692367
if (ret == WS_SUCCESS)
@@ -2377,62 +2375,65 @@ static int DoChannelRequest(WOLFSSH* ssh,
23772375
return ret;
23782376
}
23792377

2380-
WLOG(WS_LOG_DEBUG, " channelId = %u", channelId);
2381-
WLOG(WS_LOG_DEBUG, " type = %s", type);
2382-
WLOG(WS_LOG_DEBUG, " wantReply = %u", wantReply);
2378+
if (ret == WS_SUCCESS) {
2379+
WLOG(WS_LOG_DEBUG, " channelId = %u", channelId);
2380+
WLOG(WS_LOG_DEBUG, " type = %s", type);
2381+
WLOG(WS_LOG_DEBUG, " wantReply = %u", wantReply);
23832382

2384-
if (WSTRNCMP(type, "pty-req", typeSz) == 0) {
2385-
char term[32];
2386-
uint32_t termSz;
2387-
uint32_t widthChar, heightRows, widthPixels, heightPixels;
2388-
uint32_t modesSz;
2383+
if (WSTRNCMP(type, "pty-req", typeSz) == 0) {
2384+
char term[32];
2385+
uint32_t termSz;
2386+
uint32_t widthChar, heightRows, widthPixels, heightPixels;
2387+
uint32_t modesSz;
23892388

2390-
ret = GetString(term, &termSz, buf, len, &begin);
2391-
if (ret == WS_SUCCESS)
2392-
ret = GetUint32(&widthChar, buf, len, &begin);
2393-
if (ret == WS_SUCCESS)
2394-
ret = GetUint32(&heightRows, buf, len, &begin);
2395-
if (ret == WS_SUCCESS)
2396-
ret = GetUint32(&widthPixels, buf, len, &begin);
2397-
if (ret == WS_SUCCESS)
2398-
ret = GetUint32(&heightPixels, buf, len, &begin);
2399-
if (ret == WS_SUCCESS)
2400-
ret = GetUint32(&modesSz, buf, len, &begin);
2389+
ret = GetString(term, &termSz, buf, len, &begin);
2390+
if (ret == WS_SUCCESS)
2391+
ret = GetUint32(&widthChar, buf, len, &begin);
2392+
if (ret == WS_SUCCESS)
2393+
ret = GetUint32(&heightRows, buf, len, &begin);
2394+
if (ret == WS_SUCCESS)
2395+
ret = GetUint32(&widthPixels, buf, len, &begin);
2396+
if (ret == WS_SUCCESS)
2397+
ret = GetUint32(&heightPixels, buf, len, &begin);
2398+
if (ret == WS_SUCCESS)
2399+
ret = GetUint32(&modesSz, buf, len, &begin);
24012400

2402-
if (ret != WS_SUCCESS) {
2403-
WLOG(WS_LOG_DEBUG, "Leaving DoChannelRequest(), ret = %d", ret);
2404-
return ret;
2401+
if (ret == WS_SUCCESS) {
2402+
WLOG(WS_LOG_DEBUG, " term = %s", term);
2403+
WLOG(WS_LOG_DEBUG, " widthChar = %u", widthChar);
2404+
WLOG(WS_LOG_DEBUG, " heightRows = %u", heightRows);
2405+
WLOG(WS_LOG_DEBUG, " widthPixels = %u", widthPixels);
2406+
WLOG(WS_LOG_DEBUG, " heightPixels = %u", heightPixels);
2407+
WLOG(WS_LOG_DEBUG, " modes = %u", (modesSz - 1) / 5);
2408+
}
24052409
}
2410+
else if (WSTRNCMP(type, "env", typeSz) == 0) {
2411+
char name[32];
2412+
uint32_t nameSz;
2413+
char value[32];
2414+
uint32_t valueSz;
2415+
2416+
ret = GetString(name, &nameSz, buf, len, &begin);
2417+
if (ret == WS_SUCCESS)
2418+
ret = GetString(value, &valueSz, buf, len, &begin);
24062419

2407-
WLOG(WS_LOG_DEBUG, " term = %s", term);
2408-
WLOG(WS_LOG_DEBUG, " widthChar = %u", widthChar);
2409-
WLOG(WS_LOG_DEBUG, " heightRows = %u", heightRows);
2410-
WLOG(WS_LOG_DEBUG, " widthPixels = %u", widthPixels);
2411-
WLOG(WS_LOG_DEBUG, " heightPixels = %u", heightPixels);
2412-
WLOG(WS_LOG_DEBUG, " modes = %u", (modesSz - 1) / 5);
2420+
WLOG(WS_LOG_DEBUG, " %s = %s", name, value);
2421+
}
24132422
}
2414-
else if (WSTRNCMP(type, "env", typeSz) == 0) {
2415-
char name[32];
2416-
uint32_t nameSz;
2417-
char value[32];
2418-
uint32_t valueSz;
24192423

2420-
ret = GetString(name, &nameSz, buf, len, &begin);
2421-
if (ret == WS_SUCCESS)
2422-
ret = GetString(value, &valueSz, buf, len, &begin);
2424+
if (ret == WS_SUCCESS)
2425+
*idx = len;
24232426

2424-
if (ret != WS_SUCCESS) {
2425-
WLOG(WS_LOG_DEBUG, "Leaving DoChannelRequest(), ret = %d", ret);
2426-
return ret;
2427-
}
2427+
if (wantReply) {
2428+
int replyRet;
24282429

2429-
WLOG(WS_LOG_DEBUG, " %s = %s", name, value);
2430+
replyRet = SendChannelSuccess(ssh, channelId, (ret == WS_SUCCESS));
2431+
if (replyRet != WS_SUCCESS)
2432+
ret = replyRet;
24302433
}
24312434

2432-
*idx = len;
2433-
2434-
WLOG(WS_LOG_DEBUG, "Leaving DoChannelRequest()");
2435-
return WS_SUCCESS;
2435+
WLOG(WS_LOG_DEBUG, "Leaving DoChannelRequest(), ret = %d", ret);
2436+
return ret;
24362437
}
24372438

24382439

@@ -4257,6 +4258,52 @@ int SendChannelWindowAdjust(WOLFSSH* ssh, uint32_t peerChannel,
42574258
}
42584259

42594260

4261+
int SendChannelSuccess(WOLFSSH* ssh, uint32_t channelId, int success)
4262+
{
4263+
uint8_t* output;
4264+
uint32_t idx;
4265+
int ret = WS_SUCCESS;
4266+
WOLFSSH_CHANNEL* channel;
4267+
4268+
WLOG(WS_LOG_DEBUG, "Entering SendChannelSuccess(), %s",
4269+
success ? "Success" : "Failure");
4270+
4271+
if (ssh == NULL)
4272+
ret = WS_BAD_ARGUMENT;
4273+
4274+
if (ret == WS_SUCCESS) {
4275+
channel = ChannelFind(ssh, channelId, FIND_SELF);
4276+
if (channel == NULL) {
4277+
WLOG(WS_LOG_DEBUG, "Invalid channel");
4278+
ret = WS_INVALID_CHANID;
4279+
}
4280+
}
4281+
4282+
if (ret == WS_SUCCESS)
4283+
ret = PreparePacket(ssh, MSG_ID_SZ + UINT32_SZ);
4284+
4285+
if (ret == WS_SUCCESS) {
4286+
output = ssh->outputBuffer.buffer;
4287+
idx = ssh->outputBuffer.length;
4288+
4289+
output[idx++] = success ?
4290+
MSGID_CHANNEL_SUCCESS : MSGID_CHANNEL_FAILURE;
4291+
c32toa(channel->peerChannel, output + idx);
4292+
idx += UINT32_SZ;
4293+
4294+
ssh->outputBuffer.length = idx;
4295+
4296+
ret = BundlePacket(ssh);
4297+
}
4298+
4299+
if (ret == WS_SUCCESS)
4300+
ret = SendBuffered(ssh);
4301+
4302+
WLOG(WS_LOG_DEBUG, "Leaving SendChannelSuccess(), ret = %d", ret);
4303+
return ret;
4304+
}
4305+
4306+
42604307
#ifdef DEBUG_WOLFSSH
42614308

42624309
#define LINE_WIDTH 16

wolfssh/internal.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ WOLFSSH_LOCAL int SendChannelEof(WOLFSSH*, uint32_t);
318318
WOLFSSH_LOCAL int SendChannelClose(WOLFSSH*, uint32_t);
319319
WOLFSSH_LOCAL int SendChannelData(WOLFSSH*, uint32_t, uint8_t*, uint32_t);
320320
WOLFSSH_LOCAL int SendChannelWindowAdjust(WOLFSSH*, uint32_t, uint32_t);
321+
WOLFSSH_LOCAL int SendChannelSuccess(WOLFSSH*, uint32_t, int);
321322
WOLFSSH_LOCAL int GenerateKey(uint8_t, uint8_t, uint8_t*, uint32_t,
322323
const uint8_t*, uint32_t,
323324
const uint8_t*, uint32_t,
@@ -401,7 +402,9 @@ enum WS_MessageIds {
401402
MSGID_CHANNEL_DATA = 94,
402403
MSGID_CHANNEL_EOF = 96,
403404
MSGID_CHANNEL_CLOSE = 97,
404-
MSGID_CHANNEL_REQUEST = 98
405+
MSGID_CHANNEL_REQUEST = 98,
406+
MSGID_CHANNEL_SUCCESS = 99,
407+
MSGID_CHANNEL_FAILURE = 100
405408
};
406409

407410

0 commit comments

Comments
 (0)