1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
/*
20140210
Jan Mojzis
Public domain.
*/
#include "bug.h"
#include "buf.h"
#include "channel.h"
#include "ssh.h"
#include "packetparser.h"
#include "packet.h"
int packet_channel_recv_data(struct buf *b) {
long long pos = 0;
crypto_uint32 len, id;
crypto_uint8 ch;
pos = packetparser_uint8(b->buf, b->len, pos,
&ch); /* byte SSH_MSG_CHANNEL_DATA */
if (ch != SSH_MSG_CHANNEL_DATA) bug_proto();
pos = packetparser_uint32(b->buf, b->len, pos,
&id); /* uint32 recipient channel */
if (id != channel_getid()) bug_proto();
pos = packetparser_uint32(b->buf, b->len, pos, &len); /* string data */
pos = packetparser_skip(b->buf, b->len, pos, len);
pos = packetparser_end(b->buf, b->len, pos);
channel_put(b->buf + pos - len, len);
buf_purge(b);
return 1;
}
int packet_channel_recv_extendeddata(struct buf *b) {
/* ignore extended data */
buf_purge(b);
return 1;
}
int packet_channel_recv_windowadjust(struct buf *b) {
long long pos = 0;
crypto_uint32 len, id;
crypto_uint8 ch;
pos = packetparser_uint8(b->buf, b->len, pos,
&ch); /* byte SSH_MSG_CHANNEL_WINDOW_ADJUST */
if (ch != SSH_MSG_CHANNEL_WINDOW_ADJUST) bug_proto();
pos = packetparser_uint32(b->buf, b->len, pos,
&id); /* uint32 recipient channel */
if (id != channel_getid()) bug_proto();
pos = packetparser_uint32(b->buf, b->len, pos,
&len); /* uint32 bytes to add */
pos = packetparser_end(b->buf, b->len, pos);
channel_incrementremotewindow(len);
buf_purge(b);
return 1;
}
int packet_channel_recv_eof(struct buf *b) {
long long pos = 0;
crypto_uint32 id;
crypto_uint8 ch;
pos = packetparser_uint8(b->buf, b->len, pos,
&ch); /* byte SSH_MSG_CHANNEL_EOF */
if (ch != SSH_MSG_CHANNEL_EOF) bug_proto();
pos = packetparser_uint32(b->buf, b->len, pos,
&id); /* uint32 recipient channel */
if (id != channel_getid()) bug_proto();
pos = packetparser_end(b->buf, b->len, pos);
log_d1("packet=SSH_MSG_CHANNEL_EOF received");
channel_puteof();
buf_purge(b);
return 1;
}
int packet_channel_recv_close(struct buf *b) {
long long pos = 0;
crypto_uint32 id;
crypto_uint8 ch;
pos = packetparser_uint8(b->buf, b->len, pos,
&ch); /* byte SSH_MSG_CHANNEL_CLOSE */
if (ch != SSH_MSG_CHANNEL_CLOSE) bug_proto();
pos = packetparser_uint32(b->buf, b->len, pos,
&id); /* uint32 recipient channel */
if (id != channel_getid()) bug_proto();
pos = packetparser_end(b->buf, b->len, pos);
log_d1("packet=SSH_MSG_CHANNEL_CLOSE received");
packet_channel_send_eof(b);
packet.flagchanneleofreceived = 1;
buf_purge(b);
return 1;
}
|