ReactOS 0.4.16-dev-197-g92996da
rdp.c File Reference
#include "precomp.h"
Include dependency graph for rdp.c:

Go to the source code of this file.

Macros

#define RDP5_FLAG   0x0030
 

Functions

void rdssl_hmac_md5 (char *key, int keylen, char *data, int len, char *output)
 
static STREAM rdp_recv (uint8 *type)
 
static STREAM rdp_init_data (int maxlen)
 
static void rdp_send_data (STREAM s, uint8 data_pdu_type)
 
void rdp_out_unistr_mandatory_null (STREAM s, char *string, int len)
 
void rdp_out_unistr (STREAM s, char *string, int len)
 
void rdp_in_unistr (STREAM s, int in_len, char **string, uint32 *str_size)
 
static void rdp_send_logon_info (uint32 flags, char *domain, char *user, char *password, char *program, char *directory)
 
static void rdp_send_control (uint16 action)
 
static void rdp_send_synchronise (void)
 
void rdp_send_input (uint32 time, uint16 message_type, uint16 device_flags, uint16 param1, uint16 param2)
 
void rdp_send_client_window_status (int status)
 
static void rdp_enum_bmpcache2 (void)
 
static void rdp_send_fonts (uint16 seq)
 
static void rdp_out_general_caps (STREAM s)
 
static void rdp_out_bitmap_caps (STREAM s)
 
static void rdp_out_order_caps (STREAM s)
 
static void rdp_out_bmpcache_caps (STREAM s)
 
static void rdp_out_bmpcache2_caps (STREAM s)
 
static void rdp_out_control_caps (STREAM s)
 
static void rdp_out_activate_caps (STREAM s)
 
static void rdp_out_pointer_caps (STREAM s)
 
static void rdp_out_newpointer_caps (STREAM s)
 
static void rdp_out_share_caps (STREAM s)
 
static void rdp_out_colcache_caps (STREAM s)
 
static void rdp_out_brushcache_caps (STREAM s)
 
static void rdp_out_unknown_caps (STREAM s, uint16 id, uint16 length, uint8 *caps)
 
static void rdp_send_confirm_active (void)
 
static void rdp_process_general_caps (STREAM s)
 
static void rdp_process_bitmap_caps (STREAM s)
 
static void rdp_process_server_caps (STREAM s, uint16 length)
 
static void process_demand_active (STREAM s)
 
static void process_colour_pointer_common (STREAM s, int bpp)
 
void process_colour_pointer_pdu (STREAM s)
 
void process_new_pointer_pdu (STREAM s)
 
void process_cached_pointer_pdu (STREAM s)
 
void process_system_pointer_pdu (STREAM s)
 
static void process_pointer_pdu (STREAM s)
 
void process_bitmap_updates (STREAM s)
 
void process_palette (STREAM s)
 
static void process_update_pdu (STREAM s)
 
void process_pdu_logon (STREAM s)
 
void process_disconnect_pdu (STREAM s, uint32 *ext_disc_reason)
 
static RD_BOOL process_data_pdu (STREAM s, uint32 *ext_disc_reason)
 
static RD_BOOL process_redirect_pdu (STREAM s, RD_BOOL enhanced_redirect)
 
void rdp_main_loop (RD_BOOL *deactivated, uint32 *ext_disc_reason)
 
RD_BOOL rdp_loop (RD_BOOL *deactivated, uint32 *ext_disc_reason)
 
RD_BOOL rdp_connect (char *server, uint32 flags, char *domain, char *password, char *command, char *directory, RD_BOOL reconnect)
 
void rdp_reset_state (void)
 
void rdp_disconnect (void)
 

Variables

uint16 g_mcs_userid
 
char g_username [256]
 
char g_password [256]
 
char g_codepage [16]
 
RD_BOOL g_bitmap_compression
 
RD_BOOL g_orders
 
RD_BOOL g_encryption
 
RD_BOOL g_desktop_save
 
RD_BOOL g_polygon_ellipse_orders
 
RDP_VERSION g_rdp_version
 
uint16 g_server_rdp_version
 
uint32 g_rdp5_performanceflags
 
int g_server_depth
 
int g_width
 
int g_height
 
RD_BOOL g_bitmap_cache
 
RD_BOOL g_bitmap_cache_persist_enable
 
RD_BOOL g_numlock_sync
 
RD_BOOL g_pending_resize
 
RD_BOOL g_network_error
 
uint8g_next_packet
 
uint32 g_rdp_shareid
 
RDPCOMP g_mppc_dict
 
RD_BOOL g_redirect
 
charg_redirect_server
 
uint32 g_redirect_server_len
 
charg_redirect_domain
 
uint32 g_redirect_domain_len
 
charg_redirect_username
 
uint32 g_redirect_username_len
 
uint8g_redirect_lb_info
 
uint32 g_redirect_lb_info_len
 
uint8g_redirect_cookie
 
uint32 g_redirect_cookie_len
 
uint32 g_redirect_flags
 
uint32 g_redirect_session_id
 
uint32 g_reconnect_logonid
 
char g_reconnect_random [16]
 
time_t g_reconnect_random_ts
 
RD_BOOL g_has_reconnect_random
 
uint8 g_client_random [SEC_RANDOM_SIZE]
 
static uint8 caps_0x0d []
 
static uint8 caps_0x0c [] = { 0x01, 0x00, 0x00, 0x00 }
 
static uint8 caps_0x0e [] = { 0x01, 0x00, 0x00, 0x00 }
 
static uint8 caps_0x10 []
 

Macro Definition Documentation

◆ RDP5_FLAG

#define RDP5_FLAG   0x0030

Definition at line 911 of file rdp.c.

Function Documentation

◆ process_bitmap_updates()

void process_bitmap_updates ( STREAM  s)

Definition at line 1224 of file rdp.c.

