--- sourceforge.net/trunk/rdesktop/rdp.c 2003/10/28 01:44:48 513 +++ sourceforge.net/trunk/rdesktop/rdp.c 2004/03/15 14:49:12 637 @@ -18,6 +18,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include #include "rdesktop.h" extern uint16 g_mcs_userid; @@ -28,6 +29,7 @@ extern BOOL g_desktop_save; extern BOOL g_use_rdp5; extern uint16 g_server_rdp_version; +extern uint32 g_rdp5_performanceflags; extern int g_server_bpp; uint8 *g_next_packet; @@ -131,21 +133,48 @@ s->p += len; } +/* Input a string in Unicode + * + * Returns str_len of string + */ +int +rdp_in_unistr(STREAM s, char *string, int uni_len) +{ + int i = 0; + + while (i < uni_len / 2) + { + in_uint8a(s, &string[i++], 1); + in_uint8s(s, 1); + } + + return i - 1; +} + + /* Parse a logon info packet */ static void rdp_send_logon_info(uint32 flags, char *domain, char *user, char *password, char *program, char *directory) { + char *ipaddr = tcp_get_address(); int len_domain = 2 * strlen(domain); int len_user = 2 * strlen(user); int len_password = 2 * strlen(password); int len_program = 2 * strlen(program); int len_directory = 2 * strlen(directory); - int len_ip = 2 * strlen("127.0.0.1"); + int len_ip = 2 * strlen(ipaddr); int len_dll = 2 * strlen("C:\\WINNT\\System32\\mstscax.dll"); int packetlen = 0; uint32 sec_flags = g_encryption ? (SEC_LOGON_INFO | SEC_ENCRYPT) : SEC_LOGON_INFO; STREAM s; + time_t t = time(NULL); + time_t tzone; + +#if 0 + // enable rdp compression + flags |= RDP_COMPRESSION; +#endif if (!g_use_rdp5 || 1 == g_server_rdp_version) { @@ -171,33 +200,33 @@ { flags |= RDP_LOGON_BLOB; DEBUG_RDP5(("Sending RDP5-style Logon packet\n")); - packetlen = 4 + // Unknown uint32 - 4 + // flags - 2 + // len_domain - 2 + // len_user - (flags & RDP_LOGON_AUTO ? 2 : 0) + // len_password - (flags & RDP_LOGON_BLOB ? 2 : 0) + // Length of BLOB - 2 + // len_program - 2 + // len_directory - (0 < len_domain ? len_domain : 2) + // domain - len_user + (flags & RDP_LOGON_AUTO ? len_password : 0) + 0 + // We have no 512 byte BLOB. Perhaps we must? - (flags & RDP_LOGON_BLOB && !(flags & RDP_LOGON_AUTO) ? 2 : 0) + // After the BLOB is a unknown int16. If there is a BLOB, that is. - (0 < len_program ? len_program : 2) + (0 < len_directory ? len_directory : 2) + 2 + // Unknown (2) - 2 + // Client ip length - len_ip + // Client ip - 2 + // DLL string length - len_dll + // DLL string - 2 + // Unknown - 2 + // Unknown - 64 + // Time zone #0 - 2 + // Unknown - 64 + // Time zone #1 - 32; // Unknown + packetlen = 4 + /* Unknown uint32 */ + 4 + /* flags */ + 2 + /* len_domain */ + 2 + /* len_user */ + (flags & RDP_LOGON_AUTO ? 2 : 0) + /* len_password */ + (flags & RDP_LOGON_BLOB ? 2 : 0) + /* Length of BLOB */ + 2 + /* len_program */ + 2 + /* len_directory */ + (0 < len_domain ? len_domain : 2) + /* domain */ + len_user + (flags & RDP_LOGON_AUTO ? len_password : 0) + 0 + /* We have no 512 byte BLOB. Perhaps we must? */ + (flags & RDP_LOGON_BLOB && !(flags & RDP_LOGON_AUTO) ? 2 : 0) + /* After the BLOB is a unknown int16. If there is a BLOB, that is. */ + (0 < len_program ? len_program : 2) + (0 < len_directory ? len_directory : 2) + 2 + /* Unknown (2) */ + 2 + /* Client ip length */ + len_ip + /* Client ip */ + 2 + /* DLL string length */ + len_dll + /* DLL string */ + 2 + /* Unknown */ + 2 + /* Unknown */ + 64 + /* Time zone #0 */ + 2 + /* Unknown */ + 64 + /* Time zone #1 */ + 32; /* Unknown */ s = sec_init(sec_flags, packetlen); DEBUG_RDP5(("Called sec_init with packetlen %d\n", packetlen)); - out_uint32(s, 0); // Unknown + out_uint32(s, 0); /* Unknown */ out_uint32_le(s, flags); out_uint16_le(s, len_domain); out_uint16_le(s, len_user); @@ -243,16 +272,17 @@ out_uint16_le(s, 0); } out_uint16_le(s, 2); - out_uint16_le(s, len_ip + 2); // Length of client ip - rdp_out_unistr(s, "127.0.0.1", len_ip); + out_uint16_le(s, len_ip + 2); /* Length of client ip */ + rdp_out_unistr(s, ipaddr, len_ip); out_uint16_le(s, len_dll + 2); rdp_out_unistr(s, "C:\\WINNT\\System32\\mstscax.dll", len_dll); - out_uint16_le(s, 0xffc4); - out_uint16_le(s, 0xffff); + + tzone = (mktime(gmtime(&t)) - mktime(localtime(&t))) / 60; + out_uint32_le(s, tzone); + rdp_out_unistr(s, "GTB, normaltid", 2 * strlen("GTB, normaltid")); out_uint8s(s, 62 - 2 * strlen("GTB, normaltid")); - out_uint32_le(s, 0x0a0000); out_uint32_le(s, 0x050000); out_uint32_le(s, 3); @@ -268,7 +298,7 @@ out_uint32(s, 0); out_uint32_le(s, 0xffffffc4); out_uint32_le(s, 0xfffffffe); - out_uint32_le(s, 0x0f); + out_uint32_le(s, g_rdp5_performanceflags); out_uint32(s, 0); @@ -600,7 +630,7 @@ rdp_recv(&type); /* RDP_PDU_SYNCHRONIZE */ rdp_recv(&type); /* RDP_CTL_COOPERATE */ rdp_recv(&type); /* RDP_CTL_GRANT_CONTROL */ - rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, 0, 0); + rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, ui_get_numlock_state(read_keyboard_state()), 0); rdp_send_fonts(1); rdp_send_fonts(2); rdp_recv(&type); /* RDP_PDU_UNKNOWN 0x28 */ @@ -724,6 +754,13 @@ DEBUG(("BITMAP_UPDATE(l=%d,t=%d,r=%d,b=%d,w=%d,h=%d,Bpp=%d,cmp=%d)\n", left, top, right, bottom, width, height, Bpp, compress)); + /* Server may limit bpp - this is how we find out */ + if (g_server_bpp != bpp) + { + warning("Server limited colour depth to %d bits\n", bpp); + g_server_bpp = bpp; + } + if (!compress) { int y; @@ -834,10 +871,44 @@ process_data_pdu(STREAM s) { uint8 data_pdu_type; + uint8 ctype; + uint16 clen; + int roff, rlen, len, ret; + static struct stream ns; + static signed char *dict = 0; - in_uint8s(s, 8); /* shareid, pad, streamid, length */ + in_uint8s(s, 6); /* shareid, pad, streamid */ + in_uint16(s, len); in_uint8(s, data_pdu_type); - in_uint8s(s, 3); /* compress_type, compress_len */ + in_uint8(s, ctype); + in_uint16(s, clen); + clen -= 18; + +#if 0 + if (ctype & 0x20) + { + if (!dict) + { + dict = (signed char *) malloc(8200 * sizeof(signed char)); + dict = (signed char *) memset(dict, 0, 8200 * sizeof(signed char)); + } + + ret = decompress(s->p, clen, ctype, (signed char *) dict, &roff, &rlen); + + len -= 18; + + ns.data = xrealloc(ns.data, len); + + ns.data = (unsigned char *) memcpy(ns.data, (unsigned char *) (dict + roff), len); + + ns.size = len; + ns.end = ns.data + ns.size; + ns.p = ns.data; + ns.rdp_hdr = ns.p; + + s = &ns; + } +#endif switch (data_pdu_type) { @@ -858,6 +929,12 @@ /* User logged on */ break; + case RDP_DATA_PDU_DISCONNECT: + /* Normally received when user logs out or disconnects from a + console session on Windows XP and 2003 Server */ + DEBUG(("Received disconnect PDU\n")); + break; + default: unimpl("data PDU %d\n", data_pdu_type); }