libxrdp: minor fastpath logic change and indent changes

This commit is contained in:
Jay Sorg 2014-03-06 17:51:35 -08:00
parent fe042b0c61
commit 201bec9794
3 changed files with 192 additions and 178 deletions

View File

@ -1,7 +1,7 @@
/** /**
* xrdp: A Remote Desktop Protocol server. * xrdp: A Remote Desktop Protocol server.
* *
* Copyright (C) Jay Sorg 2012-2013 * Copyright (C) Jay Sorg 2012-2014
* Copyright (C) Idan Freiberg 2013-2014 * Copyright (C) Idan Freiberg 2013-2014
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -52,6 +52,7 @@ xrdp_fastpath_reset(struct xrdp_fastpath *self)
{ {
return 0; return 0;
} }
/*****************************************************************************/ /*****************************************************************************/
int APP_CC int APP_CC
xrdp_fastpath_recv(struct xrdp_fastpath *self, struct stream *s) 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 fp_hdr;
int len = 0; /* unused */ int len = 0; /* unused */
int byte; int byte;
DEBUG((" in xrdp_fastpath_recv")); char *holdp;
DEBUG((" in xrdp_fastpath_recv"));
holdp = s->p;
if (!s_check_rem(s, 2)) if (!s_check_rem(s, 2))
{ {
return 1; return 1;
@ -73,26 +76,26 @@ xrdp_fastpath_recv(struct xrdp_fastpath *self, struct stream *s)
if (byte & 0x80) if (byte & 0x80)
{ {
byte &= ~(0x80); byte &= ~(0x80);
len = (byte << 8); len = (byte << 8);
if (!s_check_rem(s, 1)) if (!s_check_rem(s, 1))
{ {
return 1; return 1;
} }
in_uint8(s, byte); /* length 2 (1 byte) */ in_uint8(s, byte); /* length 2 (1 byte) */
len += byte; len += byte;
} }
else else
{ {
len = byte; len = byte;
} }
s->next_packet = holdp + len;
DEBUG((" out xrdp_fastpath_recv")); DEBUG((" out xrdp_fastpath_recv"));
return 0; return 0;
} }
/*****************************************************************************/ /*****************************************************************************/
int APP_CC int APP_CC
xrdp_fastpath_init(struct xrdp_fastpath *self) 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 int APP_CC
xrdp_fastpath_process_EVENT_SCANCODE(struct xrdp_fastpath *self, int eventFlags, struct stream *s) xrdp_fastpath_process_EVENT_SCANCODE(struct xrdp_fastpath *self, int eventFlags, struct stream *s)
{ {
int flags; int flags;
int code; int code;
flags = 0; flags = 0;
if (!s_check_rem(s, 1)) if (!s_check_rem(s, 1))
{ {
return 1; return 1;
} }
in_uint8(s, code); /* keyCode (1 byte) */ in_uint8(s, code); /* keyCode (1 byte) */
if ((eventFlags & FASTPATH_INPUT_KBDFLAGS_RELEASE)) if ((eventFlags & FASTPATH_INPUT_KBDFLAGS_RELEASE))
flags |= KBD_FLAG_UP; flags |= KBD_FLAG_UP;
else else
flags |= KBD_FLAG_DOWN; flags |= KBD_FLAG_DOWN;
if ((eventFlags & FASTPATH_INPUT_KBDFLAGS_EXTENDED)) if ((eventFlags & FASTPATH_INPUT_KBDFLAGS_EXTENDED))
flags |= KBD_FLAG_EXT; flags |= KBD_FLAG_EXT;
if (self->session->callback != 0) if (self->session->callback != 0)
{ {
/* msg_type can be /* msg_type can be
RDP_INPUT_SYNCHRONIZE - 0 RDP_INPUT_SYNCHRONIZE - 0
RDP_INPUT_SCANCODE - 4 RDP_INPUT_SCANCODE - 4
RDP_INPUT_MOUSE - 0x8001 RDP_INPUT_MOUSE - 0x8001
RDP_INPUT_MOUSEX - 0x8002 */ RDP_INPUT_MOUSEX - 0x8002 */
/* call to xrdp_wm.c : callback */ /* call to xrdp_wm.c : callback */
self->session->callback(self->session->id, RDP_INPUT_SCANCODE, code, 0, self->session->callback(self->session->id, RDP_INPUT_SCANCODE, code, 0,
flags, 0); flags, 0);
} }
return 0; return 0;
} }
/*****************************************************************************/ /*****************************************************************************/
/* FASTPATH_INPUT_EVENT_MOUSE */ /* FASTPATH_INPUT_EVENT_MOUSE */
int APP_CC 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 pointerFlags;
int xPos; int xPos;
int yPos; int yPos;
if (!s_check_rem(s, 2 + 2 + 2)) if (!s_check_rem(s, 2 + 2 + 2))
{ {
return 1; return 1;
} }
in_uint16_le(s, pointerFlags); /* pointerFlags (2 bytes) */ in_uint16_le(s, pointerFlags); /* pointerFlags (2 bytes) */
in_uint16_le(s, xPos); /* xPos (2 bytes) */ in_uint16_le(s, xPos); /* xPos (2 bytes) */
in_uint16_le(s, yPos); /* yPos (2 bytes) */ in_uint16_le(s, yPos); /* yPos (2 bytes) */
if (self->session->callback != 0) if (self->session->callback != 0)
{ {
/* msg_type can be /* msg_type can be
RDP_INPUT_SYNCHRONIZE - 0 RDP_INPUT_SYNCHRONIZE - 0
RDP_INPUT_SCANCODE - 4 RDP_INPUT_SCANCODE - 4
RDP_INPUT_MOUSE - 0x8001 RDP_INPUT_MOUSE - 0x8001
RDP_INPUT_MOUSEX - 0x8002 */ RDP_INPUT_MOUSEX - 0x8002 */
/* call to xrdp_wm.c : callback */ /* call to xrdp_wm.c : callback */
self->session->callback(self->session->id, RDP_INPUT_MOUSE, xPos, yPos, self->session->callback(self->session->id, RDP_INPUT_MOUSE,
pointerFlags, 0); xPos, yPos, pointerFlags, 0);
} }
return 0; return 0;
} }
/*****************************************************************************/ /*****************************************************************************/
/* FASTPATH_INPUT_EVENT_MOUSEX */ /* FASTPATH_INPUT_EVENT_MOUSEX */
int APP_CC 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 pointerFlags;
int xPos; int xPos;
int yPos; int yPos;
if (!s_check_rem(s, 2 + 2 + 2)) if (!s_check_rem(s, 2 + 2 + 2))
{ {
return 1; return 1;
} }
in_uint16_le(s, pointerFlags); /* pointerFlags (2 bytes) */ in_uint16_le(s, pointerFlags); /* pointerFlags (2 bytes) */
in_uint16_le(s, xPos); /* xPos (2 bytes) */ in_uint16_le(s, xPos); /* xPos (2 bytes) */
in_uint16_le(s, yPos); /* yPos (2 bytes) */ in_uint16_le(s, yPos); /* yPos (2 bytes) */
if (self->session->callback != 0) if (self->session->callback != 0)
{ {
/* msg_type can be /* msg_type can be
RDP_INPUT_SYNCHRONIZE - 0 RDP_INPUT_SYNCHRONIZE - 0
RDP_INPUT_SCANCODE - 4 RDP_INPUT_SCANCODE - 4
RDP_INPUT_MOUSE - 0x8001 RDP_INPUT_MOUSE - 0x8001
RDP_INPUT_MOUSEX - 0x8002 */ RDP_INPUT_MOUSEX - 0x8002 */
/* call to xrdp_wm.c : callback */ /* call to xrdp_wm.c : callback */
self->session->callback(self->session->id, RDP_INPUT_MOUSEX, xPos, yPos, self->session->callback(self->session->id, RDP_INPUT_MOUSEX,
pointerFlags, 0); xPos, yPos, pointerFlags, 0);
} }
return 0; return 0;
} }
/*****************************************************************************/ /*****************************************************************************/
/* FASTPATH_INPUT_EVENT_SYNC */ /* FASTPATH_INPUT_EVENT_SYNC */
int APP_CC 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" * The eventFlags bitfield (5 bits in size) contains flags indicating the "on"
* status of the keyboard toggle keys. * status of the keyboard toggle keys.
*/ */
if (self->session->callback != 0) if (self->session->callback != 0)
{ {
/* msg_type can be /* msg_type can be
RDP_INPUT_SYNCHRONIZE - 0 RDP_INPUT_SYNCHRONIZE - 0
RDP_INPUT_SCANCODE - 4 RDP_INPUT_SCANCODE - 4
RDP_INPUT_MOUSE - 0x8001 RDP_INPUT_MOUSE - 0x8001
RDP_INPUT_MOUSEX - 0x8002 */ RDP_INPUT_MOUSEX - 0x8002 */
/* call to xrdp_wm.c : callback */ /* call to xrdp_wm.c : callback */
self->session->callback(self->session->id, RDP_INPUT_SYNCHRONIZE, eventCode, 0, self->session->callback(self->session->id, RDP_INPUT_SYNCHRONIZE,
eventFlags, 0); eventCode, 0, eventFlags, 0);
} }
return 0; return 0;
} }
/*****************************************************************************/ /*****************************************************************************/
/* FASTPATH_INPUT_EVENT_UNICODE */ /* FASTPATH_INPUT_EVENT_UNICODE */
int APP_CC 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)) 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); in_uint8s(s, 2);
return 0; return 0;
} }
/*****************************************************************************/ /*****************************************************************************/
/* FASTPATH_INPUT_EVENT */ /* FASTPATH_INPUT_EVENT */
int APP_CC int APP_CC
@ -389,7 +400,8 @@ xrdp_fastpath_process_input_event(struct xrdp_fastpath *self, struct stream *s)
int eventFlags; int eventFlags;
// process fastpath input events // process fastpath input events
for (i = 0 ; i < self->numEvents ; i++) { for (i = 0; i < self->numEvents; i++)
{
if (!s_check_rem(s, 1)) if (!s_check_rem(s, 1))
{ {
return 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)); // eventCode, eventFlags, self->sec_layer->fastpath_layer->numEvents));
switch (eventCode) switch (eventCode)
{ {
case FASTPATH_INPUT_EVENT_SCANCODE: case FASTPATH_INPUT_EVENT_SCANCODE:
if (xrdp_fastpath_process_EVENT_SCANCODE(self, eventFlags, s) != 0) if (xrdp_fastpath_process_EVENT_SCANCODE(self, eventFlags, s) != 0)
{ {
return 1; return 1;
} }
break; break;
case FASTPATH_INPUT_EVENT_MOUSE: case FASTPATH_INPUT_EVENT_MOUSE:
if (xrdp_fastpath_process_EVENT_MOUSE(self, eventFlags, s) != 0) if (xrdp_fastpath_process_EVENT_MOUSE(self, eventFlags, s) != 0)
{ {
return 1; return 1;
} }
break; break;
case FASTPATH_INPUT_EVENT_MOUSEX: case FASTPATH_INPUT_EVENT_MOUSEX:
if (xrdp_fastpath_process_EVENT_MOUSEX(self, eventFlags, s) != 0) if (xrdp_fastpath_process_EVENT_MOUSEX(self, eventFlags, s) != 0)
{ {
return 1; return 1;
} }
break; break;
case FASTPATH_INPUT_EVENT_SYNC: case FASTPATH_INPUT_EVENT_SYNC:
if (xrdp_fastpath_process_EVENT_SYNC(self, eventCode, eventFlags, s) != 0) if (xrdp_fastpath_process_EVENT_SYNC(self, eventCode, eventFlags, s) != 0)
{ {
return 1; return 1;
} }
break; break;
case FASTPATH_INPUT_EVENT_UNICODE: case FASTPATH_INPUT_EVENT_UNICODE:
if (xrdp_fastpath_process_EVENT_UNICODE(self, eventFlags, s) != 0) if (xrdp_fastpath_process_EVENT_UNICODE(self, eventFlags, s) != 0)
{ {
return 1; return 1;
} }
break; break;
default: default:
g_writeln("xrdp_fastpath_process_input_event: unknown eventCode %d", eventCode); g_writeln("xrdp_fastpath_process_input_event: unknown eventCode %d", eventCode);
break; break;
} }
} }
return 0; return 0;
} }