1225{
1226 uint16 num_updates;
1228 uint16 cx, cy, bpp, Bpp, compress, bufsize, size;
1229 uint8 *data, *bmpdata;
1230 int i;
1231
1232 in_uint16_le(s, num_updates);
1233
1234 for (i = 0; i < num_updates; i++)
1235 {
1237 in_uint16_le(s, top);
1242 in_uint16_le(s, bpp);
1243 Bpp = (bpp + 7) / 8;
1246
1247 cx = right - left + 1;
1248 cy = bottom - top + 1;
1249
1250 DEBUG(("BITMAP_UPDATE(l=%d,t=%d,r=%d,b=%d,w=%d,h=%d,Bpp=%d,cmp=%d)\n",
1251 left, top, right, bottom, width, height, Bpp, compress));
1252
1253 if (!compress)
1254 {
1255 int y;
1256 bmpdata = (uint8 *) xmalloc(width * height * Bpp);
1257 for (y = 0; y < height; y++)
1258 {
1259 in_uint8a(s, &bmpdata[(height - y - 1) * (width * Bpp)],
1260 width * Bpp);
1261 }
1262 ui_paint_bitmap(left, top, cx, cy, width, height, bmpdata);
1263 xfree(bmpdata);
1264 continue;
1265 }
1266
1267
1268 if (compress & 0x400)
1269 {
1270 size = bufsize;
1271 }
1272 else
1273 {
1274 in_uint8s(s, 2); /* pad */
1276 in_uint8s(s, 4); /* line_size, final_size */
1277 }
1278 in_uint8p(s, data, size);
1279 bmpdata = (uint8 *) xmalloc(width * height * Bpp);
1280 if (bitmap_decompress(bmpdata, width, height, data, size, Bpp))
1281 {
1282 ui_paint_bitmap(left, top, cx, cy, width, height, bmpdata);
1283 }
1284 else
1285 {
1286 DEBUG_RDP5(("Failed to decompress data\n"));
1287 }
1288
1289 xfree(bmpdata);
1290 }
1291}
RD_BOOL bitmap_decompress(uint8 *output, int width, int height, uint8 *input, int size, int Bpp)
Definition: bitmap.c:884
#define in_uint16_le(s, v)
Definition: parse.h:55
#define in_uint8p(s, v, n)
Definition: parse.h:89
#define in_uint8a(s, v, n)
Definition: parse.h:90
#define in_uint8s(s, n)
Definition: parse.h:91
void xfree(void *mem)
Definition: uimain.c:758
void ui_paint_bitmap(int x, int y, int cx, int cy, int width, int height, uint8 *data)
Definition: uimain.c:307
void * xmalloc(int size)
Definition: uimain.c:747
#define DEBUG_RDP5(args)
Definition: rdesktop.h:141
#define DEBUG(args)
Definition: rdesktop.h:129
unsigned short uint16
Definition: types.h:30
unsigned char uint8
Definition: types.h:28
DWORD bpp
Definition: surface.c:185
GLdouble s
Definition: gl.h:2039
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
GLint GLint GLsizei width
Definition: gl.h:1546
GLsizeiptr size
Definition: glext.h:5919
GLdouble GLdouble GLdouble GLdouble top
Definition: glext.h:10859
GLdouble GLdouble right
Definition: glext.h:10859
GLint left
Definition: glext.h:7726
GLint GLint bottom
Definition: glext.h:7726
GLenum GLuint GLsizei bufsize
Definition: glext.h:7473
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_Out_opt_ int _Out_opt_ int * cy
Definition: commctrl.h:586
_Out_opt_ int * cx
Definition: commctrl.h:585
int ZEXPORT compress(Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
Definition: compress.c:68

Referenced by process_update_pdu(), and rdp5_process().

◆ process_cached_pointer_pdu()

void process_cached_pointer_pdu ( STREAM  s)

Definition at line 1156 of file rdp.c.

1157{
1158 uint16 cache_idx;
1159
1160 in_uint16_le(s, cache_idx);
1161 ui_set_cursor(cache_get_cursor(cache_idx));
1162}
RD_HCURSOR cache_get_cursor(uint16 cache_idx)
Definition: cache.c:400
void ui_set_cursor(RD_HCURSOR cursor)

Referenced by process_pointer_pdu(), and rdp5_process().

◆ process_colour_pointer_common()

static void process_colour_pointer_common ( STREAM  s,
int  bpp 
)
static

Definition at line 1107 of file rdp.c.

1108{
1109 uint16 width, height, cache_idx, masklen, datalen;
1110 uint16 x, y;
1111 uint8 *mask;
1112 uint8 *data;
1114
1115 in_uint16_le(s, cache_idx);
1116 in_uint16_le(s, x);
1117 in_uint16_le(s, y);
1120 in_uint16_le(s, masklen);
1123 in_uint8p(s, mask, masklen);
1124 if ((width != 32) || (height != 32))
1125 {
1126 warning("process_colour_pointer_common: " "width %d height %d\n", width, height);
1127 }
1128
1129 /* keep hotspot within cursor bounding box */
1130 x = MIN(x, width - 1);
1131 y = MIN(y, height - 1);
1134 cache_put_cursor(cache_idx, cursor);
1135}
void cache_put_cursor(uint16 cache_idx, RD_HCURSOR cursor)
Definition: cache.c:417
RD_HCURSOR ui_create_cursor(unsigned int x, unsigned int y, int width, int height, uint8 *andmask, uint8 *xormask, int bpp)
Definition: uimain.c:175
#define MIN(x, y)
Definition: rdesktop.h:171
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLenum GLint GLuint mask
Definition: glext.h:6028
const char cursor[]
Definition: icontest.c:13
int const JOCTET unsigned int datalen
Definition: jpeglib.h:1031
#define warning(s)
Definition: debug.h:83

Referenced by process_colour_pointer_pdu(), and process_new_pointer_pdu().

◆ process_colour_pointer_pdu()

void process_colour_pointer_pdu ( STREAM  s)

Definition at line 1139 of file rdp.c.

1140{
1142}
static void process_colour_pointer_common(STREAM s, int bpp)
Definition: rdp.c:1107

Referenced by process_pointer_pdu(), and rdp5_process().

◆ process_data_pdu()

static RD_BOOL process_data_pdu ( STREAM  s,
uint32 ext_disc_reason 
)
static

Definition at line 1416 of file rdp.c.

1417{
1418 uint8 data_pdu_type;
1419 uint8 ctype;
1420 uint16 clen;
1421 uint32 len;
1422
1423 uint32 roff, rlen;
1424
1425 struct stream *ns = &(g_mppc_dict.ns);
1426
1427 in_uint8s(s, 6); /* shareid, pad, streamid */
1428 in_uint16_le(s, len);
1429 in_uint8(s, data_pdu_type);
1430 in_uint8(s, ctype);
1431 in_uint16_le(s, clen);
1432 clen -= 18;
1433
1435 {
1436 if (len > RDP_MPPC_DICT_SIZE)
1437 error("error decompressed packet size exceeds max\n");
1438 if (mppc_expand(s->p, clen, ctype, &roff, &rlen) == -1)
1439 error("error while decompressing packet\n");
1440
1441 /* len -= 18; */
1442
1443 /* allocate memory and copy the uncompressed data into the temporary stream */
1444 ns->data = (uint8 *) xrealloc(ns->data, rlen);
1445
1446 memcpy((ns->data), (unsigned char *) (g_mppc_dict.hist + roff), rlen);
1447
1448 ns->size = rlen;
1449 ns->end = (ns->data + ns->size);
1450 ns->p = ns->data;
1451 ns->rdp_hdr = ns->p;
1452
1453 s = ns;
1454 }
1455
1456 switch (data_pdu_type)
1457 {
1460 break;
1461
1463 DEBUG(("Received Control PDU\n"));
1464 break;
1465
1467 DEBUG(("Received Sync PDU\n"));
1468 break;
1469
1472 break;
1473
1474 case RDP_DATA_PDU_BELL:
1475 ui_bell();
1476 break;
1477
1478 case RDP_DATA_PDU_LOGON:
1479 DEBUG(("Received Logon PDU\n"));
1480 /* User logged on */
1482 break;
1483
1486
1487 /* We used to return true and disconnect immediately here, but
1488 * Windows Vista sends a disconnect PDU with reason 0 when
1489 * reconnecting to a disconnected session, and MSTSC doesn't
1490 * drop the connection. I think we should just save the status.
1491 */
1492 break;
1493
1495 warning("Automatic reconnect using cookie, failed.\n");
1496 break;
1497
1498 default:
1499 unimpl("data PDU %d\n", data_pdu_type);
1500 }
1501 return False;
1502}
#define RDP_MPPC_DICT_SIZE
Definition: constants.h:358
#define RDP_MPPC_COMPRESSED
Definition: constants.h:355
@ RDP_DATA_PDU_POINTER
Definition: constants.h:172
@ RDP_DATA_PDU_BELL
Definition: constants.h:175
@ RDP_DATA_PDU_CONTROL
Definition: constants.h:171
@ RDP_DATA_PDU_SYNCHRONISE
Definition: constants.h:174
@ RDP_DATA_PDU_LOGON
Definition: constants.h:177
@ RDP_DATA_PDU_AUTORECONNECT_STATUS
Definition: constants.h:181
@ RDP_DATA_PDU_DISCONNECT
Definition: constants.h:180
@ RDP_DATA_PDU_UPDATE
Definition: constants.h:170
int mppc_expand(uint8 *data, uint32 clen, uint8 ctype, uint32 *roff, uint32 *rlen)
Definition: mppc.c:58
#define in_uint8(s, v)
Definition: parse.h:88
void ui_bell(void)
Definition: uimain.c:158
void unimpl(char *format,...)
Definition: uimain.c:801
void * xrealloc(void *oldmem, size_t size)
Definition: uimain.c:736
void process_pdu_logon(STREAM s)
Definition: rdp.c:1362
static void process_update_pdu(STREAM s)
Definition: rdp.c:1326
void process_disconnect_pdu(STREAM s, uint32 *ext_disc_reason)
Definition: rdp.c:1407
RDPCOMP g_mppc_dict
Definition: mppc.c:55
static void process_pointer_pdu(STREAM s)
Definition: rdp.c:1184
unsigned int uint32
Definition: types.h:32
#define False
Definition: types.h:25
Definition: _ctype.h:58
GLenum GLsizei len
Definition: glext.h:6722
#define error(str)
Definition: mkdosfs.c:1605
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
struct stream ns
Definition: types.h:192
uint8 hist[RDP_MPPC_DICT_SIZE]
Definition: types.h:191
Definition: mxnamespace.c:45
Definition: parse.h:23
uint32 ext_disc_reason
Definition: svgawin.c:64

Referenced by rdp_loop().

◆ process_demand_active()

static void process_demand_active ( STREAM  s)
static

Definition at line 1067 of file rdp.c.

1068{
1069 uint8 type;
1070 uint16 len_src_descriptor, len_combined_caps;
1071
1073 in_uint16_le(s, len_src_descriptor);
1074 in_uint16_le(s, len_combined_caps);
1075 in_uint8s(s, len_src_descriptor);
1076
1077 DEBUG(("DEMAND_ACTIVE(id=0x%x)\n", g_rdp_shareid));
1078 rdp_process_server_caps(s, len_combined_caps);
1079
1084 rdp_recv(&type); /* RDP_PDU_SYNCHRONIZE */
1085 rdp_recv(&type); /* RDP_CTL_COOPERATE */
1086 rdp_recv(&type); /* RDP_CTL_GRANT_CONTROL */
1089
1090 if (g_rdp_version >= RDP_V5)
1091 {
1093 rdp_send_fonts(3);
1094 }
1095 else
1096 {
1097 rdp_send_fonts(1);
1098 rdp_send_fonts(2);
1099 }
1100
1101 rdp_recv(&type); /* RDP_PDU_UNKNOWN 0x28 (Fonts?) */
1103}
@ RDP_CTL_COOPERATE
Definition: constants.h:203
@ RDP_CTL_REQUEST_CONTROL
Definition: constants.h:200
@ RDP_INPUT_SYNCHRONIZE
Definition: constants.h:231
void reset_order_state(void)
Definition: orders.c:1454
#define in_uint32_le(s, v)
Definition: parse.h:56
uint16 ui_get_numlock_state(unsigned int state)
Definition: svgawin.c:1620
unsigned int read_keyboard_state(void)
Definition: uimain.c:632
static void rdp_send_control(uint16 action)
Definition: rdp.c:520
static void rdp_enum_bmpcache2(void)
Definition: rdp.c:603
RD_BOOL g_numlock_sync
Definition: uimain.c:80
void rdp_send_input(uint32 time, uint16 message_type, uint16 device_flags, uint16 param1, uint16 param2)
Definition: rdp.c:551
static void rdp_send_fonts(uint16 seq)
Definition: rdp.c:647
static void rdp_send_confirm_active(void)
Definition: rdp.c:914
RDP_VERSION g_rdp_version
Definition: uimain.c:74
static STREAM rdp_recv(uint8 *type)
Definition: rdp.c:85
uint32 g_rdp_shareid
Definition: rdp.c:46
static void rdp_process_server_caps(STREAM s, uint16 length)
Definition: rdp.c:1029
static void rdp_send_synchronise(void)
Definition: rdp.c:536
@ RDP_V5
Definition: types.h:44
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545

Referenced by rdp_loop().

◆ process_disconnect_pdu()

void process_disconnect_pdu ( STREAM  s,
uint32 ext_disc_reason 
)

Definition at line 1407 of file rdp.c.

1408{
1410
1411 DEBUG(("Received disconnect PDU\n"));
1412}

Referenced by process_data_pdu().

◆ process_new_pointer_pdu()

void process_new_pointer_pdu ( STREAM  s)

Definition at line 1146 of file rdp.c.

1147{
1148 int xor_bpp;
1149
1150 in_uint16_le(s, xor_bpp);
1152}

Referenced by process_pointer_pdu(), and rdp5_process().

◆ process_palette()

void process_palette ( STREAM  s)

Definition at line 1295 of file rdp.c.

1296{
1298 COLOURMAP map;
1299 RD_HCOLOURMAP hmap;
1300 int i;
1301
1302 in_uint8s(s, 2); /* pad */
1303 in_uint16_le(s, map.ncolours);
1304 in_uint8s(s, 2); /* pad */
1305
1306 map.colours = (COLOURENTRY *) xmalloc(sizeof(COLOURENTRY) * map.ncolours);
1307
1308 DEBUG(("PALETTE(c=%d)\n", map.ncolours));
1309
1310 for (i = 0; i < map.ncolours; i++)
1311 {
1312 entry = &map.colours[i];
1313 in_uint8(s, entry->red);
1314 in_uint8(s, entry->green);
1315 in_uint8(s, entry->blue);
1316 }
1317
1318 hmap = ui_create_colourmap(&map);
1319 ui_set_colourmap(hmap);
1320
1321 xfree(map.colours);
1322}
void ui_set_colourmap(RD_HCOLOURMAP map)
Definition: qtewin.cpp:1527
RD_HCOLOURMAP ui_create_colourmap(COLOURMAP *colours)
Definition: uimain.c:336
Definition: _map.h:48
uint32_t entry
Definition: isohybrid.c:63

Referenced by process_update_pdu(), and rdp5_process().

◆ process_pdu_logon()

void process_pdu_logon ( STREAM  s)

Definition at line 1362 of file rdp.c.

1363{
1364 uint32 infotype;
1365 in_uint32_le(s, infotype);
1366 if (infotype == INFOTYPE_LOGON_EXTENDED_INF)
1367 {
1368 uint32 fieldspresent;
1369
1370 in_uint8s(s, 2); /* Length */
1371 in_uint32_le(s, fieldspresent);
1372 if (fieldspresent & LOGON_EX_AUTORECONNECTCOOKIE)
1373 {
1374 uint32 len;
1376
1377 /* TS_LOGON_INFO_FIELD */
1378 in_uint8s(s, 4); /* cbFieldData */
1379
1380 /* ARC_SC_PRIVATE_PACKET */
1381 in_uint32_le(s, len);
1382 if (len != 28)
1383 {
1384 warning("Invalid length in Auto-Reconnect packet\n");
1385 return;
1386 }
1387
1389 if (version != 1)
1390 {
1391 warning("Unsupported version of Auto-Reconnect packet\n");
1392 return;
1393 }
1394
1399 DEBUG(("Saving auto-reconnect cookie, id=%u\n", g_reconnect_logonid));
1400 }
1401 }
1402}
@ INFOTYPE_LOGON_EXTENDED_INF
Definition: constants.h:189
@ LOGON_EX_AUTORECONNECTCOOKIE
Definition: constants.h:194
time_t g_reconnect_random_ts
Definition: uimain.c:84
uint32 g_reconnect_logonid
Definition: uimain.c:82
RD_BOOL g_has_reconnect_random
Definition: uimain.c:85
char g_reconnect_random[16]
Definition: uimain.c:83
#define True
Definition: types.h:24
#define NULL
Definition: types.h:112
static const WCHAR version[]
Definition: asmname.c:66
__u16 time
Definition: mkdosfs.c:8

Referenced by process_data_pdu().

◆ process_pointer_pdu()

static void process_pointer_pdu ( STREAM  s)
static

Definition at line 1184 of file rdp.c.

1185{
1186 uint16 message_type;
1187 uint16 x, y;
1188
1189 in_uint16_le(s, message_type);
1190 in_uint8s(s, 2); /* pad */
1191
1192 switch (message_type)
1193 {
1194 case RDP_POINTER_MOVE:
1195 in_uint16_le(s, x);
1196 in_uint16_le(s, y);
1197 if (s_check(s))
1199 break;
1200
1201 case RDP_POINTER_COLOR:
1203 break;
1204
1205 case RDP_POINTER_CACHED:
1207 break;
1208
1209 case RDP_POINTER_SYSTEM:
1211 break;
1212
1213 case RDP_POINTER_NEW:
1215 break;
1216
1217 default:
1218 unimpl("Pointer message 0x%x\n", message_type);
1219 }
1220}
@ RDP_POINTER_MOVE
Definition: constants.h:217
@ RDP_POINTER_NEW
Definition: constants.h:220
@ RDP_POINTER_CACHED
Definition: constants.h:219
@ RDP_POINTER_COLOR
Definition: constants.h:218
@ RDP_POINTER_SYSTEM
Definition: constants.h:216
#define s_check(s)
Definition: parse.h:42
void ui_move_pointer(int x, int y)
Definition: uimain.c:616
void process_cached_pointer_pdu(STREAM s)
Definition: rdp.c:1156
void process_system_pointer_pdu(STREAM s)
Definition: rdp.c:1166
void process_colour_pointer_pdu(STREAM s)
Definition: rdp.c:1139
void process_new_pointer_pdu(STREAM s)
Definition: rdp.c:1146

Referenced by process_data_pdu().

◆ process_redirect_pdu()

static RD_BOOL process_redirect_pdu ( STREAM  s,
RD_BOOL  enhanced_redirect 
)
static

Definition at line 1506 of file rdp.c.

1507{
1508 uint32 len;
1509 uint16 redirect_identifier;
1510
1511 /* reset any previous redirection information */
1512 g_redirect = True;
1518
1524
1525 /* these 2 bytes are unknown, seem to be zeros */
1526 in_uint8s(s, 2);
1527
1528 /* FIXME: Previous implementation only reads 4 bytes which has been working
1529 but todays spec says something different. Investigate and retest
1530 server redirection using WTS 2003 cluster.
1531 */
1532
1533 if (enhanced_redirect)
1534 {
1535 /* read identifier */
1536 in_uint16_le(s, redirect_identifier);
1537 if (redirect_identifier != 0x0400)
1538 error("Protocol error in server redirection, unexpected data.");
1539
1540 /* FIXME: skip total length */
1541 in_uint8s(s, 2);
1542
1543 /* read session_id */
1545 }
1546
1547 /* read connection flags */
1549
1551 {
1552 /* read length of ip string */
1553 in_uint32_le(s, len);
1554
1555 /* read ip string */
1557 }
1558
1560 {
1561 /* read length of load balance info blob */
1563
1564 /* reallocate a loadbalance info blob */
1565 if (g_redirect_lb_info != NULL)
1567
1569
1570 /* read load balance info blob */
1572 }
1573
1575 {
1576 /* read length of username string */
1577 in_uint32_le(s, len);
1578
1579 /* read username string */
1581 }
1582
1584 {
1585 /* read length of domain string */
1586 in_uint32_le(s, len);
1587
1588 /* read domain string */
1590 }
1591
1593 {
1594 /* the information in this blob is either a password or a cookie that
1595 should be passed though as blob and not parsed as a unicode string */
1596
1597 /* read blob length */
1599
1600 /* reallocate cookie blob */
1601 if (g_redirect_cookie != NULL)
1603
1605
1606 /* read cookie as is */
1608 }
1609
1611 {
1612 warning("LB_DONTSTOREUSERNAME set\n");
1613 }
1614
1616 {
1617 warning("LB_SMARTCARD_LOGON set\n");
1618 }
1619
1621 {
1622 /* By spec this is only for information and doesn't mean that an actual
1623 redirect should be performed. How it should be used is not mentioned. */
1624 g_redirect = False;
1625 }
1626
1628 {
1629 in_uint32_le(s, len);
1630
1631 /* Let target fqdn replace target ip address */
1633 {
1636 }
1637
1638 /* read fqdn string */
1640 }
1641
1643 {
1644 warning("LB_TARGET_NETBIOS set\n");
1645 }
1646
1648 {
1649 warning("LB_TARGET_NET_ADDRESSES set\n");
1650 }
1651
1653 {
1654 warning("LB_CLIENT_TSV_URL set\n");
1655 }
1656
1658 {
1659 warning("LB_SERVER_TSV_CAPABLE set\n");
1660 }
1661
1663 {
1664 warning("LB_PASSWORD_IS_PK_ENCRYPTED set\n");
1665 }
1666
1668 {
1669 warning("LB_REDIRECTION_GUID set\n");
1670 }
1671
1673 {
1674 warning("LB_TARGET_CERTIFICATE set\n");
1675 }
1676
1677 return True;
1678}
@ LB_PASSWORD
Definition: constants.h:593
@ LB_USERNAME
Definition: constants.h:591
@ LB_TARGET_CERTIFICATE
Definition: constants.h:604
@ LB_DOMAIN
Definition: constants.h:592
@ LB_TARGET_NETBIOS
Definition: constants.h:598
@ LB_SERVER_TSV_CAPABLE
Definition: constants.h:601
@ LB_CLIENT_TSV_URL
Definition: constants.h:600
@ LB_PASSWORD_IS_PK_ENCRYPTED
Definition: constants.h:602
@ LB_TARGET_NET_ADDRESSES
Definition: constants.h:599
@ LB_LOAD_BALANCE_INFO
Definition: constants.h:590
@ LB_SMARTCARD_LOGON
Definition: constants.h:595
@ LB_REDIRECTION_GUID
Definition: constants.h:603
@ LB_NOREDIRECT
Definition: constants.h:596
@ LB_DONTSTOREUSERNAME
Definition: constants.h:594
@ LB_TARGET_FQDN
Definition: constants.h:597
@ LB_TARGET_NET_ADDRESS
Definition: constants.h:589
char * g_redirect_server
Definition: uimain.c:56
uint8 * g_redirect_cookie
Definition: uimain.c:64
RD_BOOL g_redirect
Definition: uimain.c:55
void rdp_in_unistr(STREAM s, int in_len, char **string, uint32 *str_size)
Definition: rdp.c:265
uint32 g_redirect_domain_len
Definition: uimain.c:59
uint32 g_redirect_cookie_len
Definition: uimain.c:65
uint32 g_redirect_server_len
Definition: uimain.c:57
uint32 g_redirect_lb_info_len
Definition: uimain.c:63
uint8 * g_redirect_lb_info
Definition: uimain.c:62
uint32 g_redirect_username_len
Definition: uimain.c:61
uint32 g_redirect_session_id
Definition: uimain.c:67
uint32 g_redirect_flags
Definition: uimain.c:66
char * g_redirect_domain
Definition: uimain.c:58
char * g_redirect_username
Definition: uimain.c:60
#define free
Definition: debug_ros.c:5

Referenced by rdp_loop().

◆ process_system_pointer_pdu()

void process_system_pointer_pdu ( STREAM  s)

Definition at line 1166 of file rdp.c.

1167{
1168 uint16 system_pointer_type;
1169
1170 in_uint16_le(s, system_pointer_type);
1171 switch (system_pointer_type)
1172 {
1173 case RDP_NULL_POINTER:
1175 break;
1176
1177 default:
1178 unimpl("System pointer message 0x%x\n", system_pointer_type);
1179 }
1180}
@ RDP_NULL_POINTER
Definition: constants.h:225
void ui_set_null_cursor(void)
Definition: uimain.c:227

Referenced by process_pointer_pdu().

◆ process_update_pdu()

static void process_update_pdu ( STREAM  s)
static

Definition at line 1326 of file rdp.c.

1327{
1328 uint16 update_type, count;
1329
1330 in_uint16_le(s, update_type);
1331
1333 switch (update_type)
1334 {
1335 case RDP_UPDATE_ORDERS:
1336 in_uint8s(s, 2); /* pad */
1338 in_uint8s(s, 2); /* pad */
1340 break;
1341
1342 case RDP_UPDATE_BITMAP:
1344 break;
1345
1346 case RDP_UPDATE_PALETTE:
1348 break;
1349
1351 break;
1352
1353 default:
1354 unimpl("update %d\n", update_type);
1355 }
1356 ui_end_update();
1357}
@ RDP_UPDATE_PALETTE
Definition: constants.h:210
@ RDP_UPDATE_BITMAP
Definition: constants.h:209
@ RDP_UPDATE_SYNCHRONIZE
Definition: constants.h:211
@ RDP_UPDATE_ORDERS
Definition: constants.h:208
void process_orders(STREAM s, uint16 num_orders)
Definition: orders.c:1311
void ui_begin_update(void)
Definition: uimain.c:657
void ui_end_update(void)
Definition: uimain.c:664
void process_bitmap_updates(STREAM s)
Definition: rdp.c:1224
void process_palette(STREAM s)
Definition: rdp.c:1295
GLuint GLuint GLsizei count
Definition: gl.h:1545

Referenced by process_data_pdu().

◆ rdp_connect()

RD_BOOL rdp_connect ( char server,
uint32  flags,
char domain,
char password,
char command,
char directory,
RD_BOOL  reconnect 
)

Definition at line 1742 of file rdp.c.

1744{
1747
1748 if (!sec_connect(server, g_username, domain, password, reconnect))
1749 return False;
1750
1752
1753 /* run RDP loop until first licence demand active PDU */
1754 while (!g_rdp_shareid)
1755 {
1756 if (g_network_error)
1757 return False;
1758
1760 return False;
1761
1762 if (g_redirect)
1763 return True;
1764 }
1765 return True;
1766}
RD_BOOL sec_connect(char *server, char *username, char *domain, char *password, RD_BOOL reconnect)
Definition: secure.c:1005
static void rdp_send_logon_info(uint32 flags, char *domain, char *user, char *password, char *program, char *directory)
Definition: rdp.c:343
RD_BOOL g_network_error
Definition: uimain.c:77
RD_BOOL rdp_loop(RD_BOOL *deactivated, uint32 *ext_disc_reason)
Definition: rdp.c:1695
char g_username[256]
Definition: uimain.c:25
int RD_BOOL
Definition: types.h:21
GLbitfield flags
Definition: glext.h:7161
static WCHAR password[]
Definition: url.c:33
Definition: cookie.c:42
int deactivated
Definition: svgawin.c:63
static rfbScreenInfoPtr server
Definition: vnc.c:74

Referenced by main(), mstsc_ProtocolIOThread(), param_connect(), SEALED_::ProtocolLoop(), rdp2vnc_connect(), QMyScrollView::timerEvent(), ui_main(), and ui_main_loop().

◆ rdp_disconnect()

void rdp_disconnect ( void  )

Definition at line 1779 of file rdp.c.

1780{
1782}
void sec_disconnect(void)
Definition: secure.c:1032

Referenced by main(), SEALED_::ProtocolLoop(), and rdp2vnc_connect().

◆ rdp_enum_bmpcache2()

static void rdp_enum_bmpcache2 ( void  )
static

Definition at line 603 of file rdp.c.

604{
605 STREAM s;
607 uint32 num_keys, offset, count, flags;
608
609 offset = 0;
610 num_keys = pstcache_enumerate(2, keylist);
611
612 while (offset < num_keys)
613 {
614 count = MIN(num_keys - offset, 169);
615
616 s = rdp_init_data(24 + count * sizeof(HASH_KEY));
617
618 flags = 0;
619 if (offset == 0)
621 if (num_keys - offset <= 169)
623
624 /* header */
625 out_uint32_le(s, 0);
627 out_uint16_le(s, 0);
628 out_uint16_le(s, 0);
629 out_uint16_le(s, 0);
630 out_uint16_le(s, 0);
631 out_uint16_le(s, num_keys);
632 out_uint32_le(s, 0);
634
635 /* list */
636 out_uint8a(s, keylist[offset], count * sizeof(HASH_KEY));
637
638 s_mark_end(s);
639 rdp_send_data(s, 0x2b);
640
641 offset += 169;
642 }
643}
#define PDU_FLAG_FIRST
Definition: constants.h:287
#define BMPCACHE2_NUM_PSTCELLS
Definition: constants.h:285
#define PDU_FLAG_LAST
Definition: constants.h:288
#define s_mark_end(s)
Definition: parse.h:41
#define out_uint32_le(s, v)
Definition: parse.h:59
#define out_uint16_le(s, v)
Definition: parse.h:58
#define out_uint8a(s, v, n)
Definition: parse.h:94
int pstcache_enumerate(uint8 id, HASH_KEY *keylist)
Definition: pstcache.c:107
static STREAM rdp_init_data(int maxlen)
Definition: rdp.c:140
static void rdp_send_data(STREAM s, uint8 data_pdu_type)
Definition: rdp.c:152
uint8 HASH_KEY[8]
Definition: types.h:161
GLintptr offset
Definition: glext.h:5920
Definition: path.c:35

Referenced by process_demand_active().

◆ rdp_in_unistr()

void rdp_in_unistr ( STREAM  s,
int  in_len,
char **  string,
uint32 str_size 
)

Definition at line 265 of file rdp.c.

266{
267 /* Dynamic allocate of destination string if not provided */
268 *string = xmalloc(in_len * 2);
269 *str_size = in_len * 2;
270
271#ifdef HAVE_ICONV
272 size_t ibl = in_len, obl = *str_size - 1;
273 char *pin = (char *) s->p, *pout = *string;
274 static iconv_t iconv_h = (iconv_t) - 1;
275
276 if (g_iconv_works)
277 {
278 if (iconv_h == (iconv_t) - 1)
279 {
280 if ((iconv_h = iconv_open(g_codepage, WINDOWS_CODEPAGE)) == (iconv_t) - 1)
281 {
282 warning("rdp_in_unistr: iconv_open[%s -> %s] fail %d\n",
283 WINDOWS_CODEPAGE, g_codepage, (int) iconv_h);
284
285 g_iconv_works = False;
286 return rdp_in_unistr(s, in_len, string, str_size);
287 }
288 }
289
290 if (iconv(iconv_h, (ICONV_CONST char **) &pin, &ibl, &pout, &obl) == (size_t) - 1)
291 {
292 if (errno == E2BIG)
293 {
294 warning("server sent an unexpectedly long string, truncating\n");
295 }
296 else
297 {
298 warning("rdp_in_unistr: iconv fail, errno %d\n", errno);
299
300 free(*string);
301 *string = NULL;
302 *str_size = 0;
303 }
304 }
305
306 /* we must update the location of the current STREAM for future reads of s->p */
307 s->p += in_len;
308
309 *pout = 0;
310
311 if (*string)
312 *str_size = pout - *string;
313 }
314 else
315#endif
316 {
317 int i = 0;
318 int rem = 0;
319 uint32 len = in_len / 2;
320
321 if (len > *str_size - 1)
322 {
323 warning("server sent an unexpectedly long string, truncating\n");
324 len = *str_size - 1;
325 rem = in_len - 2 * len;
326 }
327
328 while (i < len)
329 {
330 in_uint8a(s, &string[i++], 1);
331 in_uint8s(s, 1);
332 }
333
334 in_uint8s(s, rem);
335 string[len] = 0;
336 *str_size = len;
337 }
338}
#define WINDOWS_CODEPAGE
Definition: constants.h:24
char g_codepage[16]
Definition: rdp.c:27
#define E2BIG
Definition: errno.h:13
iconv_t iconv_open(const char *tocode, const char *fromcode)
Definition: win_iconv.c:730
size_t iconv(iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
Definition: win_iconv.c:771
char string[160]
Definition: util.h:11
#define errno
Definition: errno.h:18
Definition: regsvr.c:104
#define iconv_t
Definition: iconv.h:68

Referenced by disk_set_information(), printercache_process(), process_redirect_pdu(), rdp_in_unistr(), and rdpdr_process_irp().

◆ rdp_init_data()

static STREAM rdp_init_data ( int  maxlen)
static

Definition at line 140 of file rdp.c.

141{
142 STREAM s;
143
144 s = sec_init(g_encryption ? SEC_ENCRYPT : 0, maxlen + 18);
145 s_push_layer(s, rdp_hdr, 18);
146
147 return s;
148}
#define SEC_ENCRYPT
Definition: constants.h:101
#define s_push_layer(s, h, n)
Definition: parse.h:39
STREAM sec_init(uint32 flags, int maxlen)
Definition: secure.c:419
RD_BOOL g_encryption
Definition: uimain.c:40

Referenced by rdp_enum_bmpcache2(), rdp_send_client_window_status(), rdp_send_control(), rdp_send_fonts(), rdp_send_input(), and rdp_send_synchronise().

◆ rdp_loop()

RD_BOOL rdp_loop ( RD_BOOL deactivated,
uint32 ext_disc_reason 
)

Definition at line 1695 of file rdp.c.

1696{
1697 uint8 type;
1698 RD_BOOL cont = True;
1699 STREAM s;
1700
1701 while (cont)
1702 {
1703 s = rdp_recv(&type);
1704 if (s == NULL)
1705 return False;
1706 switch (type)
1707 {
1710 *deactivated = False;
1711 break;
1712 case RDP_PDU_DEACTIVATE:
1713 DEBUG(("RDP_PDU_DEACTIVATE\n"));
1714 *deactivated = True;
1715 break;
1716 case RDP_PDU_REDIRECT:
1717 return process_redirect_pdu(s, False);
1718 break;
1720 return process_redirect_pdu(s, True);
1721 break;
1722 case RDP_PDU_DATA:
1723 /* If we got a data PDU, we don't need to keep the password in memory
1724 anymore and therefor we should clear it for security reasons. */
1725 if (g_password[0] != '\0')
1726 memset(g_password, 0, sizeof(g_password));
1727
1729 break;
1730 case 0:
1731 break;
1732 default:
1733 unimpl("PDU %d\n", type);
1734 }
1735 cont = g_next_packet < s->end;
1736 }
1737 return True;
1738}
@ RDP_PDU_DEMAND_ACTIVE
Definition: constants.h:160
@ RDP_PDU_DEACTIVATE
Definition: constants.h:163
@ RDP_PDU_ENHANCED_REDIRECT
Definition: constants.h:165
@ RDP_PDU_REDIRECT
Definition: constants.h:162
@ RDP_PDU_DATA
Definition: constants.h:164
static void process_demand_active(STREAM s)
Definition: rdp.c:1067
uint8 * g_next_packet
Definition: rdp.c:45
char g_password[256]
Definition: uimain.c:28
static RD_BOOL process_data_pdu(STREAM s, uint32 *ext_disc_reason)
Definition: rdp.c:1416
static RD_BOOL process_redirect_pdu(STREAM s, RD_BOOL enhanced_redirect)
Definition: rdp.c:1506
#define memset(x, y, z)
Definition: compat.h:39

Referenced by QMyMainWindow::dataReceived(), nanox_event(), rdp_connect(), rdp_main_loop(), ui_main_loop(), and ui_read_wire().

◆ rdp_main_loop()

void rdp_main_loop ( RD_BOOL deactivated,
uint32 ext_disc_reason 
)

Definition at line 1682 of file rdp.c.

1683{
1685 {
1687 {
1688 return;
1689 }
1690 }
1691}
RD_BOOL g_pending_resize
Definition: uimain.c:79

Referenced by main(), mstsc_ProtocolIOThread(), SEALED_::ProtocolLoop(), and rdp2vnc_connect().

◆ rdp_out_activate_caps()

static void rdp_out_activate_caps ( STREAM  s)
static

Definition at line 809 of file rdp.c.

810{
813
814 out_uint16(s, 0); /* Help key */
815 out_uint16(s, 0); /* Help index key */
816 out_uint16(s, 0); /* Extended help key */
817 out_uint16(s, 0); /* Window activate */
818}
#define RDP_CAPSET_ACTIVATE
Definition: constants.h:310
#define RDP_CAPLEN_ACTIVATE
Definition: constants.h:311
#define out_uint16(s, v)
Definition: parse.h:84

Referenced by rdp_send_confirm_active().

◆ rdp_out_bitmap_caps()

static void rdp_out_bitmap_caps ( STREAM  s)
static

Definition at line 690 of file rdp.c.

691{
694
695 out_uint16_le(s, g_server_depth); /* Preferred colour depth */
696 out_uint16_le(s, 1); /* Receive 1 BPP */
697 out_uint16_le(s, 1); /* Receive 4 BPP */
698 out_uint16_le(s, 1); /* Receive 8 BPP */
699 out_uint16_le(s, 800); /* Desktop width */
700 out_uint16_le(s, 600); /* Desktop height */
701 out_uint16(s, 0); /* Pad */
702 out_uint16(s, 1); /* Allow resize */
703 out_uint16_le(s, g_bitmap_compression ? 1 : 0); /* Support compression */
704 out_uint16(s, 0); /* Unknown */
705 out_uint16_le(s, 1); /* Unknown */
706 out_uint16(s, 0); /* Pad */
707}
#define RDP_CAPSET_BITMAP
Definition: constants.h:296
#define RDP_CAPLEN_BITMAP
Definition: constants.h:297
int g_server_depth
Definition: uimain.c:41
RD_BOOL g_bitmap_compression
Definition: uimain.c:34

Referenced by rdp_send_confirm_active().

◆ rdp_out_bmpcache2_caps()

static void rdp_out_bmpcache2_caps ( STREAM  s)
static

Definition at line 771 of file rdp.c.

772{
775
776 out_uint16_le(s, g_bitmap_cache_persist_enable ? 2 : 0); /* version */
777
778 out_uint16_be(s, 3); /* number of caches in this set */
779
780 /* max cell size for cache 0 is 16x16, 1 = 32x32, 2 = 64x64, etc */
783 if (pstcache_init(2))
784 {
786 }
787 else
788 {
790 }
791 out_uint8s(s, 20); /* other bitmap caches not used */
792}
#define RDP_CAPSET_BMPCACHE2
Definition: constants.h:326
#define BMPCACHE2_FLAG_PERSIST
Definition: constants.h:328
#define RDP_CAPLEN_BMPCACHE2
Definition: constants.h:327
#define BMPCACHE2_C0_CELLS
Definition: constants.h:282
#define BMPCACHE2_C1_CELLS
Definition: constants.h:283
#define BMPCACHE2_C2_CELLS
Definition: constants.h:284
#define out_uint16_be(s, v)
Definition: parse.h:77
#define out_uint8s(s, n)
Definition: parse.h:95
RD_BOOL pstcache_init(uint8 cache_id)
Definition: pstcache.c:163
RD_BOOL g_bitmap_cache_persist_enable
Definition: uimain.c:37

Referenced by rdp_send_confirm_active().

◆ rdp_out_bmpcache_caps()

static void rdp_out_bmpcache_caps ( STREAM  s)
static

Definition at line 753 of file rdp.c.

754{
755 int Bpp;
758
759 Bpp = (g_server_depth + 7) / 8; /* bytes per pixel */
760 out_uint8s(s, 24); /* unused */
761 out_uint16_le(s, 0x258); /* entries */
762 out_uint16_le(s, 0x100 * Bpp); /* max cell size */
763 out_uint16_le(s, 0x12c); /* entries */
764 out_uint16_le(s, 0x400 * Bpp); /* max cell size */
765 out_uint16_le(s, 0x106); /* entries */
766 out_uint16_le(s, 0x1000 * Bpp); /* max cell size */
767}
#define RDP_CAPSET_BMPCACHE
Definition: constants.h:304
#define RDP_CAPLEN_BMPCACHE
Definition: constants.h:305

Referenced by rdp_send_confirm_active().

◆ rdp_out_brushcache_caps()

static void rdp_out_brushcache_caps ( STREAM  s)
static

Definition at line 867 of file rdp.c.

868{
871 out_uint32_le(s, 1); /* cache type */
872}
#define RDP_CAPSET_BRUSHCACHE
Definition: constants.h:323
#define RDP_CAPLEN_BRUSHCACHE
Definition: constants.h:324

Referenced by rdp_send_confirm_active().

◆ rdp_out_colcache_caps()

static void rdp_out_colcache_caps ( STREAM  s)
static

Definition at line 856 of file rdp.c.

857{
860
861 out_uint16_le(s, 6); /* cache size */
862 out_uint16(s, 0); /* pad */
863}
#define RDP_CAPLEN_COLCACHE
Definition: constants.h:321
#define RDP_CAPSET_COLCACHE
Definition: constants.h:320

Referenced by rdp_send_confirm_active().

◆ rdp_out_control_caps()

static void rdp_out_control_caps ( STREAM  s)
static

Definition at line 796 of file rdp.c.

797{
800
801 out_uint16(s, 0); /* Control capabilities */
802 out_uint16(s, 0); /* Remote detach */
803 out_uint16_le(s, 2); /* Control interest */
804 out_uint16_le(s, 2); /* Detach interest */
805}
#define RDP_CAPLEN_CONTROL
Definition: constants.h:308
#define RDP_CAPSET_CONTROL
Definition: constants.h:307

Referenced by rdp_send_confirm_active().

◆ rdp_out_general_caps()

static void rdp_out_general_caps ( STREAM  s)
static

Definition at line 664 of file rdp.c.

665{
668
669 out_uint16_le(s, 1); /* OS major type */
670 out_uint16_le(s, 3); /* OS minor type */
671 out_uint16_le(s, 0x200); /* Protocol version */
672 out_uint16(s, 0); /* Pad */
673 out_uint16(s, 0); /* Compression types */
674 out_uint16_le(s, (g_rdp_version >= RDP_V5) ? 0x40d : 0);
675 /* Pad, according to T.128. 0x40d seems to
676 trigger
677 the server to start sending RDP5 packets.
678 However, the value is 0x1d04 with W2KTSK and
679 NT4MS. Hmm.. Anyway, thankyou, Microsoft,
680 for sending such information in a padding
681 field.. */
682 out_uint16(s, 0); /* Update capability */
683 out_uint16(s, 0); /* Remote unshare capability */
684 out_uint16(s, 0); /* Compression level */
685 out_uint16(s, 0); /* Pad */
686}
#define RDP_CAPLEN_GENERAL
Definition: constants.h:292
#define RDP_CAPSET_GENERAL
Definition: constants.h:291

Referenced by rdp_send_confirm_active().

◆ rdp_out_newpointer_caps()

static void rdp_out_newpointer_caps ( STREAM  s)
static

Definition at line 833 of file rdp.c.

834{
837
838 out_uint16_le(s, 1); /* Colour pointer */
839 out_uint16_le(s, 20); /* Cache size */
840 out_uint16_le(s, 20); /* Cache size for new pointers */
841}
#define RDP_CAPLEN_NEWPOINTER
Definition: constants.h:315
#define RDP_CAPSET_POINTER
Definition: constants.h:313

Referenced by rdp_send_confirm_active().

◆ rdp_out_order_caps()

static void rdp_out_order_caps ( STREAM  s)
static

Definition at line 711 of file rdp.c.

712{
713 uint8 order_caps[32];
714
715 memset(order_caps, 0, 32);
716 order_caps[0] = 1; /* dest blt */
717 order_caps[1] = 1; /* pat blt */
718 order_caps[2] = 1; /* screen blt */
719 order_caps[3] = (g_bitmap_cache ? 1 : 0); /* memblt */
720 order_caps[4] = 0; /* triblt */
721 order_caps[8] = 1; /* line */
722 order_caps[9] = 1; /* line */
723 order_caps[10] = 1; /* rect */
724 order_caps[11] = (g_desktop_save ? 1 : 0); /* desksave */
725 order_caps[13] = 1; /* memblt */
726 order_caps[14] = 1; /* triblt */
727 order_caps[20] = (g_polygon_ellipse_orders ? 1 : 0); /* polygon */
728 order_caps[21] = (g_polygon_ellipse_orders ? 1 : 0); /* polygon2 */
729 order_caps[22] = 1; /* polyline */
730 order_caps[25] = (g_polygon_ellipse_orders ? 1 : 0); /* ellipse */
731 order_caps[26] = (g_polygon_ellipse_orders ? 1 : 0); /* ellipse2 */
732 order_caps[27] = 1; /* text2 */
735
736 out_uint8s(s, 20); /* Terminal desc, pad */
737 out_uint16_le(s, 1); /* Cache X granularity */
738 out_uint16_le(s, 20); /* Cache Y granularity */
739 out_uint16(s, 0); /* Pad */
740 out_uint16_le(s, 1); /* Max order level */
741 out_uint16_le(s, 0x147); /* Number of fonts */
742 out_uint16_le(s, 0x2a); /* Capability flags */
743 out_uint8p(s, order_caps, 32); /* Orders supported */
744 out_uint16_le(s, 0x6a1); /* Text capability flags */
745 out_uint8s(s, 6); /* Pad */
746 out_uint32_le(s, g_desktop_save == False ? 0 : 0x38400); /* Desktop cache size */
747 out_uint32(s, 0); /* Unknown */
748 out_uint32_le(s, 0x4e4); /* Unknown */
749}
#define RDP_CAPSET_ORDER
Definition: constants.h:299
#define RDP_CAPLEN_ORDER
Definition: constants.h:300
#define out_uint8p(s, v, n)
Definition: parse.h:93
#define out_uint32(s, v)
Definition: parse.h:85
RD_BOOL g_bitmap_cache
Definition: uimain.c:39
RD_BOOL g_desktop_save
Definition: uimain.c:32
RD_BOOL g_polygon_ellipse_orders
Definition: uimain.c:33

Referenced by rdp_send_confirm_active().

◆ rdp_out_pointer_caps()

static void rdp_out_pointer_caps ( STREAM  s)
static

Definition at line 822 of file rdp.c.

823{
826
827 out_uint16(s, 0); /* Colour pointer */
828 out_uint16_le(s, 20); /* Cache size */
829}
#define RDP_CAPLEN_POINTER
Definition: constants.h:314

Referenced by rdp_send_confirm_active().

◆ rdp_out_share_caps()

static void rdp_out_share_caps ( STREAM  s)
static

Definition at line 845 of file rdp.c.

846{
849
850 out_uint16(s, 0); /* userid */
851 out_uint16(s, 0); /* pad */
852}
#define RDP_CAPLEN_SHARE
Definition: constants.h:318
#define RDP_CAPSET_SHARE
Definition: constants.h:317

Referenced by rdp_send_confirm_active().

◆ rdp_out_unistr()

void rdp_out_unistr ( STREAM  s,
char string,
int  len 
)

Definition at line 188 of file rdp.c.

189{
190 if (string == NULL || len == 0)
191 return;
192
193#ifdef HAVE_ICONV
194 size_t ibl = strlen(string), obl = len + 2;
195 static iconv_t iconv_h = (iconv_t) - 1;
196 char *pin = string, *pout = (char *) s->p;
197
198 memset(pout, 0, len + 4);
199
200 if (g_iconv_works)
201 {
202 if (iconv_h == (iconv_t) - 1)
203 {
204 size_t i = 1, o = 4;
205 if ((iconv_h = iconv_open(WINDOWS_CODEPAGE, g_codepage)) == (iconv_t) - 1)
206 {
207 warning("rdp_out_unistr: iconv_open[%s -> %s] fail %d\n",
208 g_codepage, WINDOWS_CODEPAGE, (int) iconv_h);
209
210 g_iconv_works = False;
211 rdp_out_unistr(s, string, len);
212 return;
213 }
214 if (iconv(iconv_h, (ICONV_CONST char **) &pin, &i, &pout, &o) ==
215 (size_t) - 1)
216 {
217 iconv_close(iconv_h);
218 iconv_h = (iconv_t) - 1;
219 warning("rdp_out_unistr: iconv(1) fail, errno %d\n", errno);
220
221 g_iconv_works = False;
222 rdp_out_unistr(s, string, len);
223 return;
224 }
225 pin = string;
226 pout = (char *) s->p;
227 }
228
229 if (iconv(iconv_h, (ICONV_CONST char **) &pin, &ibl, &pout, &obl) == (size_t) - 1)
230 {
231 iconv_close(iconv_h);
232 iconv_h = (iconv_t) - 1;
233 warning("rdp_out_unistr: iconv(2) fail, errno %d\n", errno);
234
235 g_iconv_works = False;
236 rdp_out_unistr(s, string, len);
237 return;
238 }
239
240 s->p += len + 2;
241
242 }
243 else
244#endif
245 {
246 int i = 0, j = 0;
247
248 len += 2;
249
250 while (i < len)
251 {
252 s->p[i++] = string[j++];
253 s->p[i++] = 0;
254 }
255
256 s->p += len;
257 }
258}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
void rdp_out_unistr(STREAM s, char *string, int len)
Definition: rdp.c:188
__kernel_size_t size_t
Definition: linux.h:237
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
int iconv_close(iconv_t cd)
Definition: win_iconv.c:756

Referenced by disk_query_directory(), disk_query_volume_information(), rdp_out_unistr(), rdp_out_unistr_mandatory_null(), rdp_send_logon_info(), rdpdr_send_available(), rdpdr_send_name(), and sec_out_mcs_data().

◆ rdp_out_unistr_mandatory_null()

void rdp_out_unistr_mandatory_null ( STREAM  s,
char string,
int  len 
)

Definition at line 178 of file rdp.c.

179{
180 if (string && len > 0)
181 rdp_out_unistr(s, string, len);
182 else
183 out_uint16_le(s, 0);
184}

Referenced by rdp_send_logon_info().

◆ rdp_out_unknown_caps()

static void rdp_out_unknown_caps ( STREAM  s,
uint16  id,
uint16  length,
uint8 caps 
)
static

Definition at line 903 of file rdp.c.

904{
905 out_uint16_le(s, id);
907
908 out_uint8p(s, caps, length - 4);
909}
GLuint GLsizei GLsizei * length
Definition: glext.h:6040

Referenced by rdp_send_confirm_active().

◆ rdp_process_bitmap_caps()

static void rdp_process_bitmap_caps ( STREAM  s)
static

Definition at line 995 of file rdp.c.

996{
998
1000 in_uint8s(s, 6);
1001
1004
1005 DEBUG(("setting desktop size and depth to: %dx%dx%d\n", width, height, depth));
1006
1007 /*
1008 * The server may limit depth and change the size of the desktop (for
1009 * example when shadowing another session).
1010 */
1011 if (g_server_depth != depth)
1012 {
1013 warning("Remote desktop does not support colour depth %d; falling back to %d\n",
1016 }
1017 if (g_width != width || g_height != height)
1018 {
1019 warning("Remote desktop changed from %dx%d to %dx%d.\n", g_width, g_height,
1020 width, height);
1021 g_width = width;
1022 g_height = height;
1024 }
1025}
void ui_resize_window(void)
Definition: uimain.c:651
int g_width
Definition: uimain.c:42
int g_height
Definition: uimain.c:43
GLint GLint GLsizei GLsizei GLsizei depth
Definition: gl.h:1546

Referenced by rdp_process_server_caps().

◆ rdp_process_general_caps()

static void rdp_process_general_caps ( STREAM  s)
static

Definition at line 982 of file rdp.c.

983{
984 uint16 pad2octetsB; /* rdp5 flags? */
985
986 in_uint8s(s, 10);
987 in_uint16_le(s, pad2octetsB);
988
989 if (!pad2octetsB)
991}
@ RDP_V4
Definition: types.h:43

Referenced by rdp_process_server_caps().

◆ rdp_process_server_caps()

static void rdp_process_server_caps ( STREAM  s,
uint16  length 
)
static

Definition at line 1029 of file rdp.c.

1030{
1031 int n;
1032 uint8 *next, *start;
1033 uint16 ncapsets, capset_type, capset_length;
1034
1035 start = s->p;
1036
1037 in_uint16_le(s, ncapsets);
1038 in_uint8s(s, 2); /* pad */
1039
1040 for (n = 0; n < ncapsets; n++)
1041 {
1042 if (s->p > start + length)
1043 return;
1044
1045 in_uint16_le(s, capset_type);
1046 in_uint16_le(s, capset_length);
1047
1048 next = s->p + capset_length - 4;
1049
1050 switch (capset_type)
1051 {
1052 case RDP_CAPSET_GENERAL:
1054 break;
1055
1056 case RDP_CAPSET_BITMAP:
1058 break;
1059 }
1060
1061 s->p = next;
1062 }
1063}
static void rdp_process_bitmap_caps(STREAM s)
Definition: rdp.c:995
static void rdp_process_general_caps(STREAM s)
Definition: rdp.c:982
GLuint start
Definition: gl.h:1545
GLdouble n
Definition: glext.h:7729
static unsigned __int64 next
Definition: rand_nt.c:6

Referenced by process_demand_active().

◆ rdp_recv()

static STREAM rdp_recv ( uint8 type)
static

Definition at line 85 of file rdp.c.

86{
87 static STREAM rdp_s;
88 uint16 length, pdu_type;
89 uint8 rdpver;
90
91 if ((rdp_s == NULL) || (g_next_packet >= rdp_s->end) || (g_next_packet == NULL))
92 {
93 rdp_s = sec_recv(&rdpver);
94 if (rdp_s == NULL)
95 return NULL;
96 if (rdpver == 0xff)
97 {
98 g_next_packet = rdp_s->end;
99 *type = 0;
100 return rdp_s;
101 }
102 else if (rdpver != 3)
103 {
104 /* rdp5_process should move g_next_packet ok */
105 rdp5_process(rdp_s);
106 *type = 0;
107 return rdp_s;
108 }
109
110 g_next_packet = rdp_s->p;
111 }
112 else
113 {
114 rdp_s->p = g_next_packet;
115 }
116
117 in_uint16_le(rdp_s, length);
118 /* 32k packets are really 8, keepalive fix */
119 if (length == 0x8000)
120 {
121 g_next_packet += 8;
122 *type = 0;
123 return rdp_s;
124 }
125 in_uint16_le(rdp_s, pdu_type);
126 in_uint8s(rdp_s, 2); /* userid */
127 *type = pdu_type & 0xf;
128
129#ifdef WITH_DEBUG
130 DEBUG(("RDP packet #%d, (type %x)\n", ++g_packetno, *type));
132#endif /* */
133
135 return rdp_s;
136}
void rdp5_process(STREAM s)
Definition: rdp5.c:28
void hexdump(unsigned char *p, unsigned int len)
Definition: shimdbg.c:234
STREAM sec_recv(uint8 *rdpver)
Definition: secure.c:903
unsigned char * end
Definition: parse.h:25
unsigned char * p
Definition: parse.h:24

Referenced by process_demand_active(), and rdp_loop().

◆ rdp_reset_state()

void rdp_reset_state ( void  )

Definition at line 1770 of file rdp.c.

1771{
1772 g_next_packet = NULL; /* reset the packet information */
1773 g_rdp_shareid = 0;
1775}
void sec_reset_state(void)
Definition: secure.c:1039

Referenced by SEALED_::ProtocolLoop(), and rdesktop_reset_state().

◆ rdp_send_client_window_status()

void rdp_send_client_window_status ( int  status)

Definition at line 572 of file rdp.c.

573{
574 STREAM s;
575 static int current_status = 1;
576
577 if (current_status == status)
578 return;
579
580 s = rdp_init_data(12);
581
583
584 switch (status)
585 {
586 case 0: /* shut the server up */
587 break;
588
589 case 1: /* receive data again */
590 out_uint32_le(s, 0); /* unknown */
593 break;
594 }
595
596 s_mark_end(s);
598 current_status = status;
599}
@ RDP_DATA_PDU_CLIENT_WINDOW_STATUS
Definition: constants.h:176
Definition: ps.c:97

Referenced by xwin_process_events().

◆ rdp_send_confirm_active()

static void rdp_send_confirm_active ( void  )
static

Definition at line 914 of file rdp.c.

915{
916 STREAM s;
918 uint16 caplen =
923 RDP_CAPLEN_BRUSHCACHE + 0x58 + 0x08 + 0x08 + 0x34 /* unknown caps */ +
924 4 /* w2k fix, sessionid */ ;
925
926 if (g_rdp_version >= RDP_V5)
927 {
928 caplen += RDP_CAPLEN_BMPCACHE2;
929 caplen += RDP_CAPLEN_NEWPOINTER;
930 }
931 else
932 {
933 caplen += RDP_CAPLEN_BMPCACHE;
934 caplen += RDP_CAPLEN_POINTER;
935 }
936
937 s = sec_init(sec_flags, 6 + 14 + caplen + sizeof(RDP_SOURCE));
938
939 out_uint16_le(s, 2 + 14 + caplen + sizeof(RDP_SOURCE));
940 out_uint16_le(s, (RDP_PDU_CONFIRM_ACTIVE | 0x10)); /* Version 1 */
941 out_uint16_le(s, (g_mcs_userid + 1001));
942
944 out_uint16_le(s, 0x3ea); /* userid */
945 out_uint16_le(s, sizeof(RDP_SOURCE));
946 out_uint16_le(s, caplen);
947
949 out_uint16_le(s, 0xe); /* num_caps */
950 out_uint8s(s, 2); /* pad */
951
955 if (g_rdp_version >= RDP_V5)
956 {
959 }
960 else
961 {
964 }
970
971 rdp_out_unknown_caps(s, 0x0d, 0x58, caps_0x0d); /* CAPSTYPE_INPUT */
972 rdp_out_unknown_caps(s, 0x0c, 0x08, caps_0x0c); /* CAPSTYPE_SOUND */
973 rdp_out_unknown_caps(s, 0x0e, 0x08, caps_0x0e); /* CAPSTYPE_FONT */
974 rdp_out_unknown_caps(s, 0x10, 0x34, caps_0x10); /* CAPSTYPE_GLYPHCACHE */
975
976 s_mark_end(s);
977 sec_send(s, sec_flags);
978}
#define RDP_SOURCE
Definition: constants.h:330
@ RDP_PDU_CONFIRM_ACTIVE
Definition: constants.h:161
void sec_send(STREAM s, uint32 flags)
Definition: secure.c:472
static uint8 caps_0x0e[]
Definition: rdp.c:890
static void rdp_out_bmpcache_caps(STREAM s)
Definition: rdp.c:753
static void rdp_out_unknown_caps(STREAM s, uint16 id, uint16 length, uint8 *caps)
Definition: rdp.c:903
static void rdp_out_activate_caps(STREAM s)
Definition: rdp.c:809
static void rdp_out_bitmap_caps(STREAM s)
Definition: rdp.c:690
static void rdp_out_order_caps(STREAM s)
Definition: rdp.c:711
static void rdp_out_control_caps(STREAM s)
Definition: rdp.c:796
static void rdp_out_general_caps(STREAM s)
Definition: rdp.c:664
static uint8 caps_0x0c[]
Definition: rdp.c:888
static void rdp_out_pointer_caps(STREAM s)
Definition: rdp.c:822
static void rdp_out_share_caps(STREAM s)
Definition: rdp.c:845
static void rdp_out_brushcache_caps(STREAM s)
Definition: rdp.c:867
static void rdp_out_newpointer_caps(STREAM s)
Definition: rdp.c:833
static void rdp_out_bmpcache2_caps(STREAM s)
Definition: rdp.c:771
static uint8 caps_0x10[]
Definition: rdp.c:892
#define RDP5_FLAG
Definition: rdp.c:911
static void rdp_out_colcache_caps(STREAM s)
Definition: rdp.c:856
uint16 g_mcs_userid
Definition: mcs.c:23
static uint8 caps_0x0d[]
Definition: rdp.c:874

Referenced by process_demand_active().

◆ rdp_send_control()

static void rdp_send_control ( uint16  action)
static

Definition at line 520 of file rdp.c.

521{
522 STREAM s;
523
524 s = rdp_init_data(8);
525
527 out_uint16(s, 0); /* userid */
528 out_uint32(s, 0); /* control id */
529
530 s_mark_end(s);
532}
const WCHAR * action
Definition: action.c:7509

Referenced by process_demand_active().

◆ rdp_send_data()

static void rdp_send_data ( STREAM  s,
uint8  data_pdu_type 
)
static

Definition at line 152 of file rdp.c.

153{
155
156 s_pop_layer(s, rdp_hdr);
157 length = s->end - s->p;
158
160 out_uint16_le(s, (RDP_PDU_DATA | 0x10));
161 out_uint16_le(s, (g_mcs_userid + 1001));
162
164 out_uint8(s, 0); /* pad */
165 out_uint8(s, 1); /* streamid */
166 out_uint16_le(s, (length - 14));
167 out_uint8(s, data_pdu_type);
168 out_uint8(s, 0); /* compress_type */
169 out_uint16(s, 0); /* compress_len */
170
172}
#define s_pop_layer(s, h)
Definition: parse.h:40
#define out_uint8(s, v)
Definition: parse.h:92

Referenced by rdp_enum_bmpcache2(), rdp_send_client_window_status(), rdp_send_control(), rdp_send_fonts(), rdp_send_input(), and rdp_send_synchronise().

◆ rdp_send_fonts()

static void rdp_send_fonts ( uint16  seq)
static

Definition at line 647 of file rdp.c.

648{
649 STREAM s;
650
651 s = rdp_init_data(8);
652
653 out_uint16(s, 0); /* number of fonts */
654 out_uint16_le(s, 0); /* pad? */
655 out_uint16_le(s, seq); /* unknown */
656 out_uint16_le(s, 0x32); /* entry size */
657
658 s_mark_end(s);
660}
@ RDP_DATA_PDU_FONT2
Definition: constants.h:178

Referenced by process_demand_active().

◆ rdp_send_input()

◆ rdp_send_logon_info()

static void rdp_send_logon_info ( uint32  flags,
char domain,
char user,
char password,
char program,
char directory 
)
static

Definition at line 343 of file rdp.c.

345{
346 char *ipaddr = tcp_get_address();
347 /* length of string in TS_INFO_PACKET excludes null terminator */
348 int len_domain = 2 * strlen(domain);
349 int len_user = 2 * strlen(user);
350 int len_password = 2 * strlen(password);
351 int len_program = 2 * strlen(program);
352 int len_directory = 2 * strlen(directory);
353
354 /* length of strings in TS_EXTENDED_PACKET includes null terminator */
355 char dllName[MAX_PATH];
356 int len_ip = 2 * strlen(ipaddr) + 2;
357 int len_dll = 0;
358
359 int packetlen = 0;
361 STREAM s;
362 time_t t = time(NULL);
363 time_t tzone;
364 uint8 security_verifier[16];
365
366 GetModuleFileNameA(NULL, dllName, ARRAYSIZE(dllName));
367 len_dll = 2 * strlen(dllName) + 2;
368
370 {
371 DEBUG_RDP5(("Sending RDP4-style Logon packet\n"));
372
373 s = sec_init(sec_flags, 18 + len_domain + len_user + len_password
374 + len_program + len_directory + 10);
375
376 out_uint32(s, 0);
378 out_uint16_le(s, len_domain);
379 out_uint16_le(s, len_user);
380 out_uint16_le(s, len_password);
381 out_uint16_le(s, len_program);
382 out_uint16_le(s, len_directory);
383
389 }
390 else
391 {
392 DEBUG_RDP5(("Sending RDP5-style Logon packet\n"));
393
395 {
397 len_password = g_redirect_cookie_len;
398 len_password -= 2; /* substract 2 bytes which is added below */
399 }
400
401 packetlen =
402 /* size of TS_INFO_PACKET */
403 4 + /* CodePage */
404 4 + /* flags */
405 2 + /* cbDomain */
406 2 + /* cbUserName */
407 2 + /* cbPassword */
408 2 + /* cbAlternateShell */
409 2 + /* cbWorkingDir */
410 2 + len_domain + /* Domain */
411 2 + len_user + /* UserName */
412 2 + len_password + /* Password */
413 2 + len_program + /* AlternateShell */
414 2 + len_directory + /* WorkingDir */
415 /* size of TS_EXTENDED_INFO_PACKET */
416 2 + /* clientAddressFamily */
417 2 + /* cbClientAddress */
418 len_ip + /* clientAddress */
419 2 + /* cbClientDir */
420 len_dll + /* clientDir */
421 /* size of TS_TIME_ZONE_INFORMATION */
422 4 + /* Bias, (UTC = local time + bias */
423 64 + /* StandardName, 32 unicode char array, Descriptive standard time on client */
424 16 + /* StandardDate */
425 4 + /* StandardBias */
426 64 + /* DaylightName, 32 unicode char array */
427 16 + /* DaylightDate */
428 4 + /* DaylightBias */
429 4 + /* clientSessionId */
430 4 + /* performanceFlags */
431 2 + /* cbAutoReconnectCookie, either 0 or 0x001c */
432 /* size of ARC_CS_PRIVATE_PACKET */
433 28; /* autoReconnectCookie */
434
435
436 s = sec_init(sec_flags, packetlen);
437 DEBUG_RDP5(("Called sec_init with packetlen %d\n", packetlen));
438
439 /* TS_INFO_PACKET */
440 out_uint32(s, 0); /* Code Page */
442 out_uint16_le(s, len_domain);
443 out_uint16_le(s, len_user);
444 out_uint16_le(s, len_password);
445 out_uint16_le(s, len_program);
446 out_uint16_le(s, len_directory);
447
450
452 {
454 }
455 else
456 {
458 }
459
460
463
464 /* TS_EXTENDED_INFO_PACKET */
465 out_uint16_le(s, 2); /* clientAddressFamily = AF_INET */
466 out_uint16_le(s, len_ip); /* cbClientAddress */
467 rdp_out_unistr_mandatory_null(s, ipaddr, len_ip - 2); /* clientAddress */
468 out_uint16_le(s, len_dll); /* cbClientDir */
469 rdp_out_unistr(s, dllName, len_dll - 2); /* clientDir */
470
471 /* TS_TIME_ZONE_INFORMATION */
472 tzone = (mktime(gmtime(&t)) - mktime(localtime(&t))) / 60;
473 out_uint32_le(s, tzone);
474 rdp_out_unistr(s, "GTB, normaltid", 2 * strlen("GTB, normaltid"));
475 out_uint8s(s, 62 - 2 * strlen("GTB, normaltid"));
476 out_uint32_le(s, 0x0a0000);
477 out_uint32_le(s, 0x050000);
478 out_uint32_le(s, 3);
479 out_uint32_le(s, 0);
480 out_uint32_le(s, 0);
481 rdp_out_unistr(s, "GTB, sommartid", 2 * strlen("GTB, sommartid"));
482 out_uint8s(s, 62 - 2 * strlen("GTB, sommartid"));
483 out_uint32_le(s, 0x30000);
484 out_uint32_le(s, 0x050000);
485 out_uint32_le(s, 2);
486 out_uint32(s, 0);
487 out_uint32_le(s, 0xffffffc4); /* DaylightBias */
488
489 /* Rest of TS_EXTENDED_INFO_PACKET */
490 out_uint32_le(s, 0); /* clientSessionId (Ignored by server MUST be 0) */
492
493 /* Client Auto-Reconnect */
495 {
496 out_uint16_le(s, 28); /* cbAutoReconnectLen */
497 /* ARC_CS_PRIVATE_PACKET */
498 out_uint32_le(s, 28); /* cbLen */
499 out_uint32_le(s, 1); /* Version */
500 out_uint32_le(s, g_reconnect_logonid); /* LogonId */
502 (char *)g_client_random, SEC_RANDOM_SIZE, (char *)security_verifier);
503 out_uint8a(s, security_verifier, sizeof(security_verifier));
504 }
505 else
506 {
507 out_uint16_le(s, 0); /* cbAutoReconnectLen */
508 }
509 }
510 s_mark_end(s);
511
512 /* clear the redirect flag */
514
515 sec_send(s, sec_flags);
516}
#define SEC_INFO_PKT
Definition: constants.h:104
#define RDP_INFO_AUTOLOGON
Definition: constants.h:335
#define SEC_RANDOM_SIZE
Definition: constants.h:91
char * tcp_get_address(void)
Definition: tcp.c:866
void rdssl_hmac_md5(char *key, int keylen, char *data, int len, char *output)
Definition: ssl_calls.c:449
uint16 g_server_rdp_version
Definition: secure.c:105
uint32 g_rdp5_performanceflags
Definition: uimain.c:35
void rdp_out_unistr_mandatory_null(STREAM s, char *string, int len)
Definition: rdp.c:178
uint8 g_client_random[SEC_RANDOM_SIZE]
Definition: uimain.c:78
void user(int argc, const char *argv[])
Definition: cmds.c:1350
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define MAX_PATH
Definition: compat.h:34
DWORD WINAPI GetModuleFileNameA(HINSTANCE hModule, LPSTR lpFilename, DWORD nSize)
Definition: loader.c:539
__kernel_time_t time_t
Definition: linux.h:252
GLdouble GLdouble t
Definition: gl.h:2047
GLuint program
Definition: glext.h:6723
_CRTIMP struct tm *__cdecl gmtime(const time_t *_Time)
Definition: time.h:415
_CRTIMP time_t __cdecl mktime(struct tm *_Tm)
Definition: time.h:418
_CRTIMP struct tm *__cdecl localtime(const time_t *_Time)
Definition: time.h:416

Referenced by rdp_connect(), and rdp_reconnect().

◆ rdp_send_synchronise()

static void rdp_send_synchronise ( void  )
static

Definition at line 536 of file rdp.c.

537{
538 STREAM s;
539
540 s = rdp_init_data(4);
541
542 out_uint16_le(s, 1); /* type */
543 out_uint16_le(s, 1002);
544
545 s_mark_end(s);
547}

Referenced by process_demand_active().

◆ rdssl_hmac_md5()

void rdssl_hmac_md5 ( char key,
int  keylen,
char data,
int  len,
char output 
)

Definition at line 449 of file ssl_calls.c.

450{
451 HCRYPTPROV hCryptProv;
454 BOOL ret;
455 DWORD dwErr, dwDataLen;
457 BYTE * blob;
459 DWORD * keySize;
460 BYTE * keyBuf;
461 BYTE sum[16];
462
463 if (!key || !keylen || !data || !len ||!output)
464 {
465 error("rdssl_hmac_md5 %p %d %p %d %p\n", key, keylen, data, len, output);
466 return;
467 }
468 blob = g_malloc(sizeof(PUBLICKEYSTRUC) + sizeof(DWORD) + keylen, 0);
470 keySize = (DWORD *)(blob + sizeof(PUBLICKEYSTRUC));
471 keyBuf = blob + sizeof(PUBLICKEYSTRUC) + sizeof(DWORD);
472 if (!blob)
473 {
474 error("rdssl_hmac_md5 %d no memory\n");
475 return;
476 }
477 ret = CryptAcquireContext(&hCryptProv,
478 L"MSTSC",
481 0);
482 if (!ret)
483 {
485 if (dwErr == NTE_BAD_KEYSET)
486 {
487 ret = CryptAcquireContext(&hCryptProv,
488 L"MSTSC",
492 }
493 }
494 if (!ret)
495 {
497 g_free(blob);
498 error("CryptAcquireContext failed with %lx\n", dwErr);
499 return;
500 }
501 desc->aiKeyAlg = CALG_RC4;
502 desc->bType = PLAINTEXTKEYBLOB;
503 desc->bVersion = CUR_BLOB_VERSION;
504 desc->reserved = 0;
505 if (keylen > 64)
506 {
508 ret = CryptCreateHash(hCryptProv,
509 CALG_MD5,
510 0,
511 0,
512 &hHash);
513 if (!ret)
514 {
516 g_free(blob);
517 error("CryptCreateHash failed with %lx\n", dwErr);
518 return;
519 }
521 (BYTE *)key,
522 keylen,
523 0);
524 if (!ret)
525 {
527 g_free(blob);
528 error("CryptHashData failed with %lx\n", dwErr);
529 return;
530 }
533 NULL,
534 &dwDataLen,
535 0);
536 if (!ret)
537 {
539 g_free(blob);
540 error("CryptGetHashParam failed with %lx\n", dwErr);
541 return;
542 }
545 sum,
546 &dwDataLen,
547 0);
548 if (!ret)
549 {
551 g_free(blob);
552 error("CryptGetHashParam failed with %lx\n", dwErr);
553 return;
554 }
555 keylen = dwDataLen;
556 key = (char *)sum;
557 }
558 *keySize = keylen;
559 memcpy(keyBuf, key, keylen);
560 ret = CryptImportKey(hCryptProv,
561 blob,
562 sizeof(PUBLICKEYSTRUC) + sizeof(DWORD) + keylen,
563 0,
565 &hKey);
566 g_free(blob);
567 if (!ret)
568 {
570 error("CryptImportKey failed with %lx\n", dwErr);
571 return;
572 }
573 ret = CryptCreateHash(hCryptProv,
574 CALG_HMAC,
575 hKey,
576 0,
577 &hHash);
578 if (!ret)
579 {
581 error("CryptCreateHash failed with %lx\n", dwErr);
582 return;
583 }
584 info.HashAlgid = CALG_MD5;
585 info.cbInnerString = 0;
586 info.cbOuterString = 0;
589 (BYTE *)&info,
590 0);
591 if (!ret)
592 {
594 error("CryptSetHashParam failed with %lx\n", dwErr);
595 return;
596 }
598 (BYTE *)data,
599 len,
600 0);
601 if (!ret)
602 {
604 error("CryptHashData failed with %lx\n", dwErr);
605 return;
606 }
609 NULL,
610 &dwDataLen,
611 0);
612 if (!ret)
613 {
615 error("CryptGetHashParam failed with %lx\n", dwErr);
616 return;
617 }
620 (BYTE *)output,
621 &dwDataLen,
622 0);
623 if (!ret)
624 {
626 error("CryptGetHashParam failed with %lx\n", dwErr);
627 return;
628 }
630 ret = CryptReleaseContext(hCryptProv, 0);
631}
static FN_RtlMultipleFreeHeap g_free
DWORD dwErr
Definition: service.c:36
BOOL WINAPI CryptCreateHash(HCRYPTPROV hProv, ALG_ID Algid, HCRYPTKEY hKey, DWORD dwFlags, HCRYPTHASH *phHash)
Definition: crypt.c:740
BOOL WINAPI CryptGetHashParam(HCRYPTHASH hHash, DWORD dwParam, BYTE *pbData, DWORD *pdwDataLen, DWORD dwFlags)
Definition: crypt.c:1610
BOOL WINAPI CryptDestroyHash(HCRYPTHASH hHash)
Definition: crypt.c:890
BOOL WINAPI CryptReleaseContext(HCRYPTPROV hProv, DWORD dwFlags)
Definition: crypt.c:648
BOOL WINAPI CryptHashData(HCRYPTHASH hHash, const BYTE *pbData, DWORD dwDataLen, DWORD dwFlags)
Definition: crypt.c:1771
BOOL WINAPI CryptSetHashParam(HCRYPTHASH hHash, DWORD dwParam, const BYTE *pbData, DWORD dwFlags)
Definition: crypt.c:1970
BOOL WINAPI CryptImportKey(HCRYPTPROV hProv, const BYTE *pbData, DWORD dwDataLen, HCRYPTKEY hPubKey, DWORD dwFlags, HCRYPTKEY *phKey)
Definition: crypt.c:1850
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
static const WCHAR desc[]
Definition: protectdata.c:36
#define L(x)
Definition: ntvdm.h:50
static int sum(int x_, int y_)
Definition: ptr2_test.cpp:35
static void * g_malloc(int size, int zero)
Definition: ssl_calls.c:26
Definition: image.c:134
Definition: copy.c:22
int ret
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define PLAINTEXTKEYBLOB
Definition: wincrypt.h:2242
#define CRYPT_NEWKEYSET
Definition: wincrypt.h:2070
#define PROV_RSA_FULL
Definition: wincrypt.h:2039
ULONG_PTR HCRYPTPROV
Definition: wincrypt.h:46
#define CALG_RC4
Definition: wincrypt.h:1837
#define CALG_MD5
Definition: wincrypt.h:1805
struct _PUBLICKEYSTRUC PUBLICKEYSTRUC
_In_ HCRYPTHASH hHash
Definition: wincrypt.h:4198
#define HP_HMAC_INFO
Definition: wincrypt.h:2185
#define MS_ENHANCED_PROV
Definition: wincrypt.h:1886
#define CryptAcquireContext
Definition: wincrypt.h:4164
ULONG_PTR HCRYPTKEY
Definition: wincrypt.h:49
#define CALG_HMAC
Definition: wincrypt.h:1810
#define HP_HASHVAL
Definition: wincrypt.h:2183
#define CRYPT_EXPORTABLE
Definition: wincrypt.h:2206
#define CUR_BLOB_VERSION
Definition: wincrypt.h:2247
#define NTE_BAD_KEYSET
Definition: winerror.h:2890
unsigned char BYTE
Definition: xxhash.c:193

