1 |
/* |
/* |
2 |
rdesktop: A Remote Desktop Protocol client. |
rdesktop: A Remote Desktop Protocol client. |
3 |
Protocol services - RDP layer |
Protocol services - RDP layer |
4 |
Copyright (C) Matthew Chapman 1999-2001 |
Copyright (C) Matthew Chapman 1999-2002 |
5 |
|
|
6 |
This program is free software; you can redistribute it and/or modify |
This program is free software; you can redistribute it and/or modify |
7 |
it under the terms of the GNU General Public License as published by |
it under the terms of the GNU General Public License as published by |
30 |
uint8 *next_packet; |
uint8 *next_packet; |
31 |
uint32 rdp_shareid; |
uint32 rdp_shareid; |
32 |
|
|
33 |
|
#if WITH_DEBUG |
34 |
|
static uint32 packetno; |
35 |
|
#endif |
36 |
|
|
37 |
/* Initialise an RDP packet */ |
/* Initialise an RDP packet */ |
38 |
static STREAM |
static STREAM |
39 |
rdp_init(int maxlen) |
rdp_init(int maxlen) |
83 |
} |
} |
84 |
|
|
85 |
in_uint16_le(rdp_s, length); |
in_uint16_le(rdp_s, length); |
86 |
|
/* 32k packets are really 8, keepalive fix */ |
87 |
|
if (length == 0x8000) |
88 |
|
{ |
89 |
|
next_packet += 8; |
90 |
|
*type = 0; |
91 |
|
return rdp_s; |
92 |
|
} |
93 |
in_uint16_le(rdp_s, pdu_type); |
in_uint16_le(rdp_s, pdu_type); |
94 |
in_uint8s(rdp_s, 2); /* userid */ |
in_uint8s(rdp_s, 2); /* userid */ |
95 |
*type = pdu_type & 0xf; |
*type = pdu_type & 0xf; |
96 |
|
|
97 |
#if WITH_DEBUG |
#if WITH_DEBUG |
98 |
DEBUG(("RDP packet (type %x):\n", *type)); |
DEBUG(("RDP packet #%d, (type %x):\n", ++packetno, *type)); |
99 |
hexdump(next_packet, length); |
hexdump(next_packet, length); |
100 |
#endif /* */ |
#endif /* */ |
101 |
|
|
131 |
out_uint32_le(s, rdp_shareid); |
out_uint32_le(s, rdp_shareid); |
132 |
out_uint8(s, 0); /* pad */ |
out_uint8(s, 0); /* pad */ |
133 |
out_uint8(s, 1); /* streamid */ |
out_uint8(s, 1); /* streamid */ |
134 |
out_uint16(s, (length - 14)); |
out_uint16_le(s, (length - 14)); |
135 |
out_uint8(s, data_pdu_type); |
out_uint8(s, data_pdu_type); |
136 |
out_uint8(s, 0); /* compress_type */ |
out_uint8(s, 0); /* compress_type */ |
137 |
out_uint16(s, 0); /* compress_len */ |
out_uint16(s, 0); /* compress_len */ |
166 |
int len_password = 2 * strlen(password); |
int len_password = 2 * strlen(password); |
167 |
int len_program = 2 * strlen(program); |
int len_program = 2 * strlen(program); |
168 |
int len_directory = 2 * strlen(directory); |
int len_directory = 2 * strlen(directory); |
169 |
uint32 sec_flags = encryption ? (SEC_LOGON_INFO | SEC_ENCRYPT) |
uint32 sec_flags = encryption ? (SEC_LOGON_INFO | SEC_ENCRYPT) : SEC_LOGON_INFO; |
|
: SEC_LOGON_INFO; |
|
170 |
STREAM s; |
STREAM s; |
171 |
|
|
172 |
s = sec_init(sec_flags, 18 + len_domain + len_user + len_password |
s = sec_init(sec_flags, 18 + len_domain + len_user + len_password |
207 |
|
|
208 |
/* Send a synchronisation PDU */ |
/* Send a synchronisation PDU */ |
209 |
static void |
static void |
210 |
rdp_send_synchronise() |
rdp_send_synchronise(void) |
211 |
{ |
{ |
212 |
STREAM s; |
STREAM s; |
213 |
|
|
222 |
|
|
223 |
/* Send a single input event */ |
/* Send a single input event */ |
224 |
void |
void |
225 |
rdp_send_input(uint32 time, uint16 message_type, uint16 device_flags, |
rdp_send_input(uint32 time, uint16 message_type, uint16 device_flags, uint16 param1, uint16 param2) |
|
uint16 param1, uint16 param2) |
|
226 |
{ |
{ |
227 |
STREAM s; |
STREAM s; |
228 |
|
|
285 |
out_uint16_le(s, RDP_CAPLEN_BITMAP); |
out_uint16_le(s, RDP_CAPLEN_BITMAP); |
286 |
|
|
287 |
out_uint16_le(s, 8); /* Preferred BPP */ |
out_uint16_le(s, 8); /* Preferred BPP */ |
288 |
out_uint16(s, 1); /* Receive 1 BPP */ |
out_uint16_le(s, 1); /* Receive 1 BPP */ |
289 |
out_uint16(s, 1); /* Receive 4 BPP */ |
out_uint16_le(s, 1); /* Receive 4 BPP */ |
290 |
out_uint16_le(s, 1); /* Receive 8 BPP */ |
out_uint16_le(s, 1); /* Receive 8 BPP */ |
291 |
out_uint16_le(s, 800); /* Desktop width */ |
out_uint16_le(s, 800); /* Desktop width */ |
292 |
out_uint16_le(s, 600); /* Desktop height */ |
out_uint16_le(s, 600); /* Desktop height */ |
309 |
order_caps[0] = 1; /* dest blt */ |
order_caps[0] = 1; /* dest blt */ |
310 |
order_caps[1] = 1; /* pat blt */ |
order_caps[1] = 1; /* pat blt */ |
311 |
order_caps[2] = 1; /* screen blt */ |
order_caps[2] = 1; /* screen blt */ |
312 |
|
order_caps[3] = 1; /* required for memblt? */ |
313 |
order_caps[8] = 1; /* line */ |
order_caps[8] = 1; /* line */ |
314 |
order_caps[9] = 1; /* line */ |
order_caps[9] = 1; /* line */ |
315 |
order_caps[10] = 1; /* rect */ |
order_caps[10] = 1; /* rect */ |
331 |
out_uint8p(s, order_caps, 32); /* Orders supported */ |
out_uint8p(s, order_caps, 32); /* Orders supported */ |
332 |
out_uint16_le(s, 0x6a1); /* Text capability flags */ |
out_uint16_le(s, 0x6a1); /* Text capability flags */ |
333 |
out_uint8s(s, 6); /* Pad */ |
out_uint8s(s, 6); /* Pad */ |
334 |
out_uint32(s, desktop_save == False ? 0 : 0x38400); /* Desktop cache size */ |
out_uint32_le(s, desktop_save == False ? 0 : 0x38400); /* Desktop cache size */ |
335 |
out_uint32(s, 0); /* Unknown */ |
out_uint32(s, 0); /* Unknown */ |
336 |
out_uint32(s, 0x4e4); /* Unknown */ |
out_uint32_le(s, 0x4e4); /* Unknown */ |
337 |
} |
} |
338 |
|
|
339 |
/* Output bitmap cache capability set */ |
/* Output bitmap cache capability set */ |
445 |
|
|
446 |
/* Send a confirm active PDU */ |
/* Send a confirm active PDU */ |
447 |
static void |
static void |
448 |
rdp_send_confirm_active() |
rdp_send_confirm_active(void) |
449 |
{ |
{ |
450 |
STREAM s; |
STREAM s; |
451 |
uint16 caplen = |
uint16 caplen = |
452 |
RDP_CAPLEN_GENERAL + RDP_CAPLEN_BITMAP + RDP_CAPLEN_ORDER + |
RDP_CAPLEN_GENERAL + RDP_CAPLEN_BITMAP + RDP_CAPLEN_ORDER + |
453 |
RDP_CAPLEN_BMPCACHE + RDP_CAPLEN_COLCACHE + |
RDP_CAPLEN_BMPCACHE + RDP_CAPLEN_COLCACHE + |
454 |
RDP_CAPLEN_ACTIVATE + RDP_CAPLEN_CONTROL + |
RDP_CAPLEN_ACTIVATE + RDP_CAPLEN_CONTROL + |
455 |
RDP_CAPLEN_POINTER + RDP_CAPLEN_SHARE + RDP_CAPLEN_UNKNOWN |
RDP_CAPLEN_POINTER + RDP_CAPLEN_SHARE + RDP_CAPLEN_UNKNOWN + 4 /* w2k fix, why? */ ; |
|
+ 4 /* w2k fix, why? */ ; |
|
456 |
|
|
457 |
s = rdp_init(14 + caplen + sizeof(RDP_SOURCE)); |
s = rdp_init(14 + caplen + sizeof(RDP_SOURCE)); |
458 |
|
|
535 |
in_uint16_le(s, datalen); |
in_uint16_le(s, datalen); |
536 |
in_uint8p(s, data, datalen); |
in_uint8p(s, data, datalen); |
537 |
in_uint8p(s, mask, masklen); |
in_uint8p(s, mask, masklen); |
538 |
cursor = ui_create_cursor(x, y, width, height, mask, |
cursor = ui_create_cursor(x, y, width, height, mask, data); |
|
data); |
|
539 |
ui_set_cursor(cursor); |
ui_set_cursor(cursor); |
540 |
cache_put_cursor(cache_idx, cursor); |
cache_put_cursor(cache_idx, cursor); |
541 |
break; |
break; |
556 |
{ |
{ |
557 |
uint16 num_updates; |
uint16 num_updates; |
558 |
uint16 left, top, right, bottom, width, height; |
uint16 left, top, right, bottom, width, height; |
559 |
uint16 cx, cy, bpp, compress, bufsize, size; |
uint16 cx, cy, bpp, Bpp, compress, bufsize, size; |
560 |
uint8 *data, *bmpdata; |
uint8 *data, *bmpdata; |
561 |
int i; |
int i; |
562 |
|
|
571 |
in_uint16_le(s, width); |
in_uint16_le(s, width); |
572 |
in_uint16_le(s, height); |
in_uint16_le(s, height); |
573 |
in_uint16_le(s, bpp); |
in_uint16_le(s, bpp); |
574 |
|
Bpp = (bpp + 7) / 8; |
575 |
in_uint16_le(s, compress); |
in_uint16_le(s, compress); |
576 |
in_uint16_le(s, bufsize); |
in_uint16_le(s, bufsize); |
577 |
|
|
584 |
if (!compress) |
if (!compress) |
585 |
{ |
{ |
586 |
int y; |
int y; |
587 |
bmpdata = xmalloc(width * height); |
bmpdata = xmalloc(width * height * Bpp); |
588 |
for (y = 0; y < height; y++) |
for (y = 0; y < height; y++) |
589 |
{ |
{ |
590 |
in_uint8a(s, |
in_uint8a(s, &bmpdata[(height - y - 1) * (width * Bpp)], |
591 |
&bmpdata[(height - y - 1) * width], |
width * Bpp); |
|
width); |
|
592 |
} |
} |
593 |
ui_paint_bitmap(left, top, cx, cy, width, height, |
ui_paint_bitmap(left, top, cx, cy, width, height, bmpdata); |
|
bmpdata); |
|
594 |
xfree(bmpdata); |
xfree(bmpdata); |
595 |
continue; |
continue; |
596 |
} |
} |
599 |
in_uint16_le(s, size); |
in_uint16_le(s, size); |
600 |
in_uint8s(s, 4); /* line_size, final_size */ |
in_uint8s(s, 4); /* line_size, final_size */ |
601 |
in_uint8p(s, data, size); |
in_uint8p(s, data, size); |
602 |
|
bmpdata = xmalloc(width * height * Bpp); |
603 |
bmpdata = xmalloc(width * height); |
if (bitmap_decompress(bmpdata, width, height, data, size, Bpp)) |
|
if (bitmap_decompress(bmpdata, width, height, data, size)) |
|
604 |
{ |
{ |
605 |
ui_paint_bitmap(left, top, cx, cy, width, height, |
ui_paint_bitmap(left, top, cx, cy, width, height, bmpdata); |
|
bmpdata); |
|
606 |
} |
} |
|
|
|
607 |
xfree(bmpdata); |
xfree(bmpdata); |
608 |
} |
} |
609 |
} |
} |
612 |
static void |
static void |
613 |
process_palette(STREAM s) |
process_palette(STREAM s) |
614 |
{ |
{ |
615 |
HCOLOURMAP hmap; |
COLOURENTRY *entry; |
616 |
COLOURMAP map; |
COLOURMAP map; |
617 |
uint8 *colours; |
HCOLOURMAP hmap; |
618 |
|
int i; |
619 |
|
|
620 |
in_uint8s(s, 2); /* pad */ |
in_uint8s(s, 2); /* pad */ |
621 |
in_uint16_le(s, map.ncolours); |
in_uint16_le(s, map.ncolours); |
622 |
in_uint8s(s, 2); /* pad */ |
in_uint8s(s, 2); /* pad */ |
623 |
in_uint8p(s, colours, (map.ncolours * 3)); |
|
624 |
map.colours = (COLOURENTRY *) colours; |
map.colours = xmalloc(3 * map.ncolours); |
625 |
|
|
626 |
|
for (i = 0; i < map.ncolours; i++) |
627 |
|
{ |
628 |
|
entry = &map.colours[i]; |
629 |
|
in_uint8(s, entry->red); |
630 |
|
in_uint8(s, entry->green); |
631 |
|
in_uint8(s, entry->blue); |
632 |
|
} |
633 |
|
|
634 |
hmap = ui_create_colourmap(&map); |
hmap = ui_create_colourmap(&map); |
635 |
ui_set_colourmap(hmap); |
ui_set_colourmap(hmap); |
636 |
|
|
637 |
|
xfree(map.colours); |
638 |
} |
} |
639 |
|
|
640 |
/* Process an update PDU */ |
/* Process an update PDU */ |
703 |
|
|
704 |
/* Process incoming packets */ |
/* Process incoming packets */ |
705 |
void |
void |
706 |
rdp_main_loop() |
rdp_main_loop(void) |
707 |
{ |
{ |
708 |
uint8 type; |
uint8 type; |
709 |
STREAM s; |
STREAM s; |
723 |
process_data_pdu(s); |
process_data_pdu(s); |
724 |
break; |
break; |
725 |
|
|
726 |
|
case 0: |
727 |
|
break; |
728 |
|
|
729 |
default: |
default: |
730 |
unimpl("PDU %d\n", type); |
unimpl("PDU %d\n", type); |
731 |
} |
} |
740 |
if (!sec_connect(server)) |
if (!sec_connect(server)) |
741 |
return False; |
return False; |
742 |
|
|
743 |
rdp_send_logon_info(flags, domain, username, password, |
rdp_send_logon_info(flags, domain, username, password, command, directory); |
|
command, directory); |
|
744 |
return True; |
return True; |
745 |
} |
} |
746 |
|
|
747 |
/* Disconnect from the RDP layer */ |
/* Disconnect from the RDP layer */ |
748 |
void |
void |
749 |
rdp_disconnect() |
rdp_disconnect(void) |
750 |
{ |
{ |
751 |
sec_disconnect(); |
sec_disconnect(); |
752 |
} |
} |