View File

@ -311,7 +311,7 @@ xrdp_rdp_recv(struct xrdp_rdp *self, struct stream *s, int *code)
{ {
return 1; return 1;
} }
s->next_packet = 0; /* next_packet gets set in xrdp_sec_recv_fastpath */
*code = 2; // special code for fastpath input *code = 2; // special code for fastpath input
DEBUG(("out (fastpath) xrdp_rdp_recv")); DEBUG(("out (fastpath) xrdp_rdp_recv"));
return 0; return 0;

View File

@ -955,58 +955,62 @@ xrdp_sec_establish_keys(struct xrdp_sec *self)
int APP_CC int APP_CC
xrdp_sec_recv_fastpath(struct xrdp_sec *self, struct stream *s) xrdp_sec_recv_fastpath(struct xrdp_sec *self, struct stream *s)
{ {
int ver; int ver;
int len; int len;
int pad; int pad;
if (xrdp_fastpath_recv(self->fastpath_layer, s) != 0) { LLOGLN(10, ("xrdp_sec_recv_fastpath:"));
return 1; if (xrdp_fastpath_recv(self->fastpath_layer, s) != 0)
} {
return 1;
}
if (self->crypt_level == CRYPT_LEVEL_FIPS) if (self->fastpath_layer->secFlags & FASTPATH_INPUT_ENCRYPTED)
{ {
if (!s_check_rem(s, 4)) if (self->crypt_level == CRYPT_LEVEL_FIPS)
{ {
return 1; if (!s_check_rem(s, 12))
} {
in_uint16_le(s, len); return 1;
in_uint8(s, ver); /* length (2 bytes) */ }
if (len != 0x10) /* length MUST set to 0x10 */ in_uint16_le(s, len);
{ in_uint8(s, ver); /* length (2 bytes) */
return 1; if (len != 0x10) /* length MUST set to 0x10 */
} {
in_uint8(s, pad); return 1;
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 */ in_uint8(s, pad);
LLOGLN(10, ("xrdp_sec_recv_fastpath: data len %d", (int)(s->end - s->p))); LLOGLN(10, ("xrdp_sec_recv_fastpath: len %d ver %d pad %d", len, ver, pad));
xrdp_sec_fips_decrypt(self, s->p, (int)(s->end - s->p)); in_uint8s(s, 8); /* dataSignature (8 bytes), skip for now */
s->end -= pad; LLOGLN(10, ("xrdp_sec_recv_fastpath: data len %d", (int)(s->end - s->p)));
} else { xrdp_sec_fips_decrypt(self, s->p, (int)(s->end - s->p));
if (!s_check_rem(s, 8)) s->end -= pad;
{ }
return 1; else
} {
in_uint8s(s, 8); /* dataSignature (8 bytes), skip for now */ 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) if (self->fastpath_layer->numEvents == 0)
{ {
xrdp_sec_decrypt(self, s->p, (int)(s->end - s->p)); /**
} * 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) { return 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;
} }
/*****************************************************************************/ /*****************************************************************************/
/* returns error */ /* returns error */