Referenced by rdp_send_logon_info().

Variable Documentation

◆ caps_0x0c

uint8 caps_0x0c[] = { 0x01, 0x00, 0x00, 0x00 }
static

Definition at line 888 of file rdp.c.

Referenced by rdp_send_confirm_active().

◆ caps_0x0d

uint8 caps_0x0d[]
static
Initial value:
= {
0x01, 0x00, 0x00, 0x00, 0x09, 0x04, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00
}

Definition at line 874 of file rdp.c.

Referenced by rdp_send_confirm_active().

◆ caps_0x0e

uint8 caps_0x0e[] = { 0x01, 0x00, 0x00, 0x00 }
static

Definition at line 890 of file rdp.c.

Referenced by rdp_send_confirm_active().

◆ caps_0x10

uint8 caps_0x10[]
static
Initial value:
= {
0xFE, 0x00, 0x04, 0x00, 0xFE, 0x00, 0x04, 0x00,
0xFE, 0x00, 0x08, 0x00, 0xFE, 0x00, 0x08, 0x00,
0xFE, 0x00, 0x10, 0x00, 0xFE, 0x00, 0x20, 0x00,
0xFE, 0x00, 0x40, 0x00, 0xFE, 0x00, 0x80, 0x00,
0xFE, 0x00, 0x00, 0x01, 0x40, 0x00, 0x00, 0x08,
0x00, 0x01, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00
}

