From 201bec97940f0c8e063158b2f256981edff51908 Mon Sep 17 00:00:00 2001 From: Jay Sorg Date: Thu, 6 Mar 2014 17:51:35 -0800 Subject: [PATCH] libxrdp: minor fastpath logic change and indent changes --- libxrdp/xrdp_fastpath.c | 268 +++++++++++++++++++++------------------- libxrdp/xrdp_rdp.c | 2 +- libxrdp/xrdp_sec.c | 100 ++++++++------- 3 files changed, 192 insertions(+), 178 deletions(-) diff --git a/libxrdp/xrdp_fastpath.c b/libxrdp/xrdp_fastpath.c index d031f003..927f9407 100644 --- a/libxrdp/xrdp_fastpath.c +++ b/libxrdp/xrdp_fastpath.c @@ -1,7 +1,7 @@ /** * xrdp: A Remote Desktop Protocol server. * - * Copyright (C) Jay Sorg 2012-2013 + * Copyright (C) Jay Sorg 2012-2014 * Copyright (C) Idan Freiberg 2013-2014 * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -52,6 +52,7 @@ xrdp_fastpath_reset(struct xrdp_fastpath *self) { return 0; } + /*****************************************************************************/ int APP_CC xrdp_fastpath_recv(struct xrdp_fastpath *self, struct stream *s) @@ -59,8 +60,10 @@ xrdp_fastpath_recv(struct xrdp_fastpath *self, struct stream *s) int fp_hdr; int len = 0; /* unused */ int byte; - DEBUG((" in xrdp_fastpath_recv")); + char *holdp; + DEBUG((" in xrdp_fastpath_recv")); + holdp = s->p; if (!s_check_rem(s, 2)) { return 1; @@ -73,26 +76,26 @@ xrdp_fastpath_recv(struct xrdp_fastpath *self, struct stream *s) if (byte & 0x80) { - byte &= ~(0x80); - len = (byte << 8); + byte &= ~(0x80); + len = (byte << 8); - if (!s_check_rem(s, 1)) - { - return 1; - } - in_uint8(s, byte); /* length 2 (1 byte) */ + if (!s_check_rem(s, 1)) + { + return 1; + } + in_uint8(s, byte); /* length 2 (1 byte) */ - len += byte; + len += byte; } else { - len = byte; + len = byte; } - + s->next_packet = holdp + len; DEBUG((" out xrdp_fastpath_recv")); - return 0; } + /*****************************************************************************/ int APP_CC xrdp_fastpath_init(struct xrdp_fastpath *self) @@ -252,97 +255,102 @@ xrdp_fastpath_process_data(struct xrdp_fastpath *self, struct stream *s, int APP_CC xrdp_fastpath_process_EVENT_SCANCODE(struct xrdp_fastpath *self, int eventFlags, struct stream *s) { - int flags; - int code; - flags = 0; + int flags; + int code; + flags = 0; - if (!s_check_rem(s, 1)) - { - return 1; - } - in_uint8(s, code); /* keyCode (1 byte) */ + if (!s_check_rem(s, 1)) + { + return 1; + } + in_uint8(s, code); /* keyCode (1 byte) */ - if ((eventFlags & FASTPATH_INPUT_KBDFLAGS_RELEASE)) - flags |= KBD_FLAG_UP; - else - flags |= KBD_FLAG_DOWN; + if ((eventFlags & FASTPATH_INPUT_KBDFLAGS_RELEASE)) + flags |= KBD_FLAG_UP; + else + flags |= KBD_FLAG_DOWN; - if ((eventFlags & FASTPATH_INPUT_KBDFLAGS_EXTENDED)) - flags |= KBD_FLAG_EXT; + if ((eventFlags & FASTPATH_INPUT_KBDFLAGS_EXTENDED)) + flags |= KBD_FLAG_EXT; - if (self->session->callback != 0) - { - /* msg_type can be - RDP_INPUT_SYNCHRONIZE - 0 - RDP_INPUT_SCANCODE - 4 - RDP_INPUT_MOUSE - 0x8001 - RDP_INPUT_MOUSEX - 0x8002 */ - /* call to xrdp_wm.c : callback */ - self->session->callback(self->session->id, RDP_INPUT_SCANCODE, code, 0, - flags, 0); - } - return 0; + if (self->session->callback != 0) + { + /* msg_type can be + RDP_INPUT_SYNCHRONIZE - 0 + RDP_INPUT_SCANCODE - 4 + RDP_INPUT_MOUSE - 0x8001 + RDP_INPUT_MOUSEX - 0x8002 */ + /* call to xrdp_wm.c : callback */ + self->session->callback(self->session->id, RDP_INPUT_SCANCODE, code, 0, + flags, 0); + } + return 0; } + /*****************************************************************************/ /* FASTPATH_INPUT_EVENT_MOUSE */ int APP_CC -xrdp_fastpath_process_EVENT_MOUSE(struct xrdp_fastpath *self, int eventFlags, struct stream *s) +xrdp_fastpath_process_EVENT_MOUSE(struct xrdp_fastpath *self, int eventFlags, + struct stream *s) { - int pointerFlags; - int xPos; - int yPos; + int pointerFlags; + int xPos; + int yPos; - if (!s_check_rem(s, 2 + 2 + 2)) - { - return 1; - } - in_uint16_le(s, pointerFlags); /* pointerFlags (2 bytes) */ - in_uint16_le(s, xPos); /* xPos (2 bytes) */ - in_uint16_le(s, yPos); /* yPos (2 bytes) */ + if (!s_check_rem(s, 2 + 2 + 2)) + { + return 1; + } + in_uint16_le(s, pointerFlags); /* pointerFlags (2 bytes) */ + in_uint16_le(s, xPos); /* xPos (2 bytes) */ + in_uint16_le(s, yPos); /* yPos (2 bytes) */ - if (self->session->callback != 0) - { - /* msg_type can be - RDP_INPUT_SYNCHRONIZE - 0 - RDP_INPUT_SCANCODE - 4 - RDP_INPUT_MOUSE - 0x8001 - RDP_INPUT_MOUSEX - 0x8002 */ - /* call to xrdp_wm.c : callback */ - self->session->callback(self->session->id, RDP_INPUT_MOUSE, xPos, yPos, - pointerFlags, 0); - } - return 0; + if (self->session->callback != 0) + { + /* msg_type can be + RDP_INPUT_SYNCHRONIZE - 0 + RDP_INPUT_SCANCODE - 4 + RDP_INPUT_MOUSE - 0x8001 + RDP_INPUT_MOUSEX - 0x8002 */ + /* call to xrdp_wm.c : callback */ + self->session->callback(self->session->id, RDP_INPUT_MOUSE, + xPos, yPos, pointerFlags, 0); + } + return 0; } + /*****************************************************************************/ /* FASTPATH_INPUT_EVENT_MOUSEX */ int APP_CC -xrdp_fastpath_process_EVENT_MOUSEX(struct xrdp_fastpath *self, int eventFlags, struct stream *s) +xrdp_fastpath_process_EVENT_MOUSEX(struct xrdp_fastpath *self, + int eventFlags, struct stream *s) { - int pointerFlags; - int xPos; - int yPos; + int pointerFlags; + int xPos; + int yPos; - if (!s_check_rem(s, 2 + 2 + 2)) - { - return 1; - } - in_uint16_le(s, pointerFlags); /* pointerFlags (2 bytes) */ - in_uint16_le(s, xPos); /* xPos (2 bytes) */ - in_uint16_le(s, yPos); /* yPos (2 bytes) */ + if (!s_check_rem(s, 2 + 2 + 2)) + { + return 1; + } + in_uint16_le(s, pointerFlags); /* pointerFlags (2 bytes) */ + in_uint16_le(s, xPos); /* xPos (2 bytes) */ + in_uint16_le(s, yPos); /* yPos (2 bytes) */ - if (self->session->callback != 0) - { - /* msg_type can be - RDP_INPUT_SYNCHRONIZE - 0 - RDP_INPUT_SCANCODE - 4 - RDP_INPUT_MOUSE - 0x8001 - RDP_INPUT_MOUSEX - 0x8002 */ - /* call to xrdp_wm.c : callback */ - self->session->callback(self->session->id, RDP_INPUT_MOUSEX, xPos, yPos, - pointerFlags, 0); - } - return 0; + if (self->session->callback != 0) + { + /* msg_type can be + RDP_INPUT_SYNCHRONIZE - 0 + RDP_INPUT_SCANCODE - 4 + RDP_INPUT_MOUSE - 0x8001 + RDP_INPUT_MOUSEX - 0x8002 */ + /* call to xrdp_wm.c : callback */ + self->session->callback(self->session->id, RDP_INPUT_MOUSEX, + xPos, yPos, pointerFlags, 0); + } + return 0; } + /*****************************************************************************/ /* FASTPATH_INPUT_EVENT_SYNC */ int APP_CC @@ -353,23 +361,25 @@ xrdp_fastpath_process_EVENT_SYNC(struct xrdp_fastpath *self, int eventCode, int * The eventFlags bitfield (5 bits in size) contains flags indicating the "on" * status of the keyboard toggle keys. */ - if (self->session->callback != 0) - { - /* msg_type can be - RDP_INPUT_SYNCHRONIZE - 0 - RDP_INPUT_SCANCODE - 4 - RDP_INPUT_MOUSE - 0x8001 - RDP_INPUT_MOUSEX - 0x8002 */ - /* call to xrdp_wm.c : callback */ - self->session->callback(self->session->id, RDP_INPUT_SYNCHRONIZE, eventCode, 0, - eventFlags, 0); - } - return 0; + if (self->session->callback != 0) + { + /* msg_type can be + RDP_INPUT_SYNCHRONIZE - 0 + RDP_INPUT_SCANCODE - 4 + RDP_INPUT_MOUSE - 0x8001 + RDP_INPUT_MOUSEX - 0x8002 */ + /* call to xrdp_wm.c : callback */ + self->session->callback(self->session->id, RDP_INPUT_SYNCHRONIZE, + eventCode, 0, eventFlags, 0); + } + return 0; } + /*****************************************************************************/ /* FASTPATH_INPUT_EVENT_UNICODE */ int APP_CC -xrdp_fastpath_process_EVENT_UNICODE(struct xrdp_fastpath *self, int eventFlags, struct stream *s) +xrdp_fastpath_process_EVENT_UNICODE(struct xrdp_fastpath *self, + int eventFlags, struct stream *s) { if (!s_check_rem(s, 2)) { @@ -378,6 +388,7 @@ xrdp_fastpath_process_EVENT_UNICODE(struct xrdp_fastpath *self, int eventFlags, in_uint8s(s, 2); return 0; } + /*****************************************************************************/ /* FASTPATH_INPUT_EVENT */ int APP_CC @@ -389,7 +400,8 @@ xrdp_fastpath_process_input_event(struct xrdp_fastpath *self, struct stream *s) int eventFlags; // process fastpath input events - for (i = 0 ; i < self->numEvents ; i++) { + for (i = 0; i < self->numEvents; i++) + { if (!s_check_rem(s, 1)) { return 1; @@ -403,44 +415,42 @@ xrdp_fastpath_process_input_event(struct xrdp_fastpath *self, struct stream *s) // eventCode, eventFlags, self->sec_layer->fastpath_layer->numEvents)); switch (eventCode) - { + { case FASTPATH_INPUT_EVENT_SCANCODE: - if (xrdp_fastpath_process_EVENT_SCANCODE(self, eventFlags, s) != 0) - { - return 1; - } - break; + if (xrdp_fastpath_process_EVENT_SCANCODE(self, eventFlags, s) != 0) + { + return 1; + } + break; case FASTPATH_INPUT_EVENT_MOUSE: - if (xrdp_fastpath_process_EVENT_MOUSE(self, eventFlags, s) != 0) - { - return 1; - } - break; + if (xrdp_fastpath_process_EVENT_MOUSE(self, eventFlags, s) != 0) + { + return 1; + } + break; case FASTPATH_INPUT_EVENT_MOUSEX: - if (xrdp_fastpath_process_EVENT_MOUSEX(self, eventFlags, s) != 0) - { - return 1; - } - break; + if (xrdp_fastpath_process_EVENT_MOUSEX(self, eventFlags, s) != 0) + { + return 1; + } + break; case FASTPATH_INPUT_EVENT_SYNC: - if (xrdp_fastpath_process_EVENT_SYNC(self, eventCode, eventFlags, s) != 0) - { - return 1; - } - break; + if (xrdp_fastpath_process_EVENT_SYNC(self, eventCode, eventFlags, s) != 0) + { + return 1; + } + break; case FASTPATH_INPUT_EVENT_UNICODE: - if (xrdp_fastpath_process_EVENT_UNICODE(self, eventFlags, s) != 0) - { - return 1; - } - break; + if (xrdp_fastpath_process_EVENT_UNICODE(self, eventFlags, s) != 0) + { + return 1; + } + break; default: - g_writeln("xrdp_fastpath_process_input_event: unknown eventCode %d", eventCode); - break; + g_writeln("xrdp_fastpath_process_input_event: unknown eventCode %d", eventCode); + break; } - } - return 0; } diff --git a/libxrdp/xrdp_rdp.c b/libxrdp/xrdp_rdp.c index ccc4f8b5..a808aaa8 100644 --- a/libxrdp/xrdp_rdp.c +++ b/libxrdp/xrdp_rdp.c @@ -311,7 +311,7 @@ xrdp_rdp_recv(struct xrdp_rdp *self, struct stream *s, int *code) { return 1; } - s->next_packet = 0; + /* next_packet gets set in xrdp_sec_recv_fastpath */ *code = 2; // special code for fastpath input DEBUG(("out (fastpath) xrdp_rdp_recv")); return 0; diff --git a/libxrdp/xrdp_sec.c b/libxrdp/xrdp_sec.c index 6c04a2e5..626fc91e 100644 --- a/libxrdp/xrdp_sec.c +++ b/libxrdp/xrdp_sec.c @@ -955,58 +955,62 @@ xrdp_sec_establish_keys(struct xrdp_sec *self) int APP_CC xrdp_sec_recv_fastpath(struct xrdp_sec *self, struct stream *s) { - int ver; - int len; - int pad; + int ver; + int len; + int pad; - if (xrdp_fastpath_recv(self->fastpath_layer, s) != 0) { - return 1; - } + LLOGLN(10, ("xrdp_sec_recv_fastpath:")); + if (xrdp_fastpath_recv(self->fastpath_layer, s) != 0) + { + return 1; + } - if (self->crypt_level == CRYPT_LEVEL_FIPS) - { - if (!s_check_rem(s, 4)) - { - return 1; - } - in_uint16_le(s, len); - in_uint8(s, ver); /* length (2 bytes) */ - if (len != 0x10) /* length MUST set to 0x10 */ - { - return 1; - } - in_uint8(s, pad); - LLOGLN(10, ("xrdp_sec_recv_fastpath: len %d ver %d pad %d", len, ver, pad)); - in_uint8s(s, 8); /* dataSignature (8 bytes), skip for now */ - LLOGLN(10, ("xrdp_sec_recv_fastpath: data len %d", (int)(s->end - s->p))); - xrdp_sec_fips_decrypt(self, s->p, (int)(s->end - s->p)); - s->end -= pad; - } else { - if (!s_check_rem(s, 8)) - { - return 1; - } - in_uint8s(s, 8); /* dataSignature (8 bytes), skip for now */ + if (self->fastpath_layer->secFlags & FASTPATH_INPUT_ENCRYPTED) + { + if (self->crypt_level == CRYPT_LEVEL_FIPS) + { + if (!s_check_rem(s, 12)) + { + return 1; + } + in_uint16_le(s, len); + in_uint8(s, ver); /* length (2 bytes) */ + if (len != 0x10) /* length MUST set to 0x10 */ + { + return 1; + } + in_uint8(s, pad); + LLOGLN(10, ("xrdp_sec_recv_fastpath: len %d ver %d pad %d", len, ver, pad)); + in_uint8s(s, 8); /* dataSignature (8 bytes), skip for now */ + LLOGLN(10, ("xrdp_sec_recv_fastpath: data len %d", (int)(s->end - s->p))); + xrdp_sec_fips_decrypt(self, s->p, (int)(s->end - s->p)); + s->end -= pad; + } + else + { + if (!s_check_rem(s, 8)) + { + return 1; + } + in_uint8s(s, 8); /* dataSignature (8 bytes), skip for now */ + xrdp_sec_decrypt(self, s->p, (int)(s->end - s->p)); + } + } - if (self->fastpath_layer->secFlags & FASTPATH_INPUT_ENCRYPTED) - { - xrdp_sec_decrypt(self, s->p, (int)(s->end - s->p)); - } - } + if (self->fastpath_layer->numEvents == 0) + { + /** + * If numberEvents is not provided in fpInputHeader, it will be provided + * as one additional byte here. + */ + if (!s_check_rem(s, 8)) + { + return 1; + } + in_uint8(s, self->fastpath_layer->numEvents); /* numEvents (1 byte) (optional) */ + } - if (self->fastpath_layer->numEvents == 0) { - /** - * If numberEvents is not provided in fpInputHeader, it will be provided - * as one additional byte here. - */ - if (!s_check_rem(s, 8)) - { - return 1; - } - in_uint8(s, self->fastpath_layer->numEvents); /* numEvents (1 byte) (optional) */ - } - - return 0; + return 0; } /*****************************************************************************/ /* returns error */