From 43f4d439ec52616ccf6380374e21bce0b7087694 Mon Sep 17 00:00:00 2001 From: speidy Date: Tue, 4 Mar 2014 10:19:19 +0200 Subject: [PATCH] libxrdp: work on fastpath, length issue --- libxrdp/libxrdp.c | 1 + libxrdp/xrdp_fastpath.c | 35 +++++++++++++++++++---------------- libxrdp/xrdp_iso.c | 2 +- libxrdp/xrdp_mcs.c | 12 +----------- libxrdp/xrdp_rdp.c | 22 ++++++++++++++++------ libxrdp/xrdp_sec.c | 13 +------------ xrdp/xrdp_process.c | 1 + 7 files changed, 40 insertions(+), 46 deletions(-) diff --git a/libxrdp/libxrdp.c b/libxrdp/libxrdp.c index ae2690f2..dc7a9869 100644 --- a/libxrdp/libxrdp.c +++ b/libxrdp/libxrdp.c @@ -29,6 +29,7 @@ libxrdp_init(tbus id, struct trans *trans) session = (struct xrdp_session *)g_malloc(sizeof(struct xrdp_session), 1); session->id = id; + session->trans = trans; session->rdp = xrdp_rdp_create(session, trans); session->orders = xrdp_orders_create(session, (struct xrdp_rdp *)session->rdp); session->client_info = &(((struct xrdp_rdp *)session->rdp)->client_info); diff --git a/libxrdp/xrdp_fastpath.c b/libxrdp/xrdp_fastpath.c index bc6f49d2..e7308ba0 100644 --- a/libxrdp/xrdp_fastpath.c +++ b/libxrdp/xrdp_fastpath.c @@ -58,22 +58,23 @@ xrdp_fastpath_recv(struct xrdp_fastpath *self, struct stream *s) int fp_hdr; int len = 0; int byte; - int hdr_len = 2; /* fastpath header lenght - can be 2 or 3 bytes long, depends on length */ + int hdr_len = 2; /* fastpath header length - can be 2 or 3 bytes long, depends on length */ DEBUG((" in xrdp_fastpath_recv")); /* read the first fastpath byte * (we already received it via iso layer */ + // receive fastpath first length packet + init_stream(s, hdr_len); + if (trans_force_read_s(self->trans, s, hdr_len) != 0) + { + return 1; + } in_uint8(s, fp_hdr); /* fpInputHeader (1 byte) */ self->numEvents = (fp_hdr & 0x3C) >> 2; self->secFlags = (fp_hdr & 0xC0) >> 6; // receive fastpath first length packet - if (trans_force_read_s(self->trans, s, 1) != 0) - { - return 1; - } - in_uint8(s, byte); /* length 1 */ if (byte & 0x80) @@ -81,7 +82,8 @@ xrdp_fastpath_recv(struct xrdp_fastpath *self, struct stream *s) byte &= ~(0x80); len = (byte << 8); // receive fastpath second length packet - if (xrdp_tcp_recv(self->tcp_layer, s, 1) != 0) + init_stream(s, 1); + if (trans_force_read_s(self->trans, s, 1) != 0) { return 1; } @@ -94,10 +96,11 @@ xrdp_fastpath_recv(struct xrdp_fastpath *self, struct stream *s) len = byte; } - //g_writeln("len= %d , numEvents= %d, secFlags= %d, bytesleft: %d", len, self->numEvents, self->secFlags, (s->p - s->data)); + g_writeln("len= %d , numEvents= %d, secFlags= %d, bytesleft: %d", len, self->numEvents, self->secFlags, (s->p - s->data)); // receive the left bytes - if (xrdp_tcp_recv(self->tcp_layer, s, len - hdr_len) != 0) + init_stream(s, len - hdr_len); + if (trans_force_read_s(self->trans, s, len - hdr_len) != 0) { return 1; } @@ -166,10 +169,10 @@ xrdp_fastpath_send_update_pdu(struct xrdp_fastpath *self, tui8 updateCode, // s_copy(s_send, s, len); s_mark_end(s_send); - if (xrdp_tcp_send(self->tcp_layer, s_send) != 0) - { - return 1; - } +// if (xrdp_tcp_send(self->tcp_layer, s_send) != 0) +// { +// return 1; +// } } return 0; @@ -220,12 +223,12 @@ xrdp_fastpath_process_data(struct xrdp_fastpath *self, struct stream *s, encryptionFlags = (header & 0xc0) >> 6; numberEvents = (header & 0x3c) >> 2; - xrdp_tcp_recv(self->tcp_layer, s, 1); +// xrdp_tcp_recv(self->tcp_layer, s, 1); in_uint8(s, length); if (length & 0x80) { - xrdp_tcp_recv(self->tcp_layer, s, 1); +// xrdp_tcp_recv(self->tcp_layer, s, 1); in_uint8(s, length2); length = (length & 0x7f) << 8 + length2 - 3; } @@ -234,7 +237,7 @@ xrdp_fastpath_process_data(struct xrdp_fastpath *self, struct stream *s, length -= 2; } - xrdp_tcp_recv(self->tcp_layer, s, length); +// xrdp_tcp_recv(self->tcp_layer, s, length); if (encryptionFlags != 0) { diff --git a/libxrdp/xrdp_iso.c b/libxrdp/xrdp_iso.c index df00f52b..31c279b5 100644 --- a/libxrdp/xrdp_iso.c +++ b/libxrdp/xrdp_iso.c @@ -111,7 +111,7 @@ xrdp_iso_recv_msg(struct xrdp_iso *self, struct stream *s, int *code, int *len) if (ver != 3) { - return 2; // special code for fastpath + return 1; } in_uint8s(s, 1); diff --git a/libxrdp/xrdp_mcs.c b/libxrdp/xrdp_mcs.c index 526587d5..08055191 100644 --- a/libxrdp/xrdp_mcs.c +++ b/libxrdp/xrdp_mcs.c @@ -122,21 +122,11 @@ xrdp_mcs_recv(struct xrdp_mcs *self, struct stream *s, int *chan) int len; int userid; int chanid; - int iso_msg; DEBUG((" in xrdp_mcs_recv")); while (1) { - - iso_msg = xrdp_iso_recv(self->iso_layer, s); - - if (iso_msg == 2) // non-TPKT header - { - DEBUG((" out xrdp_mcs_recv, non-TPKT header detected, we try fastpath")); - return iso_msg; - } - - if (iso_msg == 1) // error + if (xrdp_iso_recv(self->iso_layer, s) != 0) { DEBUG((" out xrdp_mcs_recv, xrdp_iso_recv return non zero")); return 1; diff --git a/libxrdp/xrdp_rdp.c b/libxrdp/xrdp_rdp.c index 85ca15d7..ea2204f5 100644 --- a/libxrdp/xrdp_rdp.c +++ b/libxrdp/xrdp_rdp.c @@ -299,20 +299,30 @@ xrdp_rdp_recv(struct xrdp_rdp *self, struct stream *s, int *code) int len = 0; int pdu_code = 0; int chan = 0; + const tui8 *header; + header = (const tui8 *) (self->session->trans->in_s->p); DEBUG(("in xrdp_rdp_recv")); + /* not fastpath, do tpkt */ if (s->next_packet == 0 || s->next_packet >= s->end) { - chan = 0; - error = xrdp_sec_recv(self->sec_layer, s, &chan); + /* check for fastpath first */ + g_writeln("xrdp_rdp_recv: header= 0x%8.8x", header[0]); - if (error == 2) /* we have fastpath packet! */ + if ((header[0] & 0x3) == 0 && (header[0] != 0x3c)) { - *code = 2; + if (xrdp_sec_recv_fastpath(self->sec_layer, s) != 0) + { + return 1; + } + *code = 2; // special code for fastpath return 0; } + chan = 0; + error = xrdp_sec_recv(self->sec_layer, s, &chan); + if (error == -1) /* special code for send demand active */ { s->next_packet = 0; @@ -1691,8 +1701,8 @@ xrdp_rdp_process_fastpath_data_input(struct xrdp_rdp *self, struct stream *s) eventFlags = (eventHeader & 0x1F); eventCode = (eventHeader >> 5); - //g_writeln("eventCode= %d, eventFlags= %d, numEvents= %d", - // eventCode, eventFlags, self->sec_layer->fastpath_layer->numEvents); +// g_writeln("eventCode= %d, eventFlags= %d, numEvents= %d", +// eventCode, eventFlags, self->sec_layer->fastpath_layer->numEvents); switch (eventCode) { diff --git a/libxrdp/xrdp_sec.c b/libxrdp/xrdp_sec.c index ec9b5711..6b8dbbc4 100644 --- a/libxrdp/xrdp_sec.c +++ b/libxrdp/xrdp_sec.c @@ -972,23 +972,12 @@ xrdp_sec_recv(struct xrdp_sec *self, struct stream *s, int *chan) { int flags; int len; - int mcs_msg; int ver; int pad; - DEBUG((" in xrdp_sec_recv")); - mcs_msg = xrdp_mcs_recv(self->mcs_layer, s, chan); - - if (mcs_msg == 2) - { - xrdp_sec_recv_fastpath(self, s); - DEBUG((" out xrdp_sec_recv : non-TPKT msg detected, we try fastpath")); - return mcs_msg; - } - - if (mcs_msg == 1) + if (xrdp_mcs_recv(self->mcs_layer, s, chan) != 0) { DEBUG((" out xrdp_sec_recv : error")); return 1; diff --git a/xrdp/xrdp_process.c b/xrdp/xrdp_process.c index 78576f1f..fe6e2c4b 100644 --- a/xrdp/xrdp_process.c +++ b/xrdp/xrdp_process.c @@ -123,6 +123,7 @@ xrdp_process_get_pdu_bytes(const char *aheader) rv = -1; header = (const tui8 *) aheader; + if (header[0] == 0x03) { /* TPKT */