Definition at line 892 of file rdp.c.

Referenced by rdp_send_confirm_active().

◆ g_bitmap_cache

RD_BOOL g_bitmap_cache
extern

Definition at line 39 of file uimain.c.

Referenced by rdp_out_order_caps().

◆ g_bitmap_cache_persist_enable

RD_BOOL g_bitmap_cache_persist_enable
extern

Definition at line 37 of file uimain.c.

Referenced by parse_parameters(), and rdp_out_bmpcache2_caps().

◆ g_bitmap_compression

RD_BOOL g_bitmap_compression
extern

Definition at line 34 of file uimain.c.

Referenced by rdp_out_bitmap_caps().

◆ g_client_random

uint8 g_client_random[SEC_RANDOM_SIZE]
extern

Definition at line 78 of file uimain.c.

Referenced by rdp_send_logon_info().

◆ g_codepage

char g_codepage[16]

Definition at line 27 of file rdp.c.

Referenced by rdp_in_unistr(), and rdp_out_unistr().

◆ g_desktop_save

RD_BOOL g_desktop_save
extern

Definition at line 32 of file uimain.c.

Referenced by rdp_out_order_caps().

◆ g_encryption

RD_BOOL g_encryption
extern

◆ g_has_reconnect_random

RD_BOOL g_has_reconnect_random
extern

