From 2dc5f491323a23c6ce758e9cb82ca4eb5ff21478 Mon Sep 17 00:00:00 2001 From: speidy Date: Sun, 17 Nov 2013 16:23:11 +0200 Subject: [PATCH 1/5] libxrdp: add Montior Layout PDU (server to client), temporary hack --- libxrdp/xrdp_rdp.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/libxrdp/xrdp_rdp.c b/libxrdp/xrdp_rdp.c index 5f358fca..f07cf251 100644 --- a/libxrdp/xrdp_rdp.c +++ b/libxrdp/xrdp_rdp.c @@ -52,6 +52,16 @@ static tui8 g_unknown1[172] = 0x2b, 0x00, 0x2a, 0x00 }; +static tui8 g_monitorlayout[44] = +{ + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x7F, 0x07, 0x00, 0x00, + 0x37, 0x04, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x80, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0x0E, 0x00, 0x00, 0x37, 0x04, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 +}; + /* some compilers need unsigned char to avoid warnings */ /* static tui8 g_unknown2[8] = @@ -1600,7 +1610,33 @@ xrdp_rdp_send_unknown1(struct xrdp_rdp *self) free_stream(s); return 0; } +/*****************************************************************************/ +static int APP_CC +xrdp_rdp_send_monitorlayout(struct xrdp_rdp *self) +{ + struct stream *s; + make_stream(s); + init_stream(s, 8192); + + if (xrdp_rdp_init_data(self, s) != 0) + { + free_stream(s); + return 1; + } + + out_uint8a(s, g_monitorlayout, 44); + s_mark_end(s); + + if (xrdp_rdp_send_data(self, s, 0x37) != 0) + { + free_stream(s); + return 1; + } + + free_stream(s); + return 0; +} /*****************************************************************************/ static int APP_CC xrdp_rdp_process_data_font(struct xrdp_rdp *self, struct stream *s) @@ -1619,6 +1655,12 @@ xrdp_rdp_process_data_font(struct xrdp_rdp *self, struct stream *s) /* running */ DEBUG(("sending unknown1")); xrdp_rdp_send_unknown1(self); + if (self->client_info.monitorCount > 0) { + if (xrdp_rdp_send_monitorlayout(self) != 0) + { + g_writeln("Problem with monitor layout packet!!!"); + } + } self->session->up_and_running = 1; DEBUG(("up_and_running set")); xrdp_rdp_send_data_update_sync(self); From bc4fd1afbab95e1d1f92700e642163067722d737 Mon Sep 17 00:00:00 2001 From: speidy Date: Sun, 17 Nov 2013 16:56:27 +0200 Subject: [PATCH 2/5] libxrdp: Monitor Layout PDU changes --- libxrdp/xrdp_rdp.c | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/libxrdp/xrdp_rdp.c b/libxrdp/xrdp_rdp.c index f07cf251..54ae75e0 100644 --- a/libxrdp/xrdp_rdp.c +++ b/libxrdp/xrdp_rdp.c @@ -52,16 +52,6 @@ static tui8 g_unknown1[172] = 0x2b, 0x00, 0x2a, 0x00 }; -static tui8 g_monitorlayout[44] = -{ - 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x7F, 0x07, 0x00, 0x00, - 0x37, 0x04, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x80, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xFF, 0x0E, 0x00, 0x00, 0x37, 0x04, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00 -}; - /* some compilers need unsigned char to avoid warnings */ /* static tui8 g_unknown2[8] = @@ -1615,6 +1605,7 @@ static int APP_CC xrdp_rdp_send_monitorlayout(struct xrdp_rdp *self) { struct stream *s; + int i; make_stream(s); init_stream(s, 8192); @@ -1625,7 +1616,18 @@ xrdp_rdp_send_monitorlayout(struct xrdp_rdp *self) return 1; } - out_uint8a(s, g_monitorlayout, 44); + out_uint32_le(s, self->client_info.monitorCount); /* MonitorCount */ + + /* TODO: validate for allowed monitors in terminal server (maybe by config?) */ + for (i = 0; i < self->client_info.monitorCount; i++) + { + out_uint32_le(s, self->client_info.minfo[i].left); + out_uint32_le(s, self->client_info.minfo[i].top); + out_uint32_le(s, self->client_info.minfo[i].right); + out_uint32_le(s, self->client_info.minfo[i].bottom); + out_uint32_le(s, self->client_info.minfo[i].is_primary); + } + s_mark_end(s); if (xrdp_rdp_send_data(self, s, 0x37) != 0) @@ -1644,9 +1646,9 @@ xrdp_rdp_process_data_font(struct xrdp_rdp *self, struct stream *s) int seq; DEBUG(("in xrdp_rdp_process_data_font")); - in_uint8s(s, 2); /* num of fonts */ - in_uint8s(s, 2); /* unknown */ - in_uint16_le(s, seq); + in_uint8s(s, 2); /* NumberFonts: 0x0, SHOULD be set to 0 */ + in_uint8s(s, 2); /* TotalNumberFonts: 0x0, SHOULD be set to 0 */ + in_uint16_le(s, seq); /* ListFlags */ /* 419 client sends Seq 1, then 2 */ /* 2600 clients sends only Seq 3 */ @@ -1655,12 +1657,19 @@ xrdp_rdp_process_data_font(struct xrdp_rdp *self, struct stream *s) /* running */ DEBUG(("sending unknown1")); xrdp_rdp_send_unknown1(self); - if (self->client_info.monitorCount > 0) { + + /* TODO: Monitor Layout PDU should send to client after demand active pdu + * MOVE THAT CALL + */ + DEBUG(("sending monitor layout pdu")); + if (self->client_info.monitorCount > 0 && self->client_info.multimon == 1) + { if (xrdp_rdp_send_monitorlayout(self) != 0) { g_writeln("Problem with monitor layout packet!!!"); } } + self->session->up_and_running = 1; DEBUG(("up_and_running set")); xrdp_rdp_send_data_update_sync(self); From 638843526a9bca8abf474aa6edf663a43be6b414 Mon Sep 17 00:00:00 2001 From: speidy Date: Sun, 17 Nov 2013 17:50:40 +0200 Subject: [PATCH 3/5] libxrdp: change xrdp_rdp_send_unknown1 hack to xrdp_rdp_send_fontmap, relying on docs. --- libxrdp/xrdp_rdp.c | 41 +++++++++-------------------------------- 1 file changed, 9 insertions(+), 32 deletions(-) diff --git a/libxrdp/xrdp_rdp.c b/libxrdp/xrdp_rdp.c index 54ae75e0..ed1291fa 100644 --- a/libxrdp/xrdp_rdp.c +++ b/libxrdp/xrdp_rdp.c @@ -25,33 +25,6 @@ #include #endif -/* some compilers need unsigned char to avoid warnings */ -static tui8 g_unknown1[172] = -{ - 0xff, 0x02, 0xb6, 0x00, 0x28, 0x00, 0x00, 0x00, - 0x27, 0x00, 0x27, 0x00, 0x03, 0x00, 0x04, 0x00, - 0x00, 0x00, 0x26, 0x00, 0x01, 0x00, 0x1e, 0x00, - 0x02, 0x00, 0x1f, 0x00, 0x03, 0x00, 0x1d, 0x00, - 0x04, 0x00, 0x27, 0x00, 0x05, 0x00, 0x0b, 0x00, - 0x06, 0x00, 0x28, 0x00, 0x08, 0x00, 0x21, 0x00, - 0x09, 0x00, 0x20, 0x00, 0x0a, 0x00, 0x22, 0x00, - 0x0b, 0x00, 0x25, 0x00, 0x0c, 0x00, 0x24, 0x00, - 0x0d, 0x00, 0x23, 0x00, 0x0e, 0x00, 0x19, 0x00, - 0x0f, 0x00, 0x16, 0x00, 0x10, 0x00, 0x15, 0x00, - 0x11, 0x00, 0x1c, 0x00, 0x12, 0x00, 0x1b, 0x00, - 0x13, 0x00, 0x1a, 0x00, 0x14, 0x00, 0x17, 0x00, - 0x15, 0x00, 0x18, 0x00, 0x16, 0x00, 0x0e, 0x00, - 0x18, 0x00, 0x0c, 0x00, 0x19, 0x00, 0x0d, 0x00, - 0x1a, 0x00, 0x12, 0x00, 0x1b, 0x00, 0x14, 0x00, - 0x1f, 0x00, 0x13, 0x00, 0x20, 0x00, 0x00, 0x00, - 0x21, 0x00, 0x0a, 0x00, 0x22, 0x00, 0x06, 0x00, - 0x23, 0x00, 0x07, 0x00, 0x24, 0x00, 0x08, 0x00, - 0x25, 0x00, 0x09, 0x00, 0x26, 0x00, 0x04, 0x00, - 0x27, 0x00, 0x03, 0x00, 0x28, 0x00, 0x02, 0x00, - 0x29, 0x00, 0x01, 0x00, 0x2a, 0x00, 0x05, 0x00, - 0x2b, 0x00, 0x2a, 0x00 -}; - /* some compilers need unsigned char to avoid warnings */ /* static tui8 g_unknown2[8] = @@ -1575,7 +1548,7 @@ xrdp_rdp_process_screen_update(struct xrdp_rdp *self, struct stream *s) /*****************************************************************************/ static int APP_CC -xrdp_rdp_send_unknown1(struct xrdp_rdp *self) +xrdp_rdp_send_fontmap(struct xrdp_rdp *self) { struct stream *s; @@ -1588,7 +1561,11 @@ xrdp_rdp_send_unknown1(struct xrdp_rdp *self) return 1; } - out_uint8a(s, g_unknown1, 172); + out_uint16_le(s, 0); /* numberEntries */ + out_uint16_le(s, 0); /* totalNumEntries */ + out_uint16_le(s, 0x3); /* mapFlags (sequence flags) */ + out_uint16_le(s, 0x4); /* entrySize */ + s_mark_end(s); if (xrdp_rdp_send_data(self, s, 0x28) != 0) @@ -1655,15 +1632,15 @@ xrdp_rdp_process_data_font(struct xrdp_rdp *self, struct stream *s) if (seq == 2 || seq == 3) /* after second font message, we are up and */ { /* running */ - DEBUG(("sending unknown1")); - xrdp_rdp_send_unknown1(self); + DEBUG(("sending fontmap")); + xrdp_rdp_send_fontmap(self); /* TODO: Monitor Layout PDU should send to client after demand active pdu * MOVE THAT CALL */ - DEBUG(("sending monitor layout pdu")); if (self->client_info.monitorCount > 0 && self->client_info.multimon == 1) { + DEBUG(("sending monitor layout pdu")); if (xrdp_rdp_send_monitorlayout(self) != 0) { g_writeln("Problem with monitor layout packet!!!"); From e5f2f997db5c4d523cbd9da24b83b1b117f81466 Mon Sep 17 00:00:00 2001 From: speidy Date: Sun, 17 Nov 2013 17:53:23 +0200 Subject: [PATCH 4/5] libxrdp: some cleanup --- libxrdp/xrdp_rdp.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/libxrdp/xrdp_rdp.c b/libxrdp/xrdp_rdp.c index ed1291fa..1712704e 100644 --- a/libxrdp/xrdp_rdp.c +++ b/libxrdp/xrdp_rdp.c @@ -25,12 +25,6 @@ #include #endif -/* some compilers need unsigned char to avoid warnings */ -/* -static tui8 g_unknown2[8] = -{ 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x04, 0x00 }; -*/ - /*****************************************************************************/ static int APP_CC xrdp_rdp_read_config(struct xrdp_client_info *client_info) From 6f7958bdcbcc65cc073f1f8f7f1e3bb98d011173 Mon Sep 17 00:00:00 2001 From: speidy Date: Tue, 19 Nov 2013 21:34:07 +0200 Subject: [PATCH 5/5] libxrdp: move xrdp_rdp_send_monitorlayout call after demand active pdu --- libxrdp/libxrdp.c | 11 +++++++++++ libxrdp/libxrdp.h | 2 ++ libxrdp/xrdp_rdp.c | 14 +------------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/libxrdp/libxrdp.c b/libxrdp/libxrdp.c index e72fa1d0..ac5bbe98 100644 --- a/libxrdp/libxrdp.c +++ b/libxrdp/libxrdp.c @@ -107,6 +107,17 @@ libxrdp_process_data(struct xrdp_session *session) { case -1: xrdp_rdp_send_demand_active((struct xrdp_rdp *)session->rdp); + + // send Monitor Layout PDU for multimon + if (session->client_info->monitorCount > 0 && session->client_info->multimon == 1) + { + DEBUG(("sending monitor layout pdu")); + if (xrdp_rdp_send_monitorlayout((struct xrdp_rdp *)session->rdp) != 0) + { + g_writeln("xrdp_rdp_send_monitorlayout: error"); + } + } + session->up_and_running = 0; break; case 0: diff --git a/libxrdp/libxrdp.h b/libxrdp/libxrdp.h index 5bf627b5..70c8a124 100644 --- a/libxrdp/libxrdp.h +++ b/libxrdp/libxrdp.h @@ -353,6 +353,8 @@ xrdp_rdp_incoming(struct xrdp_rdp* self); int APP_CC xrdp_rdp_send_demand_active(struct xrdp_rdp* self); int APP_CC +xrdp_rdp_send_monitorlayout(struct xrdp_rdp* self); +int APP_CC xrdp_rdp_process_confirm_active(struct xrdp_rdp* self, struct stream* s); int APP_CC xrdp_rdp_process_data(struct xrdp_rdp* self, struct stream* s); diff --git a/libxrdp/xrdp_rdp.c b/libxrdp/xrdp_rdp.c index 1712704e..48deb6e2 100644 --- a/libxrdp/xrdp_rdp.c +++ b/libxrdp/xrdp_rdp.c @@ -1572,7 +1572,7 @@ xrdp_rdp_send_fontmap(struct xrdp_rdp *self) return 0; } /*****************************************************************************/ -static int APP_CC +int APP_CC xrdp_rdp_send_monitorlayout(struct xrdp_rdp *self) { struct stream *s; @@ -1629,18 +1629,6 @@ xrdp_rdp_process_data_font(struct xrdp_rdp *self, struct stream *s) DEBUG(("sending fontmap")); xrdp_rdp_send_fontmap(self); - /* TODO: Monitor Layout PDU should send to client after demand active pdu - * MOVE THAT CALL - */ - if (self->client_info.monitorCount > 0 && self->client_info.multimon == 1) - { - DEBUG(("sending monitor layout pdu")); - if (xrdp_rdp_send_monitorlayout(self) != 0) - { - g_writeln("Problem with monitor layout packet!!!"); - } - } - self->session->up_and_running = 1; DEBUG(("up_and_running set")); xrdp_rdp_send_data_update_sync(self);