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-2000 |
Copyright (C) Matthew Chapman 1999-2001 |
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 |
24 |
extern char username[16]; |
extern char username[16]; |
25 |
extern BOOL bitmap_compression; |
extern BOOL bitmap_compression; |
26 |
extern BOOL orders; |
extern BOOL orders; |
27 |
extern BOOL use_encryption; |
extern BOOL encryption; |
28 |
extern BOOL desktop_save; |
extern BOOL desktop_save; |
29 |
|
|
30 |
uint8 *next_packet; |
uint8 *next_packet; |
36 |
{ |
{ |
37 |
STREAM s; |
STREAM s; |
38 |
|
|
39 |
s = sec_init(use_encryption ? SEC_ENCRYPT : 0, maxlen + 6); |
s = sec_init(encryption ? SEC_ENCRYPT : 0, maxlen + 6); |
40 |
s_push_layer(s, rdp_hdr, 6); |
s_push_layer(s, rdp_hdr, 6); |
41 |
|
|
42 |
return s; |
return s; |
55 |
out_uint16_le(s, (pdu_type | 0x10)); /* Version 1 */ |
out_uint16_le(s, (pdu_type | 0x10)); /* Version 1 */ |
56 |
out_uint16_le(s, (mcs_userid + 1001)); |
out_uint16_le(s, (mcs_userid + 1001)); |
57 |
|
|
58 |
sec_send(s, use_encryption ? SEC_ENCRYPT : 0); |
sec_send(s, encryption ? SEC_ENCRYPT : 0); |
59 |
} |
} |
60 |
|
|
61 |
/* Receive an RDP packet */ |
/* Receive an RDP packet */ |
62 |
static STREAM |
static STREAM |
63 |
rdp_recv(uint8 *type) |
rdp_recv(uint8 * type) |
64 |
{ |
{ |
65 |
static STREAM rdp_s; |
static STREAM rdp_s; |
66 |
uint16 length, pdu_type; |
uint16 length, pdu_type; |
83 |
in_uint8s(rdp_s, 2); /* userid */ |
in_uint8s(rdp_s, 2); /* userid */ |
84 |
*type = pdu_type & 0xf; |
*type = pdu_type & 0xf; |
85 |
|
|
86 |
#if RDP_DEBUG |
#if WITH_DEBUG |
87 |
DEBUG("RDP packet (type %x):\n", *type); |
DEBUG(("RDP packet (type %x):\n", *type)); |
88 |
hexdump(next_packet, length); |
hexdump(next_packet, length); |
89 |
#endif /* */ |
#endif /* */ |
90 |
|
|
98 |
{ |
{ |
99 |
STREAM s; |
STREAM s; |
100 |
|
|
101 |
s = sec_init(use_encryption ? SEC_ENCRYPT : 0, maxlen + 18); |
s = sec_init(encryption ? SEC_ENCRYPT : 0, maxlen + 18); |
102 |
s_push_layer(s, rdp_hdr, 18); |
s_push_layer(s, rdp_hdr, 18); |
103 |
|
|
104 |
return s; |
return s; |
125 |
out_uint8(s, 0); /* compress_type */ |
out_uint8(s, 0); /* compress_type */ |
126 |
out_uint16(s, 0); /* compress_len */ |
out_uint16(s, 0); /* compress_len */ |
127 |
|
|
128 |
sec_send(s, use_encryption ? SEC_ENCRYPT : 0); |
sec_send(s, encryption ? SEC_ENCRYPT : 0); |
129 |
} |
} |
130 |
|
|
131 |
/* Output a string in Unicode */ |
/* Output a string in Unicode */ |
155 |
int len_password = 2 * strlen(password); |
int len_password = 2 * strlen(password); |
156 |
int len_program = 2 * strlen(program); |
int len_program = 2 * strlen(program); |
157 |
int len_directory = 2 * strlen(directory); |
int len_directory = 2 * strlen(directory); |
158 |
uint32 sec_flags = use_encryption ? (SEC_LOGON_INFO | SEC_ENCRYPT) |
uint32 sec_flags = encryption ? (SEC_LOGON_INFO | SEC_ENCRYPT) : SEC_LOGON_INFO; |
|
: SEC_LOGON_INFO; |
|
159 |
STREAM s; |
STREAM s; |
160 |
|
|
161 |
s = sec_init(sec_flags, 18 + len_domain + len_user + len_password |
s = sec_init(sec_flags, 18 + len_domain + len_user + len_password |
211 |
|
|
212 |
/* Send a single input event */ |
/* Send a single input event */ |
213 |
void |
void |
214 |
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) |
|
215 |
{ |
{ |
216 |
STREAM s; |
STREAM s; |
217 |
|
|
440 |
RDP_CAPLEN_GENERAL + RDP_CAPLEN_BITMAP + RDP_CAPLEN_ORDER + |
RDP_CAPLEN_GENERAL + RDP_CAPLEN_BITMAP + RDP_CAPLEN_ORDER + |
441 |
RDP_CAPLEN_BMPCACHE + RDP_CAPLEN_COLCACHE + |
RDP_CAPLEN_BMPCACHE + RDP_CAPLEN_COLCACHE + |
442 |
RDP_CAPLEN_ACTIVATE + RDP_CAPLEN_CONTROL + |
RDP_CAPLEN_ACTIVATE + RDP_CAPLEN_CONTROL + |
443 |
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? */; |
|
444 |
|
|
445 |
s = rdp_init(14 + caplen + sizeof(RDP_SOURCE)); |
s = rdp_init(14 + caplen + sizeof(RDP_SOURCE)); |
446 |
|
|
476 |
|
|
477 |
in_uint32_le(s, rdp_shareid); |
in_uint32_le(s, rdp_shareid); |
478 |
|
|
479 |
DEBUG("DEMAND_ACTIVE(id=0x%x)\n", rdp_shareid); |
DEBUG(("DEMAND_ACTIVE(id=0x%x)\n", rdp_shareid)); |
480 |
|
|
481 |
rdp_send_confirm_active(); |
rdp_send_confirm_active(); |
482 |
rdp_send_synchronise(); |
rdp_send_synchronise(); |
523 |
in_uint16_le(s, datalen); |
in_uint16_le(s, datalen); |
524 |
in_uint8p(s, data, datalen); |
in_uint8p(s, data, datalen); |
525 |
in_uint8p(s, mask, masklen); |
in_uint8p(s, mask, masklen); |
526 |
cursor = ui_create_cursor(x, y, width, height, mask, |
cursor = ui_create_cursor(x, y, width, height, mask, data); |
|
data); |
|
527 |
ui_set_cursor(cursor); |
ui_set_cursor(cursor); |
528 |
cache_put_cursor(cache_idx, cursor); |
cache_put_cursor(cache_idx, cursor); |
529 |
break; |
break; |
534 |
break; |
break; |
535 |
|
|
536 |
default: |
default: |
537 |
DEBUG("Pointer message 0x%x\n", message_type); |
DEBUG(("Pointer message 0x%x\n", message_type)); |
538 |
} |
} |
539 |
} |
} |
540 |
|
|
565 |
cx = right - left + 1; |
cx = right - left + 1; |
566 |
cy = bottom - top + 1; |
cy = bottom - top + 1; |
567 |
|
|
568 |
DEBUG("UPDATE(l=%d,t=%d,r=%d,b=%d,w=%d,h=%d,cmp=%d)\n", |
DEBUG(("UPDATE(l=%d,t=%d,r=%d,b=%d,w=%d,h=%d,cmp=%d)\n", |
569 |
left, top, right, bottom, width, height, compress); |
left, top, right, bottom, width, height, compress)); |
570 |
|
|
571 |
if (!compress) |
if (!compress) |
572 |
{ |
{ |
574 |
bmpdata = xmalloc(width * height); |
bmpdata = xmalloc(width * height); |
575 |
for (y = 0; y < height; y++) |
for (y = 0; y < height; y++) |
576 |
{ |
{ |
577 |
in_uint8a(s, |
in_uint8a(s, &bmpdata[(height - y - 1) * width], width); |
|
&bmpdata[(height - y - 1) * width], |
|
|
width); |
|
578 |
} |
} |
579 |
ui_paint_bitmap(left, top, cx, cy, width, height, |
ui_paint_bitmap(left, top, cx, cy, width, height, bmpdata); |
|
bmpdata); |
|
580 |
xfree(bmpdata); |
xfree(bmpdata); |
581 |
continue; |
continue; |
582 |
} |
} |
589 |
bmpdata = xmalloc(width * height); |
bmpdata = xmalloc(width * height); |
590 |
if (bitmap_decompress(bmpdata, width, height, data, size)) |
if (bitmap_decompress(bmpdata, width, height, data, size)) |
591 |
{ |
{ |
592 |
ui_paint_bitmap(left, top, cx, cy, width, height, |
ui_paint_bitmap(left, top, cx, cy, width, height, bmpdata); |
|
bmpdata); |
|
593 |
} |
} |
594 |
|
|
595 |
xfree(bmpdata); |
xfree(bmpdata); |
602 |
{ |
{ |
603 |
HCOLOURMAP hmap; |
HCOLOURMAP hmap; |
604 |
COLOURMAP map; |
COLOURMAP map; |
605 |
|
uint8 *colours; |
606 |
|
|
607 |
in_uint8s(s, 2); /* pad */ |
in_uint8s(s, 2); /* pad */ |
608 |
in_uint16_le(s, map.ncolours); |
in_uint16_le(s, map.ncolours); |
609 |
in_uint8s(s, 2); /* pad */ |
in_uint8s(s, 2); /* pad */ |
610 |
in_uint8p(s, (uint8 *) map.colours, (map.ncolours * 3)); |
in_uint8p(s, colours, (map.ncolours * 3)); |
611 |
|
map.colours = (COLOURENTRY *) colours; |
612 |
|
|
613 |
hmap = ui_create_colourmap(&map); |
hmap = ui_create_colourmap(&map); |
614 |
ui_set_colourmap(hmap); |
ui_set_colourmap(hmap); |
640 |
break; |
break; |
641 |
|
|
642 |
default: |
default: |
643 |
NOTIMP("update %d\n", update_type); |
unimpl("update %d\n", update_type); |
644 |
} |
} |
645 |
|
|
646 |
} |
} |
674 |
break; |
break; |
675 |
|
|
676 |
default: |
default: |
677 |
NOTIMP("data PDU %d\n", data_pdu_type); |
unimpl("data PDU %d\n", data_pdu_type); |
678 |
} |
} |
679 |
} |
} |
680 |
|
|
701 |
break; |
break; |
702 |
|
|
703 |
default: |
default: |
704 |
NOTIMP("PDU %d\n", type); |
unimpl("PDU %d\n", type); |
705 |
} |
} |
706 |
} |
} |
707 |
} |
} |
714 |
if (!sec_connect(server)) |
if (!sec_connect(server)) |
715 |
return False; |
return False; |
716 |
|
|
717 |
rdp_send_logon_info(flags, domain, username, password, |
rdp_send_logon_info(flags, domain, username, password, command, directory); |
|
command, directory); |
|
718 |
return True; |
return True; |
719 |
} |
} |
720 |
|
|