Definition at line 85 of file uimain.c.

Referenced by process_pdu_logon(), and rdp_send_logon_info().

◆ g_height

◆ g_mcs_userid

◆ g_mppc_dict

RDPCOMP g_mppc_dict
extern

Definition at line 55 of file mppc.c.

Referenced by process_data_pdu().

◆ g_network_error

RD_BOOL g_network_error
extern

Definition at line 77 of file uimain.c.

Referenced by rdp_connect().

◆ g_next_packet

uint8* g_next_packet

Definition at line 45 of file rdp.c.

Referenced by process_orders(), rdp5_process(), rdp_loop(), rdp_recv(), and rdp_reset_state().

◆ g_numlock_sync

RD_BOOL g_numlock_sync
extern

Definition at line 80 of file uimain.c.

Referenced by process_demand_active().

◆ g_orders

RD_BOOL g_orders
extern

◆ g_password

char g_password[256]
extern

Definition at line 28 of file uimain.c.

Referenced by rdp_loop(), and QMyScrollView::timerEvent().

◆ g_pending_resize

RD_BOOL g_pending_resize
extern

Definition at line 79 of file uimain.c.

Referenced by rdp_main_loop().

◆ g_polygon_ellipse_orders

RD_BOOL g_polygon_ellipse_orders
extern

