xrdp/libxrdp/xrdp_rdp.c

1370 lines
38 KiB
C
Raw Normal View History

2005-06-28 07:11:35 +04:00
/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
xrdp: A Remote Desktop Protocol server.
2010-05-04 13:24:24 +04:00
Copyright (C) Jay Sorg 2004-2010
2005-06-28 07:11:35 +04:00
rdp layer
*/
#include "libxrdp.h"
2012-04-06 02:40:46 +04:00
#if defined(XRDP_FREERDP1)
#include <freerdp/codec/mppc_enc.h>
#endif
2007-09-15 12:14:49 +04:00
/* some compilers need unsigned char to avoid warnings */
static tui8 g_unknown1[172] =
2005-06-28 07:11:35 +04:00
{ 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 };
2007-09-15 12:14:49 +04:00
/* some compilers need unsigned char to avoid warnings */
/*
2007-09-15 12:14:49 +04:00
static tui8 g_unknown2[8] =
{ 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x04, 0x00 };
*/
2005-06-28 07:11:35 +04:00
/*****************************************************************************/
static int APP_CC
xrdp_rdp_read_config(struct xrdp_client_info* client_info)
{
int index = 0;
struct list* items = (struct list *)NULL;
struct list* values = (struct list *)NULL;
char* item = (char *)NULL;
char* value = (char *)NULL;
char cfg_file[256];
2005-06-28 07:11:35 +04:00
/* initialize (zero out) local variables: */
g_memset(cfg_file,0,sizeof(char) * 256);
2007-10-28 09:14:13 +03:00
items = list_create();
items->auto_free = 1;
values = list_create();
values->auto_free = 1;
g_snprintf(cfg_file, 255, "%s/xrdp.ini", XRDP_CFG_PATH);
file_by_name_read_section(cfg_file, "globals", items, values);
2007-10-28 09:14:13 +03:00
for (index = 0; index < items->count; index++)
2005-06-28 07:11:35 +04:00
{
2007-10-28 09:14:13 +03:00
item = (char*)list_get_item(items, index);
value = (char*)list_get_item(values, index);
if (g_strcasecmp(item, "bitmap_cache") == 0)
2005-06-28 07:11:35 +04:00
{
2007-10-28 09:14:13 +03:00
if ((g_strcasecmp(value, "yes") == 0) ||
(g_strcasecmp(value, "true") == 0) ||
(g_strcasecmp(value, "1") == 0))
2005-06-28 07:11:35 +04:00
{
2007-10-28 09:14:13 +03:00
client_info->use_bitmap_cache = 1;
2005-06-28 07:11:35 +04:00
}
2007-10-28 09:14:13 +03:00
}
else if (g_strcasecmp(item, "bitmap_compression") == 0)
{
if (g_strcasecmp(value, "yes") == 0 ||
g_strcasecmp(value, "true") == 0 ||
g_strcasecmp(value, "1") == 0)
{
client_info->use_bitmap_comp = 1;
}
}
else if (g_strcasecmp(item, "crypt_level") == 0)
{
if (g_strcasecmp(value, "low") == 0)
{
client_info->crypt_level = 1;
}
else if (g_strcasecmp(value, "medium") == 0)
2005-06-28 07:11:35 +04:00
{
2007-10-28 09:14:13 +03:00
client_info->crypt_level = 2;
2005-06-28 07:11:35 +04:00
}
2007-10-28 09:14:13 +03:00
else if (g_strcasecmp(value, "high") == 0)
{
2007-10-28 09:14:13 +03:00
client_info->crypt_level = 3;
}
else
{
g_writeln("Warning: Your configured crypt level is"
"undefined 'high' will be used");
client_info->crypt_level = 3;
}
2007-10-28 09:14:13 +03:00
}
else if (g_strcasecmp(item, "channel_code") == 0)
{
if ((g_strcasecmp(value, "yes") == 0) ||
(g_strcasecmp(value, "1") == 0) ||
(g_strcasecmp(value, "true") == 0))
{
2007-10-28 09:14:13 +03:00
client_info->channel_code = 1;
}
else
{
g_writeln("Info: All channels are disabled");
}
2005-06-28 07:11:35 +04:00
}
2011-08-25 09:45:02 +04:00
else if (g_strcasecmp(item, "max_bpp") == 0)
{
client_info->max_bpp = g_atoi(value);
}
2005-06-28 07:11:35 +04:00
}
2007-10-28 09:14:13 +03:00
list_delete(items);
list_delete(values);
2005-06-28 07:11:35 +04:00
return 0;
}
/*****************************************************************************/
struct xrdp_rdp* APP_CC
2010-05-04 13:24:24 +04:00
xrdp_rdp_create(struct xrdp_session* session, struct trans* trans)
2005-06-28 07:11:35 +04:00
{
struct xrdp_rdp* self = (struct xrdp_rdp *)NULL;
int bytes;
2005-06-28 07:11:35 +04:00
2007-01-15 12:08:03 +03:00
DEBUG(("in xrdp_rdp_create"));
2005-06-28 07:11:35 +04:00
self = (struct xrdp_rdp*)g_malloc(sizeof(struct xrdp_rdp), 1);
self->session = session;
self->share_id = 66538;
/* read ini settings */
xrdp_rdp_read_config(&self->client_info);
/* create sec layer */
2010-05-04 13:24:24 +04:00
self->sec_layer = xrdp_sec_create(self, trans, self->client_info.crypt_level,
2006-12-28 09:15:13 +03:00
self->client_info.channel_code);
2006-03-17 04:10:24 +03:00
/* default 8 bit v1 color bitmap cache entries and size */
2006-03-13 03:58:12 +03:00
self->client_info.cache1_entries = 600;
self->client_info.cache1_size = 256;
self->client_info.cache2_entries = 300;
self->client_info.cache2_size = 1024;
self->client_info.cache3_entries = 262;
self->client_info.cache3_size = 4096;
/* load client ip info */
bytes = sizeof(self->client_info.client_ip) - 1;
g_write_ip_address(trans->sck, self->client_info.client_ip, bytes);
2012-04-06 02:40:46 +04:00
#if defined(XRDP_FREERDP1)
self->mppc_enc = mppc_enc_new(PROTO_RDP_50);
#endif
self->client_info.size = sizeof(self->client_info);
2007-01-15 12:08:03 +03:00
DEBUG(("out xrdp_rdp_create"));
2005-06-28 07:11:35 +04:00
return self;
}
/*****************************************************************************/
void APP_CC
xrdp_rdp_delete(struct xrdp_rdp* self)
{
if (self == 0)
{
return;
}
xrdp_sec_delete(self->sec_layer);
2012-04-06 02:40:46 +04:00
#if defined(XRDP_FREERDP1)
mppc_enc_free((struct rdp_mppc_enc*)(self->mppc_enc));
#endif
2005-06-28 07:11:35 +04:00
g_free(self);
}
/*****************************************************************************/
int APP_CC
xrdp_rdp_init(struct xrdp_rdp* self, struct stream* s)
{
if (xrdp_sec_init(self->sec_layer, s) != 0)
{
return 1;
}
s_push_layer(s, rdp_hdr, 6);
return 0;
}
/*****************************************************************************/
int APP_CC
xrdp_rdp_init_data(struct xrdp_rdp* self, struct stream* s)
{
if (xrdp_sec_init(self->sec_layer, s) != 0)
{
return 1;
}
s_push_layer(s, rdp_hdr, 18);
return 0;
}
/*****************************************************************************/
/* returns erros */
int APP_CC
xrdp_rdp_recv(struct xrdp_rdp* self, struct stream* s, int* code)
{
int error = 0;
int len = 0;
int pdu_code = 0;
int chan = 0;
2005-06-28 07:11:35 +04:00
2006-04-29 05:47:06 +04:00
DEBUG(("in xrdp_rdp_recv"));
2005-06-28 07:11:35 +04:00
if (s->next_packet == 0 || s->next_packet >= s->end)
{
chan = 0;
error = xrdp_sec_recv(self->sec_layer, s, &chan);
if (error == -1) /* special code for send demand active */
{
s->next_packet = 0;
*code = -1;
DEBUG(("out (1) xrdp_rdp_recv"));
2005-06-28 07:11:35 +04:00
return 0;
}
if (error != 0)
{
2006-04-29 05:47:06 +04:00
DEBUG(("out xrdp_rdp_recv error"));
2005-06-28 07:11:35 +04:00
return 1;
}
if ((chan != MCS_GLOBAL_CHANNEL) && (chan > 0))
2005-06-28 07:11:35 +04:00
{
2006-12-28 09:15:13 +03:00
if (chan > MCS_GLOBAL_CHANNEL)
{
if(xrdp_channel_process(self->sec_layer->chan_layer, s, chan)!=0)
{
g_writeln("xrdp_channel_process returned unhandled error") ;
}
2012-06-18 10:48:51 +04:00
}
else
{
g_writeln("Wrong channel Id to be handled by xrdp_channel_process %d",chan);
2006-12-28 09:15:13 +03:00
}
2005-06-28 07:11:35 +04:00
s->next_packet = 0;
*code = 0;
DEBUG(("out (2) xrdp_rdp_recv"));
2005-06-28 07:11:35 +04:00
return 0;
}
s->next_packet = s->p;
}
else
{
DEBUG(("xrdp_rdp_recv stream not touched"))
2005-06-28 07:11:35 +04:00
s->p = s->next_packet;
}
if (!s_check_rem(s, 6))
2005-06-28 07:11:35 +04:00
{
s->next_packet = 0;
2005-06-28 07:11:35 +04:00
*code = 0;
DEBUG(("out (3) xrdp_rdp_recv"));
len = (int)(s->end - s->p);
g_writeln("xrdp_rdp_recv: bad RDP packet, length [%d]", len);
2005-06-28 07:11:35 +04:00
return 0;
}
2012-06-18 10:48:51 +04:00
else
{
in_uint16_le(s, len);
/*g_writeln("New len received : %d next packet: %d s_end: %d",len,s->next_packet,s->end); */
in_uint16_le(s, pdu_code);
*code = pdu_code & 0xf;
in_uint8s(s, 2); /* mcs user id */
s->next_packet += len;
DEBUG(("out (4) xrdp_rdp_recv"));
return 0;
2005-06-28 07:11:35 +04:00
}
}
/*****************************************************************************/
int APP_CC
xrdp_rdp_send(struct xrdp_rdp* self, struct stream* s, int pdu_type)
{
int len = 0;
2005-06-28 07:11:35 +04:00
2006-04-29 05:47:06 +04:00
DEBUG(("in xrdp_rdp_send"));
2005-06-28 07:11:35 +04:00
s_pop_layer(s, rdp_hdr);
len = s->end - s->p;
out_uint16_le(s, len);
out_uint16_le(s, 0x10 | pdu_type);
out_uint16_le(s, self->mcs_channel);
2006-12-28 09:15:13 +03:00
if (xrdp_sec_send(self->sec_layer, s, MCS_GLOBAL_CHANNEL) != 0)
2005-06-28 07:11:35 +04:00
{
2006-04-29 05:47:06 +04:00
DEBUG(("out xrdp_rdp_send error"));
2005-06-28 07:11:35 +04:00
return 1;
}
2006-04-29 05:47:06 +04:00
DEBUG(("out xrdp_rdp_send"));
2005-06-28 07:11:35 +04:00
return 0;
}
/*****************************************************************************/
int APP_CC
xrdp_rdp_send_data(struct xrdp_rdp* self, struct stream* s,
int data_pdu_type)
{
2012-04-06 02:40:46 +04:00
int len;
int ctype;
int clen;
int dlen;
int pdulen;
int pdutype;
int tocomplen;
int iso_offset;
int mcs_offset;
int sec_offset;
int rdp_offset;
struct stream ls;
2012-04-06 22:12:03 +04:00
#if defined(XRDP_FREERDP1)
2012-04-06 02:40:46 +04:00
struct rdp_mppc_enc* mppc_enc;
2012-04-06 22:12:03 +04:00
#endif
2005-06-28 07:11:35 +04:00
2006-04-29 05:47:06 +04:00
DEBUG(("in xrdp_rdp_send_data"));
2005-06-28 07:11:35 +04:00
s_pop_layer(s, rdp_hdr);
2012-04-06 02:40:46 +04:00
len = (int)(s->end - s->p);
pdutype = 0x10 | RDP_PDU_DATA;
pdulen = len;
dlen = len;
ctype = 0;
clen = len;
tocomplen = pdulen - 18;
2012-04-06 22:12:03 +04:00
#if defined(XRDP_FREERDP1)
2012-04-06 02:40:46 +04:00
if (self->client_info.rdp_compression && self->session->up_and_running)
{
mppc_enc = (struct rdp_mppc_enc*)(self->mppc_enc);
2012-06-12 07:29:30 +04:00
if (compress_rdp(mppc_enc, (tui8*)(s->p + 18), tocomplen))
2012-04-06 02:40:46 +04:00
{
DEBUG(("mppc_encode ok flags 0x%x bytes_in_opb %d historyOffset %d "
"tocomplen %d", mppc_enc->flags, mppc_enc->bytes_in_opb,
mppc_enc->historyOffset, tocomplen));
if (mppc_enc->flags & RDP_MPPC_COMPRESSED)
{
clen = mppc_enc->bytes_in_opb + 18;
pdulen = clen;
ctype = mppc_enc->flags;
iso_offset = (int)(s->iso_hdr - s->data);
mcs_offset = (int)(s->mcs_hdr - s->data);
sec_offset = (int)(s->sec_hdr - s->data);
rdp_offset = (int)(s->rdp_hdr - s->data);
/* outputBuffer has 64 bytes preceding it */
ls.data = mppc_enc->outputBuffer - (rdp_offset + 18);
ls.p = ls.data + rdp_offset;
ls.end = ls.p + clen;
ls.size = clen;
ls.iso_hdr = ls.data + iso_offset;
ls.mcs_hdr = ls.data + mcs_offset;
ls.sec_hdr = ls.data + sec_offset;
ls.rdp_hdr = ls.data + rdp_offset;
ls.channel_hdr = 0;
ls.next_packet = 0;
s = &ls;
}
}
else
{
g_writeln("mppc_encode not ok");
}
}
2012-04-06 22:12:03 +04:00
#endif
2012-04-06 02:40:46 +04:00
out_uint16_le(s, pdulen);
out_uint16_le(s, pdutype);
2005-06-28 07:11:35 +04:00
out_uint16_le(s, self->mcs_channel);
out_uint32_le(s, self->share_id);
out_uint8(s, 0);
out_uint8(s, 1);
2012-04-06 02:40:46 +04:00
out_uint16_le(s, dlen);
2005-06-28 07:11:35 +04:00
out_uint8(s, data_pdu_type);
2012-04-06 02:40:46 +04:00
out_uint8(s, ctype);
out_uint16_le(s, clen);
2006-12-28 09:15:13 +03:00
if (xrdp_sec_send(self->sec_layer, s, MCS_GLOBAL_CHANNEL) != 0)
2005-06-28 07:11:35 +04:00
{
2006-04-29 05:47:06 +04:00
DEBUG(("out xrdp_rdp_send_data error"));
2005-06-28 07:11:35 +04:00
return 1;
}
2006-04-29 05:47:06 +04:00
DEBUG(("out xrdp_rdp_send_data"));
2005-06-28 07:11:35 +04:00
return 0;
}
/*****************************************************************************/
int APP_CC
xrdp_rdp_send_data_update_sync(struct xrdp_rdp* self)
{
struct stream * s = (struct stream *)NULL;
make_stream(s);
init_stream(s, 8192);
DEBUG(("in xrdp_rdp_send_data_update_sync"));
if (xrdp_rdp_init_data(self, s) != 0)
{
DEBUG(("out xrdp_rdp_send_data_update_sync error"));
free_stream(s);
return 1;
}
out_uint16_le(s, RDP_UPDATE_SYNCHRONIZE);
out_uint8s(s, 2);
s_mark_end(s);
if (xrdp_rdp_send_data(self, s, RDP_DATA_PDU_UPDATE) != 0)
{
DEBUG(("out xrdp_rdp_send_data_update_sync error"));
free_stream(s);
return 1;
}
DEBUG(("out xrdp_rdp_send_data_update_sync"));
free_stream(s);
return 0;
}
2005-06-28 07:11:35 +04:00
/*****************************************************************************/
static int APP_CC
xrdp_rdp_parse_client_mcs_data(struct xrdp_rdp* self)
{
struct stream* p = (struct stream *)NULL;
int i = 0;
2005-06-28 07:11:35 +04:00
p = &(self->sec_layer->client_mcs_data);
2005-06-28 07:11:35 +04:00
p->p = p->data;
in_uint8s(p, 31);
in_uint16_le(p, self->client_info.width);
in_uint16_le(p, self->client_info.height);
in_uint8s(p, 120);
self->client_info.bpp = 8;
in_uint16_le(p, i);
switch (i)
{
case 0xca01:
in_uint8s(p, 6);
in_uint8(p, i);
if (i > 8)
{
self->client_info.bpp = i;
}
break;
case 0xca02:
self->client_info.bpp = 15;
break;
case 0xca03:
self->client_info.bpp = 16;
break;
case 0xca04:
self->client_info.bpp = 24;
break;
}
2011-08-25 09:45:02 +04:00
if (self->client_info.max_bpp > 0)
{
if (self->client_info.bpp > self->client_info.max_bpp)
{
self->client_info.bpp = self->client_info.max_bpp;
}
}
2005-06-28 07:11:35 +04:00
p->p = p->data;
2006-04-29 05:47:06 +04:00
DEBUG(("client width %d, client height %d bpp %d",
2005-06-28 07:11:35 +04:00
self->client_info.width, self->client_info.height,
self->client_info.bpp));
return 0;
}
/*****************************************************************************/
int APP_CC
xrdp_rdp_incoming(struct xrdp_rdp* self)
{
2006-04-29 05:47:06 +04:00
DEBUG(("in xrdp_rdp_incoming"));
2005-06-28 07:11:35 +04:00
if (xrdp_sec_incoming(self->sec_layer) != 0)
{
return 1;
}
self->mcs_channel = self->sec_layer->mcs_layer->userid +
MCS_USERCHANNEL_BASE;
xrdp_rdp_parse_client_mcs_data(self);
2006-04-29 05:47:06 +04:00
DEBUG(("out xrdp_rdp_incoming mcs channel %d", self->mcs_channel));
2005-06-28 07:11:35 +04:00
return 0;
}
/*****************************************************************************/
int APP_CC
xrdp_rdp_send_demand_active(struct xrdp_rdp* self)
{
struct stream* s;
2008-05-01 10:06:52 +04:00
int caps_count;
int caps_size;
char* caps_count_ptr;
char* caps_size_ptr;
char* caps_ptr;
2005-06-28 07:11:35 +04:00
make_stream(s);
init_stream(s, 8192);
if (xrdp_rdp_init(self, s) != 0)
{
free_stream(s);
return 1;
}
2008-05-01 10:06:52 +04:00
caps_count = 0;
2005-06-28 07:11:35 +04:00
out_uint32_le(s, self->share_id);
out_uint16_le(s, 4); /* 4 chars for RDP\0 */
2008-05-01 10:06:52 +04:00
/* 2 bytes size after num caps, set later */
caps_size_ptr = s->p;
out_uint8s(s, 2);
out_uint8a(s, "RDP", 4);
2008-05-01 10:06:52 +04:00
/* 4 byte num caps, set later */
caps_count_ptr = s->p;
out_uint8s(s, 4);
caps_ptr = s->p;
/* Output share capability set */
2008-05-01 10:06:52 +04:00
caps_count++;
out_uint16_le(s, RDP_CAPSET_SHARE);
out_uint16_le(s, RDP_CAPLEN_SHARE);
2005-06-28 07:11:35 +04:00
out_uint16_le(s, self->mcs_channel);
out_uint16_be(s, 0xb5e2); /* 0x73e1 */
2005-06-28 07:11:35 +04:00
/* Output general capability set */
2008-05-01 10:06:52 +04:00
caps_count++;
2005-06-28 07:11:35 +04:00
out_uint16_le(s, RDP_CAPSET_GENERAL); /* 1 */
out_uint16_le(s, RDP_CAPLEN_GENERAL); /* 24(0x18) */
out_uint16_le(s, 1); /* OS major type */
out_uint16_le(s, 3); /* OS minor type */
out_uint16_le(s, 0x200); /* Protocol version */
out_uint16_le(s, 0); /* pad */
out_uint16_le(s, 0); /* Compression types */
//out_uint16_le(s, 0); /* pad use 0x40d for rdp packets, 0 for not */
out_uint16_le(s, 0x40d); /* pad use 0x40d for rdp packets, 0 for not */
2005-06-28 07:11:35 +04:00
out_uint16_le(s, 0); /* Update capability */
out_uint16_le(s, 0); /* Remote unshare capability */
out_uint16_le(s, 0); /* Compression level */
out_uint16_le(s, 0); /* Pad */
/* Output bitmap capability set */
2008-05-01 10:06:52 +04:00
caps_count++;
2005-06-28 07:11:35 +04:00
out_uint16_le(s, RDP_CAPSET_BITMAP); /* 2 */
out_uint16_le(s, RDP_CAPLEN_BITMAP); /* 28(0x1c) */
out_uint16_le(s, self->client_info.bpp); /* Preferred BPP */
out_uint16_le(s, 1); /* Receive 1 BPP */
out_uint16_le(s, 1); /* Receive 4 BPP */
out_uint16_le(s, 1); /* Receive 8 BPP */
out_uint16_le(s, self->client_info.width); /* width */
out_uint16_le(s, self->client_info.height); /* height */
out_uint16_le(s, 0); /* Pad */
out_uint16_le(s, 1); /* Allow resize */
out_uint16_le(s, 1); /* bitmap compression */
out_uint16_le(s, 0); /* unknown */
out_uint16_le(s, 0); /* unknown */
out_uint16_le(s, 0); /* pad */
2008-05-01 10:06:52 +04:00
/* Output font capability set */
caps_count++;
out_uint16_le(s, RDP_CAPSET_FONT); /* 14 */
out_uint16_le(s, RDP_CAPLEN_FONT); /* 4 */
2005-06-28 07:11:35 +04:00
/* Output order capability set */
2008-05-01 10:06:52 +04:00
caps_count++;
2005-06-28 07:11:35 +04:00
out_uint16_le(s, RDP_CAPSET_ORDER); /* 3 */
out_uint16_le(s, RDP_CAPLEN_ORDER); /* 88(0x58) */
out_uint8s(s, 16);
out_uint32_be(s, 0x40420f00);
out_uint16_le(s, 1); /* Cache X granularity */
out_uint16_le(s, 20); /* Cache Y granularity */
out_uint16_le(s, 0); /* Pad */
out_uint16_le(s, 1); /* Max order level */
out_uint16_le(s, 0x2f); /* Number of fonts */
out_uint16_le(s, 0x22); /* Capability flags */
/* caps */
out_uint8(s, 1); /* dest blt */
out_uint8(s, 1); /* pat blt */
out_uint8(s, 1); /* screen blt */
2008-06-22 01:34:25 +04:00
out_uint8(s, 1); /* mem blt */
out_uint8(s, 0); /* tri blt */
out_uint8(s, 0); /* unused */
out_uint8(s, 0); /* unused */
out_uint8(s, 0); /* nine grid */
out_uint8(s, 1); /* line to */
out_uint8(s, 0); /* multi nine grid */
out_uint8(s, 1); /* rect */
out_uint8(s, 0); /* desk save */
out_uint8(s, 0); /* unused */
out_uint8(s, 0); /* unused */
out_uint8(s, 0); /* unused */
out_uint8(s, 0); /* multi dest blt */
out_uint8(s, 0); /* multi pat blt */
out_uint8(s, 0); /* multi screen blt */
out_uint8(s, 1); /* multi rect */
2008-06-22 01:34:25 +04:00
out_uint8(s, 0); /* fast index */
out_uint8(s, 0); /* polygonSC ([MS-RDPEGDI], 2.2.2.2.1.1.2.16) */
out_uint8(s, 0); /* polygonCB ([MS-RDPEGDI], 2.2.2.2.1.1.2.17) */
2008-06-22 01:34:25 +04:00
out_uint8(s, 0); /* polyline */
out_uint8(s, 0); /* unused */
out_uint8(s, 0); /* fast glyph */
out_uint8(s, 0); /* ellipse */
out_uint8(s, 0); /* ellipse */
out_uint8(s, 0); /* ? */
out_uint8(s, 0); /* unused */
out_uint8(s, 0); /* unused */
out_uint8(s, 0); /* unused */
out_uint8(s, 0); /* unused */
2005-06-28 07:11:35 +04:00
out_uint16_le(s, 0x6a1);
out_uint8s(s, 2); /* ? */
2005-06-28 07:11:35 +04:00
out_uint32_le(s, 0x0f4240); /* desk save */
out_uint32_le(s, 0x0f4240); /* desk save */
out_uint32_le(s, 1); /* ? */
2005-06-28 07:11:35 +04:00
out_uint32_le(s, 0); /* ? */
/* Output color cache capability set */
2008-05-01 10:06:52 +04:00
caps_count++;
2005-06-28 07:11:35 +04:00
out_uint16_le(s, RDP_CAPSET_COLCACHE);
out_uint16_le(s, RDP_CAPLEN_COLCACHE);
out_uint16_le(s, 6); /* cache size */
out_uint16_le(s, 0); /* pad */
/* Output pointer capability set */
2008-05-01 10:06:52 +04:00
caps_count++;
2005-06-28 07:11:35 +04:00
out_uint16_le(s, RDP_CAPSET_POINTER);
out_uint16_le(s, RDP_CAPLEN_POINTER);
out_uint16_le(s, 1); /* Colour pointer */
out_uint16_le(s, 0x19); /* Cache size */
2008-05-01 10:06:52 +04:00
out_uint16_le(s, 0x19); /* Cache size */
2005-06-28 07:11:35 +04:00
2008-05-01 10:06:52 +04:00
/* Output input capability set */
caps_count++;
out_uint16_le(s, RDP_CAPSET_INPUT); /* 13(0xd) */
out_uint16_le(s, RDP_CAPLEN_INPUT); /* 88(0x58) */
2005-06-28 07:11:35 +04:00
out_uint8(s, 1);
out_uint8s(s, 83);
2012-06-15 02:15:00 +04:00
/* Remote Programs Capability Set */
caps_count++;
out_uint16_le(s, 0x0017); /* CAPSETTYPE_RAIL */
out_uint16_le(s, 8);
out_uint32_le(s, 3); /* TS_RAIL_LEVEL_SUPPORTED
TS_RAIL_LEVEL_DOCKED_LANGBAR_SUPPORTED */
/* Window List Capability Set */
caps_count++;
out_uint16_le(s, 0x0018); /* CAPSETTYPE_WINDOW */
out_uint16_le(s, 11);
out_uint32_le(s, 2); /* TS_WINDOW_LEVEL_SUPPORTED_EX */
out_uint8(s, 3); /* NumIconCaches */
out_uint16_le(s, 12); /* NumIconCacheEntries */
2008-05-01 10:06:52 +04:00
out_uint8s(s, 4); /* pad */
2005-06-28 07:11:35 +04:00
s_mark_end(s);
2008-05-01 10:06:52 +04:00
caps_size = (int)(s->end - caps_ptr);
caps_size_ptr[0] = caps_size;
caps_size_ptr[1] = caps_size >> 8;
caps_count_ptr[0] = caps_count;
caps_count_ptr[1] = caps_count >> 8;
caps_count_ptr[2] = caps_count >> 16;
caps_count_ptr[3] = caps_count >> 24;
2005-06-28 07:11:35 +04:00
if (xrdp_rdp_send(self, s, RDP_PDU_DEMAND_ACTIVE) != 0)
{
free_stream(s);
return 1;
}
free_stream(s);
return 0;
}
/*****************************************************************************/
static int APP_CC
xrdp_process_capset_general(struct xrdp_rdp* self, struct stream* s,
int len)
{
int i;
in_uint8s(s, 10);
in_uint16_le(s, i);
2005-08-18 04:23:28 +04:00
/* use_compact_packets is pretty much 'use rdp5' */
2005-06-28 07:11:35 +04:00
self->client_info.use_compact_packets = (i != 0);
2005-08-18 04:23:28 +04:00
/* op2 is a boolean to use compact bitmap headers in bitmap cache */
/* set it to same as 'use rdp5' boolean */
self->client_info.op2 = self->client_info.use_compact_packets;
2005-06-28 07:11:35 +04:00
return 0;
}
/*****************************************************************************/
static int APP_CC
xrdp_process_capset_order(struct xrdp_rdp* self, struct stream* s,
int len)
{
int i;
char order_caps[32];
DEBUG(("order capabilities"));
in_uint8s(s, 20); /* Terminal desc, pad */
in_uint8s(s, 2); /* Cache X granularity */
in_uint8s(s, 2); /* Cache Y granularity */
in_uint8s(s, 2); /* Pad */
in_uint8s(s, 2); /* Max order level */
in_uint8s(s, 2); /* Number of fonts */
in_uint8s(s, 2); /* Capability flags */
in_uint8a(s, order_caps, 32); /* Orders supported */
DEBUG(("dest blt-0 %d", order_caps[0]));
DEBUG(("pat blt-1 %d", order_caps[1]));
DEBUG(("screen blt-2 %d", order_caps[2]));
DEBUG(("memblt-3-13 %d %d", order_caps[3], order_caps[13]));
DEBUG(("triblt-4-14 %d %d", order_caps[4], order_caps[14]));
DEBUG(("line-8 %d", order_caps[8]));
DEBUG(("line-9 %d", order_caps[9]));
DEBUG(("rect-10 %d", order_caps[10]));
DEBUG(("desksave-11 %d", order_caps[11]));
DEBUG(("polygon-20 %d", order_caps[20]));
DEBUG(("polygon2-21 %d", order_caps[21]));
DEBUG(("polyline-22 %d", order_caps[22]));
DEBUG(("ellipse-25 %d", order_caps[25]));
DEBUG(("ellipse2-26 %d", order_caps[26]));
DEBUG(("text2-27 %d", order_caps[27]));
DEBUG(("order_caps dump"));
#if defined(XRDP_DEBUG)
g_hexdump(order_caps, 32);
#endif
in_uint8s(s, 2); /* Text capability flags */
in_uint8s(s, 6); /* Pad */
2005-06-28 07:11:35 +04:00
in_uint32_le(s, i); /* desktop cache size, usually 0x38400 */
self->client_info.desktop_cache = i;
DEBUG(("desktop cache size %d", i));
in_uint8s(s, 4); /* Unknown */
in_uint8s(s, 4); /* Unknown */
2005-06-28 07:11:35 +04:00
return 0;
}
/*****************************************************************************/
/* get the bitmap cache size */
static int APP_CC
xrdp_process_capset_bmpcache(struct xrdp_rdp* self, struct stream* s,
int len)
{
in_uint8s(s, 24);
in_uint16_le(s, self->client_info.cache1_entries);
in_uint16_le(s, self->client_info.cache1_size);
in_uint16_le(s, self->client_info.cache2_entries);
in_uint16_le(s, self->client_info.cache2_size);
in_uint16_le(s, self->client_info.cache3_entries);
in_uint16_le(s, self->client_info.cache3_size);
2006-04-29 05:47:06 +04:00
DEBUG(("cache1 entries %d size %d", self->client_info.cache1_entries,
2006-03-13 03:58:12 +03:00
self->client_info.cache1_size));
2006-04-29 05:47:06 +04:00
DEBUG(("cache2 entries %d size %d", self->client_info.cache2_entries,
2006-03-13 03:58:12 +03:00
self->client_info.cache2_size));
2006-04-29 05:47:06 +04:00
DEBUG(("cache3 entries %d size %d", self->client_info.cache3_entries,
2006-03-13 03:58:12 +03:00
self->client_info.cache3_size));
2005-06-28 07:11:35 +04:00
return 0;
}
2006-03-17 04:10:24 +03:00
/*****************************************************************************/
/* get the bitmap cache size */
static int APP_CC
xrdp_process_capset_bmpcache2(struct xrdp_rdp* self, struct stream* s,
int len)
{
int Bpp = 0;
int i = 0;
2006-03-17 04:10:24 +03:00
self->client_info.bitmap_cache_version = 2;
Bpp = (self->client_info.bpp + 7) / 8;
in_uint16_le(s, i); /* cache flags */
#if defined(XRDP_JPEG)
if (i & 0x80)
{
g_writeln("xrdp_process_capset_bmpcache2: client supports jpeg");
self->client_info.jpeg = 1;
}
#endif
2006-03-17 04:10:24 +03:00
self->client_info.bitmap_cache_persist_enable = i;
in_uint8s(s, 2); /* number of caches in set, 3 */
in_uint32_le(s, i);
i = MIN(i, 2000);
self->client_info.cache1_entries = i;
self->client_info.cache1_size = 256 * Bpp;
in_uint32_le(s, i);
i = MIN(i, 2000);
self->client_info.cache2_entries = i;
self->client_info.cache2_size = 1024 * Bpp;
in_uint32_le(s, i);
i = i & 0x7fffffff;
i = MIN(i, 2000);
self->client_info.cache3_entries = i;
self->client_info.cache3_size = 4096 * Bpp;
2006-04-29 05:47:06 +04:00
DEBUG(("cache1 entries %d size %d", self->client_info.cache1_entries,
2006-03-17 04:10:24 +03:00
self->client_info.cache1_size));
2006-04-29 05:47:06 +04:00
DEBUG(("cache2 entries %d size %d", self->client_info.cache2_entries,
2006-03-17 04:10:24 +03:00
self->client_info.cache2_size));
2006-04-29 05:47:06 +04:00
DEBUG(("cache3 entries %d size %d", self->client_info.cache3_entries,
2006-03-17 04:10:24 +03:00
self->client_info.cache3_size));
return 0;
}
2005-06-28 07:11:35 +04:00
/*****************************************************************************/
/* get the number of client cursor cache */
static int APP_CC
xrdp_process_capset_pointercache(struct xrdp_rdp* self, struct stream* s,
int len)
{
int i;
in_uint8s(s, 2); /* color pointer */
in_uint16_le(s, i);
i = MIN(i, 32);
self->client_info.pointer_cache_entries = i;
return 0;
}
/*****************************************************************************/
/* get the type of client brush cache */
static int APP_CC
xrdp_process_capset_brushcache(struct xrdp_rdp* self, struct stream* s,
int len)
{
int code;
in_uint32_le(s, code);
self->client_info.brush_cache_code = code;
return 0;
}
/*****************************************************************************/
static int APP_CC
xrdp_process_offscreen_bmpcache(struct xrdp_rdp* self, struct stream* s,
int len)
{
int i32;
if (len - 4 < 8)
{
g_writeln("xrdp_process_offscreen_bmpcache: bad len");
return 1;
}
in_uint32_le(s, i32);
self->client_info.offscreen_support_level = i32;
in_uint16_le(s, i32);
self->client_info.offscreen_cache_size = i32 * 1024;
in_uint16_le(s, i32);
self->client_info.offscreen_cache_entries = i32;
g_writeln("xrdp_process_offscreen_bmpcache: support level %d "
"cache size %d MB cache entries %d",
self->client_info.offscreen_support_level,
self->client_info.offscreen_cache_size,
self->client_info.offscreen_cache_entries);
return 0;
}
2012-06-15 02:15:00 +04:00
/*****************************************************************************/
static int APP_CC
xrdp_process_capset_rail(struct xrdp_rdp* self, struct stream* s, int len)
{
int i32;
if (len - 4 < 4)
{
g_writeln("xrdp_process_capset_rail: bad len");
return 1;
}
in_uint32_le(s, i32);
self->client_info.rail_support_level = i32;
g_writeln("xrdp_process_capset_rail: rail_support_level %d",
self->client_info.rail_support_level);
return 0;
}
/*****************************************************************************/
static int APP_CC
xrdp_process_capset_window(struct xrdp_rdp* self, struct stream* s, int len)
{
int i32;
if (len - 4 < 7)
{
g_writeln("xrdp_process_capset_window: bad len");
return 1;
}
in_uint32_le(s, i32);
self->client_info.wnd_support_level = i32;
in_uint8(s, i32);
self->client_info.wnd_num_icon_caches = i32;
in_uint16_le(s, i32);
self->client_info.wnd_num_icon_cache_entries = i32;
g_writeln("xrdp_process_capset_window wnd_support_level %d "
"wnd_num_icon_caches %d wnd_num_icon_cache_entries %d",
self->client_info.wnd_support_level,
self->client_info.wnd_num_icon_caches,
self->client_info.wnd_num_icon_cache_entries);
return 0;
}
2005-06-28 07:11:35 +04:00
/*****************************************************************************/
int APP_CC
xrdp_rdp_process_confirm_active(struct xrdp_rdp* self, struct stream* s)
{
int cap_len;
int source_len;
int num_caps;
int index;
int type;
int len;
char* p;
2006-04-29 05:47:06 +04:00
DEBUG(("in xrdp_rdp_process_confirm_active"));
2005-06-28 07:11:35 +04:00
in_uint8s(s, 4); /* rdp_shareid */
in_uint8s(s, 2); /* userid */
in_uint16_le(s, source_len); /* sizeof RDP_SOURCE */
in_uint16_le(s, cap_len);
in_uint8s(s, source_len);
in_uint16_le(s, num_caps);
in_uint8s(s, 2); /* pad */
for (index = 0; index < num_caps; index++)
{
p = s->p;
in_uint16_le(s, type);
in_uint16_le(s, len);
switch (type)
{
case RDP_CAPSET_GENERAL: /* 1 */
2006-04-29 05:47:06 +04:00
DEBUG(("RDP_CAPSET_GENERAL"));
2005-06-28 07:11:35 +04:00
xrdp_process_capset_general(self, s, len);
break;
2006-03-13 03:58:12 +03:00
case RDP_CAPSET_BITMAP: /* 2 */
2006-04-29 05:47:06 +04:00
DEBUG(("RDP_CAPSET_BITMAP"));
2006-03-13 03:58:12 +03:00
break;
2005-06-28 07:11:35 +04:00
case RDP_CAPSET_ORDER: /* 3 */
2006-04-29 05:47:06 +04:00
DEBUG(("RDP_CAPSET_ORDER"));
2005-06-28 07:11:35 +04:00
xrdp_process_capset_order(self, s, len);
break;
case RDP_CAPSET_BMPCACHE: /* 4 */
2006-04-29 05:47:06 +04:00
DEBUG(("RDP_CAPSET_BMPCACHE"));
2005-06-28 07:11:35 +04:00
xrdp_process_capset_bmpcache(self, s, len);
break;
2006-03-13 03:58:12 +03:00
case RDP_CAPSET_CONTROL: /* 5 */
2006-04-29 05:47:06 +04:00
DEBUG(("RDP_CAPSET_CONTROL"));
2006-03-13 03:58:12 +03:00
break;
case RDP_CAPSET_ACTIVATE: /* 7 */
2006-04-29 05:47:06 +04:00
DEBUG(("RDP_CAPSET_ACTIVATE"));
2006-03-13 03:58:12 +03:00
break;
2005-06-28 07:11:35 +04:00
case RDP_CAPSET_POINTER: /* 8 */
2006-04-29 05:47:06 +04:00
DEBUG(("RDP_CAPSET_POINTER"));
2005-06-28 07:11:35 +04:00
xrdp_process_capset_pointercache(self, s, len);
break;
2006-03-13 03:58:12 +03:00
case RDP_CAPSET_SHARE: /* 9 */
2006-04-29 05:47:06 +04:00
DEBUG(("RDP_CAPSET_SHARE"));
2006-03-13 03:58:12 +03:00
break;
case RDP_CAPSET_COLCACHE: /* 10 */
2006-04-29 05:47:06 +04:00
DEBUG(("RDP_CAPSET_COLCACHE"));
2006-03-13 03:58:12 +03:00
break;
case 12: /* 12 */
2006-04-29 05:47:06 +04:00
DEBUG(("--12"));
2006-03-13 03:58:12 +03:00
break;
case 13: /* 13 */
2006-04-29 05:47:06 +04:00
DEBUG(("--13"));
2006-03-13 03:58:12 +03:00
break;
case 14: /* 14 */
2006-04-29 05:47:06 +04:00
DEBUG(("--14"));
2006-03-13 03:58:12 +03:00
break;
case RDP_CAPSET_BRUSHCACHE: /* 15 */
xrdp_process_capset_brushcache(self, s, len);
2006-03-13 03:58:12 +03:00
break;
case 16: /* 16 */
2006-04-29 05:47:06 +04:00
DEBUG(("--16"));
2006-03-13 03:58:12 +03:00
break;
case 17: /* 17 */
DEBUG(("CAPSET_TYPE_OFFSCREEN_CACHE"));
xrdp_process_offscreen_bmpcache(self, s, len);
2006-03-13 03:58:12 +03:00
break;
case RDP_CAPSET_BMPCACHE2: /* 19 */
2006-04-29 05:47:06 +04:00
DEBUG(("RDP_CAPSET_BMPCACHE2"));
2006-03-17 04:10:24 +03:00
xrdp_process_capset_bmpcache2(self, s, len);
2006-03-13 03:58:12 +03:00
break;
case 20: /* 20 */
2006-04-29 05:47:06 +04:00
DEBUG(("--20"));
2006-03-13 03:58:12 +03:00
break;
case 21: /* 21 */
2006-04-29 05:47:06 +04:00
DEBUG(("--21"));
2006-03-13 03:58:12 +03:00
break;
case 22: /* 22 */
DEBUG(("--22"));
break;
2012-06-15 02:15:00 +04:00
case 0x0017: /* 23 CAPSETTYPE_RAIL */
xrdp_process_capset_rail(self, s, len);
break;
case 0x0018: /* 24 CAPSETTYPE_WINDOW */
xrdp_process_capset_window(self, s, len);
break;
case 26: /* 26 */
DEBUG(("--26"));
break;
2006-03-13 03:58:12 +03:00
default:
2006-04-29 05:47:06 +04:00
g_writeln("unknown in xrdp_rdp_process_confirm_active %d", type);
2006-03-13 03:58:12 +03:00
break;
2005-06-28 07:11:35 +04:00
}
s->p = p + len;
}
2006-04-29 05:47:06 +04:00
DEBUG(("out xrdp_rdp_process_confirm_active"));
2005-06-28 07:11:35 +04:00
return 0;
}
/*****************************************************************************/
static int APP_CC
xrdp_rdp_process_data_pointer(struct xrdp_rdp* self, struct stream* s)
{
return 0;
}
/*****************************************************************************/
/* RDP_DATA_PDU_INPUT */
static int APP_CC
xrdp_rdp_process_data_input(struct xrdp_rdp* self, struct stream* s)
{
int num_events;
int index;
int msg_type;
int device_flags;
int param1;
int param2;
int time;
in_uint16_le(s, num_events);
in_uint8s(s, 2); /* pad */
2006-04-29 05:47:06 +04:00
DEBUG(("in xrdp_rdp_process_data_input %d events", num_events));
2005-06-28 07:11:35 +04:00
for (index = 0; index < num_events; index++)
{
in_uint32_le(s, time);
in_uint16_le(s, msg_type);
in_uint16_le(s, device_flags);
in_sint16_le(s, param1);
in_sint16_le(s, param2);
DEBUG(("xrdp_rdp_process_data_input event %4.4x flags %4.4x param1 %d \
2006-04-29 05:47:06 +04:00
param2 %d time %d", msg_type, device_flags, param1, param2, time));
2005-06-28 07:11:35 +04:00
if (self->session->callback != 0)
{
/* msg_type can be
RDP_INPUT_SYNCHRONIZE - 0
RDP_INPUT_SCANCODE - 4
RDP_INPUT_MOUSE - 0x8001 */
2006-03-13 03:58:12 +03:00
/* call to xrdp_wm.c : callback */
2005-06-28 07:11:35 +04:00
self->session->callback(self->session->id, msg_type, param1, param2,
device_flags, time);
}
}
2006-04-29 05:47:06 +04:00
DEBUG(("out xrdp_rdp_process_data_input"));
2005-06-28 07:11:35 +04:00
return 0;
}
/*****************************************************************************/
static int APP_CC
xrdp_rdp_send_synchronise(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_uint16_le(s, 1);
out_uint16_le(s, 1002);
s_mark_end(s);
if (xrdp_rdp_send_data(self, s, RDP_DATA_PDU_SYNCHRONISE) != 0)
{
free_stream(s);
return 1;
}
free_stream(s);
return 0;
}
/*****************************************************************************/
static int APP_CC
xrdp_rdp_send_control(struct xrdp_rdp* self, int action)
{
struct stream* s;
make_stream(s);
init_stream(s, 8192);
if (xrdp_rdp_init_data(self, s) != 0)
{
free_stream(s);
return 1;
}
out_uint16_le(s, action);
out_uint16_le(s, 0); /* userid */
out_uint32_le(s, 1002); /* control id */
s_mark_end(s);
if (xrdp_rdp_send_data(self, s, RDP_DATA_PDU_CONTROL) != 0)
{
free_stream(s);
return 1;
}
free_stream(s);
return 0;
}
/*****************************************************************************/
static int APP_CC
xrdp_rdp_process_data_control(struct xrdp_rdp* self, struct stream* s)
{
int action;
DEBUG(("xrdp_rdp_process_data_control"));
2005-06-28 07:11:35 +04:00
in_uint16_le(s, action);
in_uint8s(s, 2); /* user id */
in_uint8s(s, 4); /* control id */
if (action == RDP_CTL_REQUEST_CONTROL)
{
DEBUG(("xrdp_rdp_process_data_control got RDP_CTL_REQUEST_CONTROL"));
DEBUG(("xrdp_rdp_process_data_control calling xrdp_rdp_send_synchronise"));
2005-06-28 07:11:35 +04:00
xrdp_rdp_send_synchronise(self);
DEBUG(("xrdp_rdp_process_data_control sending RDP_CTL_COOPERATE"));
2005-06-28 07:11:35 +04:00
xrdp_rdp_send_control(self, RDP_CTL_COOPERATE);
DEBUG(("xrdp_rdp_process_data_control sending RDP_CTL_GRANT_CONTROL"));
2005-06-28 07:11:35 +04:00
xrdp_rdp_send_control(self, RDP_CTL_GRANT_CONTROL);
}
else
{
DEBUG(("xrdp_rdp_process_data_control unknown action"));
}
2005-06-28 07:11:35 +04:00
return 0;
}
/*****************************************************************************/
static int APP_CC
xrdp_rdp_process_data_sync(struct xrdp_rdp* self)
{
DEBUG(("xrdp_rdp_process_data_sync"));
2005-06-28 07:11:35 +04:00
return 0;
}
/*****************************************************************************/
static int APP_CC
xrdp_rdp_process_screen_update(struct xrdp_rdp* self, struct stream* s)
{
int op;
int left;
int top;
int right;
int bottom;
int cx;
int cy;
in_uint32_le(s, op);
in_uint16_le(s, left);
in_uint16_le(s, top);
in_uint16_le(s, right);
in_uint16_le(s, bottom);
cx = (right - left) + 1;
cy = (bottom - top) + 1;
if (self->session->callback != 0)
{
self->session->callback(self->session->id, 0x4444, left, top, cx, cy);
}
return 0;
}
/*****************************************************************************/
static int APP_CC
xrdp_rdp_send_unknown1(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_unknown1, 172);
2005-06-28 07:11:35 +04:00
s_mark_end(s);
if (xrdp_rdp_send_data(self, s, 0x28) != 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)
{
int seq;
2007-01-20 08:19:57 +03:00
DEBUG(("in xrdp_rdp_process_data_font"));
2005-06-28 07:11:35 +04:00
in_uint8s(s, 2); /* num of fonts */
in_uint8s(s, 2); /* unknown */
in_uint16_le(s, seq);
/* 419 client sends Seq 1, then 2 */
/* 2600 clients sends only Seq 3 */
if (seq == 2 || seq == 3) /* after second font message, we are up and */
{ /* running */
DEBUG(("sending unknown1"));
2005-06-28 07:11:35 +04:00
xrdp_rdp_send_unknown1(self);
self->session->up_and_running = 1;
2007-01-20 08:19:57 +03:00
DEBUG(("up_and_running set"));
xrdp_rdp_send_data_update_sync(self);
2005-06-28 07:11:35 +04:00
}
2007-01-20 08:19:57 +03:00
DEBUG(("out xrdp_rdp_process_data_font"));
2005-06-28 07:11:35 +04:00
return 0;
}
/*****************************************************************************/
/* sent 37 pdu */
static int APP_CC
xrdp_rdp_send_disconnect_query_response(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;
}
s_mark_end(s);
if (xrdp_rdp_send_data(self, s, 37) != 0)
{
free_stream(s);
return 1;
}
free_stream(s);
return 0;
}
#if 0 /* not used */
/*****************************************************************************/
/* sent RDP_DATA_PDU_DISCONNECT 47 pdu */
static int APP_CC
xrdp_rdp_send_disconnect_reason(struct xrdp_rdp* self, int reason)
{
struct stream* s;
make_stream(s);
init_stream(s, 8192);
if (xrdp_rdp_init_data(self, s) != 0)
{
free_stream(s);
return 1;
}
out_uint32_le(s, reason);
s_mark_end(s);
if (xrdp_rdp_send_data(self, s, RDP_DATA_PDU_DISCONNECT) != 0)
{
free_stream(s);
return 1;
}
free_stream(s);
return 0;
}
#endif
/*****************************************************************************/
/* RDP_PDU_DATA */
int APP_CC
xrdp_rdp_process_data(struct xrdp_rdp* self, struct stream* s)
{
int len;
int data_type;
int ctype;
int clen;
in_uint8s(s, 6);
in_uint16_le(s, len);
in_uint8(s, data_type);
in_uint8(s, ctype);
in_uint16_le(s, clen);
2006-04-29 05:47:06 +04:00
DEBUG(("xrdp_rdp_process_data code %d", data_type));
2005-06-28 07:11:35 +04:00
switch (data_type)
{
case RDP_DATA_PDU_POINTER: /* 27(0x1b) */
2005-06-28 07:11:35 +04:00
xrdp_rdp_process_data_pointer(self, s);
break;
case RDP_DATA_PDU_INPUT: /* 28(0x1c) */
2005-06-28 07:11:35 +04:00
xrdp_rdp_process_data_input(self, s);
break;
case RDP_DATA_PDU_CONTROL: /* 20(0x14) */
2005-06-28 07:11:35 +04:00
xrdp_rdp_process_data_control(self, s);
break;
case RDP_DATA_PDU_SYNCHRONISE: /* 31(0x1f) */
2005-06-28 07:11:35 +04:00
xrdp_rdp_process_data_sync(self);
break;
case 33: /* 33(0x21) ?? Invalidate an area I think */
2005-06-28 07:11:35 +04:00
xrdp_rdp_process_screen_update(self, s);
break;
case 35: /* 35(0x23) */
2005-06-28 07:11:35 +04:00
/* 35 ?? this comes when minimuzing a full screen mstsc.exe 2600 */
/* I think this is saying the client no longer wants screen */
/* updates and it will issue a 33 above to catch up */
/* so minimized apps don't take bandwidth */
break;
case 36: /* 36(0x24) ?? disconnect query? */
2005-06-28 07:11:35 +04:00
/* when this message comes, send a 37 back so the client */
/* is sure the connection is alive and it can ask if user */
/* really wants to disconnect */
xrdp_rdp_send_disconnect_query_response(self); /* send a 37 back */
break;
case RDP_DATA_PDU_FONT2: /* 39(0x27) */
2005-06-28 07:11:35 +04:00
xrdp_rdp_process_data_font(self, s);
break;
default:
2006-04-29 05:47:06 +04:00
g_writeln("unknown in xrdp_rdp_process_data %d", data_type);
2005-06-28 07:11:35 +04:00
break;
}
return 0;
}
/*****************************************************************************/
int APP_CC
xrdp_rdp_disconnect(struct xrdp_rdp* self)
{
2007-01-15 12:08:03 +03:00
int rv;
DEBUG(("in xrdp_rdp_disconnect"));
rv = xrdp_sec_disconnect(self->sec_layer);
DEBUG(("out xrdp_rdp_disconnect"));
return rv;
2005-06-28 07:11:35 +04:00
}
/*****************************************************************************/
int APP_CC
xrdp_rdp_send_deactive(struct xrdp_rdp* self)
{
struct stream* s;
2007-01-15 12:08:03 +03:00
DEBUG(("in xrdp_rdp_send_deactive"));
make_stream(s);
init_stream(s, 8192);
if (xrdp_rdp_init(self, s) != 0)
{
free_stream(s);
2007-01-15 12:08:03 +03:00
DEBUG(("out xrdp_rdp_send_deactive error"));
return 1;
}
s_mark_end(s);
if (xrdp_rdp_send(self, s, RDP_PDU_DEACTIVATE) != 0)
{
free_stream(s);
2007-01-15 12:08:03 +03:00
DEBUG(("out xrdp_rdp_send_deactive error"));
return 1;
}
free_stream(s);
2007-01-15 12:08:03 +03:00
DEBUG(("out xrdp_rdp_send_deactive"));
return 0;
}