Definition at line 33 of file uimain.c.

Referenced by rdp_out_order_caps().

◆ g_rdp5_performanceflags

uint32 g_rdp5_performanceflags
extern

Definition at line 35 of file uimain.c.

Referenced by rdp_send_logon_info().

◆ g_rdp_shareid

uint32 g_rdp_shareid

◆ g_rdp_version

◆ g_reconnect_logonid

uint32 g_reconnect_logonid
extern

Definition at line 82 of file uimain.c.

Referenced by process_pdu_logon(), and rdp_send_logon_info().

◆ g_reconnect_random

char g_reconnect_random[16]
extern

Definition at line 83 of file uimain.c.

Referenced by process_pdu_logon(), and rdp_send_logon_info().

◆ g_reconnect_random_ts

time_t g_reconnect_random_ts
extern

Definition at line 84 of file uimain.c.

Referenced by process_pdu_logon().

◆ g_redirect

RD_BOOL g_redirect
extern

Definition at line 55 of file uimain.c.

Referenced by process_redirect_pdu(), rdp_connect(), rdp_main_loop(), and rdp_send_logon_info().

◆ g_redirect_cookie

uint8* g_redirect_cookie
extern

Definition at line 64 of file uimain.c.

Referenced by process_redirect_pdu(), and rdp_send_logon_info().

◆ g_redirect_cookie_len

uint32 g_redirect_cookie_len
extern

Definition at line 65 of file uimain.c.

Referenced by process_redirect_pdu(), and rdp_send_logon_info().

◆ g_redirect_domain

char* g_redirect_domain
extern

Definition at line 58 of file uimain.c.

Referenced by process_redirect_pdu().

◆ g_redirect_domain_len

uint32 g_redirect_domain_len
extern

Definition at line 59 of file uimain.c.

Referenced by process_redirect_pdu().

◆ g_redirect_flags

uint32 g_redirect_flags
extern

Definition at line 66 of file uimain.c.

Referenced by process_redirect_pdu().

◆ g_redirect_lb_info

uint8* g_redirect_lb_info
extern

Definition at line 62 of file uimain.c.

Referenced by process_redirect_pdu().

◆ g_redirect_lb_info_len

uint32 g_redirect_lb_info_len
extern

Definition at line 63 of file uimain.c.

Referenced by process_redirect_pdu().

◆ g_redirect_server

char* g_redirect_server
extern

Definition at line 56 of file uimain.c.

Referenced by process_redirect_pdu().

◆ g_redirect_server_len

uint32 g_redirect_server_len
extern

Definition at line 57 of file uimain.c.

Referenced by process_redirect_pdu().

◆ g_redirect_session_id

uint32 g_redirect_session_id
extern

Definition at line 67 of file uimain.c.

Referenced by process_redirect_pdu().

◆ g_redirect_username

char* g_redirect_username
extern

Definition at line 60 of file uimain.c.

Referenced by process_redirect_pdu().

◆ g_redirect_username_len

uint32 g_redirect_username_len
extern

Definition at line 61 of file uimain.c.

Referenced by process_redirect_pdu().

◆ g_server_depth

int g_server_depth
extern

Definition at line 41 of file uimain.c.

Referenced by rdp_out_bitmap_caps(), rdp_out_bmpcache_caps(), and rdp_process_bitmap_caps().

◆ g_server_rdp_version

uint16 g_server_rdp_version
extern

Definition at line 105 of file secure.c.

Referenced by rdp_send_logon_info(), sec_process_srv_info(), and sec_reset_state().

◆ g_username

char g_username[256]
extern

Definition at line 25 of file uimain.c.

Referenced by rdp_connect().

◆ g_width