/[rdesktop]/sourceforge.net/trunk/rdesktop/rdp.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /sourceforge.net/trunk/rdesktop/rdp.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 10 by matty, Tue Aug 15 10:23:24 2000 UTC revision 28 by matty, Wed Jun 20 13:54:48 2001 UTC
# Line 22  Line 22 
22    
23  extern uint16 mcs_userid;  extern uint16 mcs_userid;
24  extern char username[16];  extern char username[16];
25    extern BOOL bitmap_compression;
26  extern BOOL orders;  extern BOOL orders;
27    extern BOOL use_encryption;
28    extern BOOL desktop_save;
29    
30  unsigned char *next_packet;  uint8 *next_packet;
31  uint32 rdp_shareid;  uint32 rdp_shareid;
32    
33  /* Initialise an RDP packet */  /* Initialise an RDP packet */
34  static STREAM rdp_init(int maxlen)  static STREAM
35    rdp_init(int maxlen)
36  {  {
37          STREAM s;          STREAM s;
38    
39          s = sec_init(SEC_ENCRYPT, maxlen + 6);          s = sec_init(use_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;
43  }  }
44    
45  /* Send an RDP packet */  /* Send an RDP packet */
46  static void rdp_send(STREAM s, uint8 pdu_type)  static void
47    rdp_send(STREAM s, uint8 pdu_type)
48  {  {
49          uint16 length;          uint16 length;
50    
# Line 47  static void rdp_send(STREAM s, uint8 pdu Line 52  static void rdp_send(STREAM s, uint8 pdu
52          length = s->end - s->p;          length = s->end - s->p;
53    
54          out_uint16_le(s, length);          out_uint16_le(s, length);
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, SEC_ENCRYPT);          sec_send(s, use_encryption ? SEC_ENCRYPT : 0);
59  }  }
60    
61  /* Receive an RDP packet */  /* Receive an RDP packet */
62  static STREAM rdp_recv(uint8 *type)  static STREAM
63    rdp_recv(uint8 *type)
64  {  {
65          static STREAM rdp_s;          static STREAM rdp_s;
66          uint16 length, pdu_type;          uint16 length, pdu_type;
# Line 74  static STREAM rdp_recv(uint8 *type) Line 80  static STREAM rdp_recv(uint8 *type)
80    
81          in_uint16_le(rdp_s, length);          in_uint16_le(rdp_s, length);
82          in_uint16_le(rdp_s, pdu_type);          in_uint16_le(rdp_s, pdu_type);
83          in_uint8s(rdp_s, 2); /* userid */          in_uint8s(rdp_s, 2);    /* userid */
   
         next_packet += length;  
84          *type = pdu_type & 0xf;          *type = pdu_type & 0xf;
85    
86  #if RDP_DEBUG  #if RDP_DEBUG
87          DEBUG("RDP packet (type %x):\n", *type);          DEBUG("RDP packet (type %x):\n", *type);
88          hexdump(rdp_s->p, length);          hexdump(next_packet, length);
89  #endif  #endif /*  */
90    
91            next_packet += length;
92          return rdp_s;          return rdp_s;
93  }  }
94    
95  /* Initialise an RDP data packet */  /* Initialise an RDP data packet */
96  static STREAM rdp_init_data(int maxlen)  static STREAM
97    rdp_init_data(int maxlen)
98  {  {
99          STREAM s;          STREAM s;
100    
101          s = sec_init(SEC_ENCRYPT, maxlen + 18);          s = sec_init(use_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;
105  }  }
106    
107  /* Send an RDP data packet */  /* Send an RDP data packet */
108  static void rdp_send_data(STREAM s, uint8 data_pdu_type)  static void
109    rdp_send_data(STREAM s, uint8 data_pdu_type)
110  {  {
111          uint16 length;          uint16 length;
112    
# Line 111  static void rdp_send_data(STREAM s, uint Line 118  static void rdp_send_data(STREAM s, uint
118          out_uint16_le(s, (mcs_userid + 1001));          out_uint16_le(s, (mcs_userid + 1001));
119    
120          out_uint32_le(s, rdp_shareid);          out_uint32_le(s, rdp_shareid);
121          out_uint8(s, 0);  /* pad */          out_uint8(s, 0);        /* pad */
122          out_uint8(s, 1);  /* streamid */          out_uint8(s, 1);        /* streamid */
123          out_uint16(s, (length - 14));          out_uint16(s, (length - 14));
124          out_uint8(s, data_pdu_type);          out_uint8(s, data_pdu_type);
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, SEC_ENCRYPT);          sec_send(s, use_encryption ? SEC_ENCRYPT : 0);
129  }  }
130    
131  /* Output a string in Unicode */  /* Output a string in Unicode */
132  void rdp_out_unistr(STREAM s, char *string, int len)  void
133    rdp_out_unistr(STREAM s, char *string, int len)
134  {  {
135          int i = 0, j = 0;          int i = 0, j = 0;
136    
# Line 138  void rdp_out_unistr(STREAM s, char *stri Line 146  void rdp_out_unistr(STREAM s, char *stri
146  }  }
147    
148  /* Parse a logon info packet */  /* Parse a logon info packet */
149  static void rdp_send_logon_info(uint32 flags, char *domain, char *user,  static void
150                                  char *password, char *program, char *directory)  rdp_send_logon_info(uint32 flags, char *domain, char *user,
151  {                      char *password, char *program, char *directory)
152          int len_domain    = 2 * strlen(domain);  {
153          int len_user      = 2 * strlen(user);          int len_domain = 2 * strlen(domain);
154          int len_password  = 2 * strlen(password);          int len_user = 2 * strlen(user);
155          int len_program   = 2 * strlen(program);          int len_password = 2 * strlen(password);
156            int len_program = 2 * strlen(program);
157          int len_directory = 2 * strlen(directory);          int len_directory = 2 * strlen(directory);
158          uint32 sec_flags = SEC_LOGON_INFO | SEC_ENCRYPT;          uint32 sec_flags = use_encryption ? (SEC_LOGON_INFO | SEC_ENCRYPT)
159                                    : SEC_LOGON_INFO;
160          STREAM s;          STREAM s;
161    
162          s = sec_init(sec_flags, 18 + len_domain + len_user + len_password          s = sec_init(sec_flags, 18 + len_domain + len_user + len_password
163                                          + len_program + len_directory + 10);                       + len_program + len_directory + 10);
164    
165          out_uint32(s, 0);          out_uint32(s, 0);
166          out_uint32_le(s, flags);          out_uint32_le(s, flags);
# Line 159  static void rdp_send_logon_info(uint32 f Line 169  static void rdp_send_logon_info(uint32 f
169          out_uint16_le(s, len_password);          out_uint16_le(s, len_password);
170          out_uint16_le(s, len_program);          out_uint16_le(s, len_program);
171          out_uint16_le(s, len_directory);          out_uint16_le(s, len_directory);
172          rdp_out_unistr(s, domain,    len_domain);          rdp_out_unistr(s, domain, len_domain);
173          rdp_out_unistr(s, user,      len_user);          rdp_out_unistr(s, user, len_user);
174          rdp_out_unistr(s, password,  len_password);          rdp_out_unistr(s, password, len_password);
175          rdp_out_unistr(s, program,   len_program);          rdp_out_unistr(s, program, len_program);
176          rdp_out_unistr(s, directory, len_directory);          rdp_out_unistr(s, directory, len_directory);
177    
178          s_mark_end(s);          s_mark_end(s);
# Line 170  static void rdp_send_logon_info(uint32 f Line 180  static void rdp_send_logon_info(uint32 f
180  }  }
181    
182  /* Send a control PDU */  /* Send a control PDU */
183  static void rdp_send_control(uint16 action)  static void
184    rdp_send_control(uint16 action)
185  {  {
186          STREAM s;          STREAM s;
187    
188          s = rdp_init_data(8);          s = rdp_init_data(8);
189    
190          out_uint16_le(s, action);          out_uint16_le(s, action);
191          out_uint16(s, 0); /* userid */          out_uint16(s, 0);       /* userid */
192          out_uint32(s, 0); /* control id */          out_uint32(s, 0);       /* control id */
193    
194          s_mark_end(s);          s_mark_end(s);
195          rdp_send_data(s, RDP_DATA_PDU_CONTROL);          rdp_send_data(s, RDP_DATA_PDU_CONTROL);
196  }  }
197    
198  /* Send a synchronisation PDU */  /* Send a synchronisation PDU */
199  static void rdp_send_synchronise()  static void
200    rdp_send_synchronise()
201  {  {
202          STREAM s;          STREAM s;
203    
204          s = rdp_init_data(4);          s = rdp_init_data(4);
205    
206          out_uint16_le(s, 1); /* type */          out_uint16_le(s, 1);    /* type */
207          out_uint16_le(s, 1002);          out_uint16_le(s, 1002);
208    
209          s_mark_end(s);          s_mark_end(s);
# Line 199  static void rdp_send_synchronise() Line 211  static void rdp_send_synchronise()
211  }  }
212    
213  /* Send a single input event */  /* Send a single input event */
214  void rdp_send_input(uint32 time, uint16 message_type, uint16 device_flags,  void
215                      uint16 param1, uint16 param2)  rdp_send_input(uint32 time, uint16 message_type, uint16 device_flags,
216                   uint16 param1, uint16 param2)
217  {  {
218          STREAM s;          STREAM s;
219    
220          s = rdp_init_data(16);          s = rdp_init_data(16);
221    
222          out_uint16_le(s, 1); /* number of events */          out_uint16_le(s, 1);    /* number of events */
223          out_uint16(s, 0);    /* pad */          out_uint16(s, 0);       /* pad */
224    
225          out_uint32_le(s, time);          out_uint32_le(s, time);
226          out_uint16_le(s, message_type);          out_uint16_le(s, message_type);
# Line 220  void rdp_send_input(uint32 time, uint16 Line 233  void rdp_send_input(uint32 time, uint16
233  }  }
234    
235  /* Send an (empty) font information PDU */  /* Send an (empty) font information PDU */
236  static void rdp_send_fonts(uint16 seq)  static void
237    rdp_send_fonts(uint16 seq)
238  {  {
239          STREAM s;          STREAM s;
240    
# Line 236  static void rdp_send_fonts(uint16 seq) Line 250  static void rdp_send_fonts(uint16 seq)
250  }  }
251    
252  /* Output general capability set */  /* Output general capability set */
253  static void rdp_out_general_caps(STREAM s)  static void
254    rdp_out_general_caps(STREAM s)
255  {  {
256          out_uint16_le(s, RDP_CAPSET_GENERAL);          out_uint16_le(s, RDP_CAPSET_GENERAL);
257          out_uint16_le(s, RDP_CAPLEN_GENERAL);          out_uint16_le(s, RDP_CAPLEN_GENERAL);
258    
259          out_uint16_le(s, 1);    /* OS major type */          out_uint16_le(s, 1);    /* OS major type */
260          out_uint16_le(s, 3);    /* OS minor type */          out_uint16_le(s, 3);    /* OS minor type */
261          out_uint16_le(s, 0x200); /* Protocol version */          out_uint16_le(s, 0x200);        /* Protocol version */
262          out_uint16(s, 0);       /* Pad */          out_uint16(s, 0);       /* Pad */
263          out_uint16(s, 0);       /* Compression types */          out_uint16(s, 0);       /* Compression types */
264          out_uint16(s, 0);       /* Pad */          out_uint16(s, 0);       /* Pad */
# Line 254  static void rdp_out_general_caps(STREAM Line 269  static void rdp_out_general_caps(STREAM
269  }  }
270    
271  /* Output bitmap capability set */  /* Output bitmap capability set */
272  static void rdp_out_bitmap_caps(STREAM s)  static void
273    rdp_out_bitmap_caps(STREAM s)
274  {  {
275          out_uint16_le(s, RDP_CAPSET_BITMAP);          out_uint16_le(s, RDP_CAPSET_BITMAP);
276          out_uint16_le(s, RDP_CAPLEN_BITMAP);          out_uint16_le(s, RDP_CAPLEN_BITMAP);
# Line 267  static void rdp_out_bitmap_caps(STREAM s Line 283  static void rdp_out_bitmap_caps(STREAM s
283          out_uint16_le(s, 600);  /* Desktop height */          out_uint16_le(s, 600);  /* Desktop height */
284          out_uint16(s, 0);       /* Pad */          out_uint16(s, 0);       /* Pad */
285          out_uint16(s, 0);       /* Allow resize */          out_uint16(s, 0);       /* Allow resize */
286          out_uint16_le(s, 1);    /* Support compression */          out_uint16_le(s, bitmap_compression ? 1 : 0);   /* Support compression */
287          out_uint16(s, 0);       /* Unknown */          out_uint16(s, 0);       /* Unknown */
288          out_uint16_le(s, 1);    /* Unknown */          out_uint16_le(s, 1);    /* Unknown */
289          out_uint16(s, 0);       /* Pad */          out_uint16(s, 0);       /* Pad */
290  }  }
291    
292  /* Output order capability set */  /* Output order capability set */
293  static void rdp_out_order_caps(STREAM s)  static void
294    rdp_out_order_caps(STREAM s)
295  {  {
296          uint8 order_caps[32];          uint8 order_caps[32];
297    
         memset(order_caps, orders, 32);  
298    
299            memset(order_caps, 0, 32);
300            order_caps[0] = 1;      /* dest blt */
301            order_caps[1] = 1;      /* pat blt */
302            order_caps[2] = 1;      /* screen blt */
303            order_caps[8] = 1;      /* line */
304            order_caps[9] = 1;      /* line */
305            order_caps[10] = 1;     /* rect */
306            order_caps[11] = (desktop_save == False ? 0 : 1);       /* desksave */
307            order_caps[13] = 1;     /* memblt */
308            order_caps[14] = 1;     /* triblt */
309            order_caps[22] = 1;     /* polyline */
310            order_caps[27] = 1;     /* text2 */
311          out_uint16_le(s, RDP_CAPSET_ORDER);          out_uint16_le(s, RDP_CAPSET_ORDER);
312          out_uint16_le(s, RDP_CAPLEN_ORDER);          out_uint16_le(s, RDP_CAPLEN_ORDER);
313    
# Line 289  static void rdp_out_order_caps(STREAM s) Line 317  static void rdp_out_order_caps(STREAM s)
317          out_uint16(s, 0);       /* Pad */          out_uint16(s, 0);       /* Pad */
318          out_uint16_le(s, 1);    /* Max order level */          out_uint16_le(s, 1);    /* Max order level */
319          out_uint16_le(s, 0x147);        /* Number of fonts */          out_uint16_le(s, 0x147);        /* Number of fonts */
320          out_uint16_le(s, 0x2a);         /* Capability flags */          out_uint16_le(s, 0x2a); /* Capability flags */
321          out_uint8p(s, order_caps, 32);  /* Orders supported */          out_uint8p(s, order_caps, 32);  /* Orders supported */
322          out_uint16_le(s, 0x6a1);        /* Text capability flags */          out_uint16_le(s, 0x6a1);        /* Text capability flags */
323          out_uint8s(s, 6);       /* Pad */          out_uint8s(s, 6);       /* Pad */
324          out_uint32(s, 0x38400); /* Desktop cache size */          out_uint32(s, desktop_save == False ? 0 : 0x38400);     /* Desktop cache size */
325          out_uint32(s, 0);       /* Unknown */          out_uint32(s, 0);       /* Unknown */
326          out_uint32(s, 0x4e4);   /* Unknown */          out_uint32(s, 0x4e4);   /* Unknown */
327  }  }
328    
329  /* Output bitmap cache capability set */  /* Output bitmap cache capability set */
330  static void rdp_out_bmpcache_caps(STREAM s)  static void
331    rdp_out_bmpcache_caps(STREAM s)
332  {  {
333          out_uint16_le(s, RDP_CAPSET_BMPCACHE);          out_uint16_le(s, RDP_CAPSET_BMPCACHE);
334          out_uint16_le(s, RDP_CAPLEN_BMPCACHE);          out_uint16_le(s, RDP_CAPLEN_BMPCACHE);
335    
336          out_uint8s(s, 24); /* unused */          out_uint8s(s, 24);      /* unused */
337          out_uint16_le(s, 0x258); /* entries */          out_uint16_le(s, 0x258);        /* entries */
338          out_uint16_le(s, 0x100); /* max cell size */          out_uint16_le(s, 0x100);        /* max cell size */
339          out_uint16_le(s, 0x12c); /* entries */          out_uint16_le(s, 0x12c);        /* entries */
340          out_uint16_le(s, 0x400); /* max cell size */          out_uint16_le(s, 0x400);        /* max cell size */
341          out_uint16_le(s, 0x106); /* entries */          out_uint16_le(s, 0x106);        /* entries */
342          out_uint16_le(s, 0x1000); /* max cell size */          out_uint16_le(s, 0x1000);       /* max cell size */
343  }  }
344    
345  /* Output control capability set */  /* Output control capability set */
346  static void rdp_out_control_caps(STREAM s)  static void
347    rdp_out_control_caps(STREAM s)
348  {  {
349          out_uint16_le(s, RDP_CAPSET_CONTROL);          out_uint16_le(s, RDP_CAPSET_CONTROL);
350          out_uint16_le(s, RDP_CAPLEN_CONTROL);          out_uint16_le(s, RDP_CAPLEN_CONTROL);
# Line 326  static void rdp_out_control_caps(STREAM Line 356  static void rdp_out_control_caps(STREAM
356  }  }
357    
358  /* Output activation capability set */  /* Output activation capability set */
359  static void rdp_out_activate_caps(STREAM s)  static void
360    rdp_out_activate_caps(STREAM s)
361  {  {
362          out_uint16_le(s, RDP_CAPSET_ACTIVATE);          out_uint16_le(s, RDP_CAPSET_ACTIVATE);
363          out_uint16_le(s, RDP_CAPLEN_ACTIVATE);          out_uint16_le(s, RDP_CAPLEN_ACTIVATE);
# Line 338  static void rdp_out_activate_caps(STREAM Line 369  static void rdp_out_activate_caps(STREAM
369  }  }
370    
371  /* Output pointer capability set */  /* Output pointer capability set */
372  static void rdp_out_pointer_caps(STREAM s)  static void
373    rdp_out_pointer_caps(STREAM s)
374  {  {
375          out_uint16_le(s, RDP_CAPSET_POINTER);          out_uint16_le(s, RDP_CAPSET_POINTER);
376          out_uint16_le(s, RDP_CAPLEN_POINTER);          out_uint16_le(s, RDP_CAPLEN_POINTER);
# Line 348  static void rdp_out_pointer_caps(STREAM Line 380  static void rdp_out_pointer_caps(STREAM
380  }  }
381    
382  /* Output share capability set */  /* Output share capability set */
383  static void rdp_out_share_caps(STREAM s)  static void
384    rdp_out_share_caps(STREAM s)
385  {  {
386          out_uint16_le(s, RDP_CAPSET_SHARE);          out_uint16_le(s, RDP_CAPSET_SHARE);
387          out_uint16_le(s, RDP_CAPLEN_SHARE);          out_uint16_le(s, RDP_CAPLEN_SHARE);
# Line 358  static void rdp_out_share_caps(STREAM s) Line 391  static void rdp_out_share_caps(STREAM s)
391  }  }
392    
393  /* Output colour cache capability set */  /* Output colour cache capability set */
394  static void rdp_out_colcache_caps(STREAM s)  static void
395    rdp_out_colcache_caps(STREAM s)
396  {  {
397          out_uint16_le(s, RDP_CAPSET_COLCACHE);          out_uint16_le(s, RDP_CAPSET_COLCACHE);
398          out_uint16_le(s, RDP_CAPLEN_COLCACHE);          out_uint16_le(s, RDP_CAPLEN_COLCACHE);
# Line 368  static void rdp_out_colcache_caps(STREAM Line 402  static void rdp_out_colcache_caps(STREAM
402  }  }
403    
404  static uint8 canned_caps[] = {  static uint8 canned_caps[] = {
405  0x01,0x00,0x00,0x00,0x09,0x04,0x00,0x00,0x04,          0x01, 0x00, 0x00, 0x00, 0x09, 0x04, 0x00, 0x00, 0x04,
406  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00,
407  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,          0x00, 0x00, 0x00, 0x00, 0x00,
408  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,
409  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,          0x00, 0x00, 0x00, 0x00, 0x00,
410  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x08,0x00,0x01,          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
411  0x00,0x00,0x00,0x0E,0x00,0x08,0x00,0x01,0x00,0x00,0x00,0x10,0x00,0x34,0x00,0xFE,          0x00, 0x00, 0x00, 0x00, 0x00,
412  0x00,0x04,0x00,0xFE,0x00,0x04,0x00,0xFE,0x00,0x08,0x00,0xFE,0x00,0x08,0x00,0xFE,          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
413  0x00,0x10,0x00,0xFE,0x00,0x20,0x00,0xFE,0x00,0x40,0x00,0xFE,0x00,0x80,0x00,0xFE,          0x00, 0x00, 0x00, 0x00, 0x00,
414  0x00,0x00,0x01,0x40,0x00,0x00,0x08,0x00,0x01,0x00,0x01,0x02,0x00,0x00,0x00          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
415            0x0C, 0x00, 0x08, 0x00, 0x01,
416            0x00, 0x00, 0x00, 0x0E, 0x00, 0x08, 0x00, 0x01, 0x00, 0x00, 0x00,
417            0x10, 0x00, 0x34, 0x00, 0xFE,
418            0x00, 0x04, 0x00, 0xFE, 0x00, 0x04, 0x00, 0xFE, 0x00, 0x08, 0x00,
419            0xFE, 0x00, 0x08, 0x00, 0xFE,
420            0x00, 0x10, 0x00, 0xFE, 0x00, 0x20, 0x00, 0xFE, 0x00, 0x40, 0x00,
421            0xFE, 0x00, 0x80, 0x00, 0xFE,
422            0x00, 0x00, 0x01, 0x40, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00, 0x01,
423            0x02, 0x00, 0x00, 0x00
424  };  };
425    
426  /* Output unknown capability set */  /* Output unknown capability set */
427  static void rdp_out_unknown_caps(STREAM s)  static void
428    rdp_out_unknown_caps(STREAM s)
429  {  {
430          out_uint16_le(s, RDP_CAPSET_UNKNOWN);          out_uint16_le(s, RDP_CAPSET_UNKNOWN);
431          out_uint16_le(s, 0x58);          out_uint16_le(s, 0x58);
432            
433          out_uint8p(s, canned_caps, RDP_CAPLEN_UNKNOWN-4);          out_uint8p(s, canned_caps, RDP_CAPLEN_UNKNOWN - 4);
434  }  }
435    
436  /* Send a confirm active PDU */  /* Send a confirm active PDU */
437  static void rdp_send_confirm_active()  static void
438    rdp_send_confirm_active()
439  {  {
440          STREAM s;          STREAM s;
441          uint16 caplen = RDP_CAPLEN_GENERAL + RDP_CAPLEN_BITMAP + RDP_CAPLEN_ORDER          uint16 caplen =
442                  + RDP_CAPLEN_BMPCACHE + RDP_CAPLEN_COLCACHE + RDP_CAPLEN_ACTIVATE                  RDP_CAPLEN_GENERAL + RDP_CAPLEN_BITMAP + RDP_CAPLEN_ORDER +
443                  + RDP_CAPLEN_CONTROL + RDP_CAPLEN_POINTER + RDP_CAPLEN_SHARE                  RDP_CAPLEN_BMPCACHE + RDP_CAPLEN_COLCACHE +
444                  + RDP_CAPLEN_UNKNOWN;                  RDP_CAPLEN_ACTIVATE + RDP_CAPLEN_CONTROL +
445                    RDP_CAPLEN_POINTER + RDP_CAPLEN_SHARE + RDP_CAPLEN_UNKNOWN
446                            + 4 /* w2k fix, why? */;
447    
448          s = rdp_init(14 + caplen + sizeof(RDP_SOURCE));          s = rdp_init(14 + caplen + sizeof(RDP_SOURCE));
449    
450          out_uint32_le(s, rdp_shareid);          out_uint32_le(s, rdp_shareid);
451          out_uint16_le(s, 0x3ea); /* userid */          out_uint16_le(s, 0x3ea);        /* userid */
452          out_uint16_le(s, sizeof(RDP_SOURCE));          out_uint16_le(s, sizeof(RDP_SOURCE));
453          out_uint16_le(s, caplen);          out_uint16_le(s, caplen);
454    
455          out_uint8p(s, RDP_SOURCE, sizeof(RDP_SOURCE));          out_uint8p(s, RDP_SOURCE, sizeof(RDP_SOURCE));
456          out_uint16_le(s, 0xd); /* num_caps */          out_uint16_le(s, 0xd);  /* num_caps */
457          out_uint8s(s, 2);     /* pad */          out_uint8s(s, 2);       /* pad */
458    
459          rdp_out_general_caps(s);          rdp_out_general_caps(s);
460          rdp_out_bitmap_caps(s);          rdp_out_bitmap_caps(s);
# Line 425  static void rdp_send_confirm_active() Line 472  static void rdp_send_confirm_active()
472  }  }
473    
474  /* Respond to a demand active PDU */  /* Respond to a demand active PDU */
475  static void process_demand_active(STREAM s)  static void
476    process_demand_active(STREAM s)
477  {  {
478          uint8 type;          uint8 type;
479    
# Line 437  static void process_demand_active(STREAM Line 485  static void process_demand_active(STREAM
485          rdp_send_synchronise();          rdp_send_synchronise();
486          rdp_send_control(RDP_CTL_COOPERATE);          rdp_send_control(RDP_CTL_COOPERATE);
487          rdp_send_control(RDP_CTL_REQUEST_CONTROL);          rdp_send_control(RDP_CTL_REQUEST_CONTROL);
488          rdp_recv(&type); // RDP_PDU_SYNCHRONIZE          rdp_recv(&type);        /* RDP_PDU_SYNCHRONIZE */
489          rdp_recv(&type); // RDP_CTL_COOPERATE          rdp_recv(&type);        /* RDP_CTL_COOPERATE */
490          rdp_recv(&type); // RDP_CTL_GRANT_CONTROL          rdp_recv(&type);        /* RDP_CTL_GRANT_CONTROL */
491          rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, 0, 0);          rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, 0, 0);
492          rdp_send_fonts(1);          rdp_send_fonts(1);
493          rdp_send_fonts(2);          rdp_send_fonts(2);
494          rdp_recv(&type); // RDP_PDU_UNKNOWN 0x28          rdp_recv(&type);        /* RDP_PDU_UNKNOWN 0x28 */
495          reset_order_state();          reset_order_state();
496  }  }
497    
498  /* Process a pointer PDU */  /* Process a pointer PDU */
499  static void process_pointer_pdu(STREAM s)  static void
500    process_pointer_pdu(STREAM s)
501  {  {
502          uint16 message_type;          uint16 message_type;
503          uint16 x, y;          uint16 x, y, width, height, cache_idx, masklen, datalen;
504            uint8 *mask, *data;
505            HCURSOR cursor;
506    
507          in_uint16_le(s, message_type);          in_uint16_le(s, message_type);
508          in_uint8s(s, 2); /* pad */          in_uint8s(s, 2);        /* pad */
509    
510          switch (message_type)          switch (message_type)
511          {          {
# Line 465  static void process_pointer_pdu(STREAM s Line 516  static void process_pointer_pdu(STREAM s
516                                  ui_move_pointer(x, y);                                  ui_move_pointer(x, y);
517                          break;                          break;
518    
519                    case RDP_POINTER_COLOR:
520                            in_uint16_le(s, cache_idx);
521                            in_uint16_le(s, x);
522                            in_uint16_le(s, y);
523                            in_uint16_le(s, width);
524                            in_uint16_le(s, height);
525                            in_uint16_le(s, masklen);
526                            in_uint16_le(s, datalen);
527                            in_uint8p(s, data, datalen);
528                            in_uint8p(s, mask, masklen);
529                            cursor = ui_create_cursor(x, y, width, height, mask,
530                                                      data);
531                            ui_set_cursor(cursor);
532                            cache_put_cursor(cache_idx, cursor);
533                            break;
534    
535                    case RDP_POINTER_CACHED:
536                            in_uint16_le(s, cache_idx);
537                            ui_set_cursor(cache_get_cursor(cache_idx));
538                            break;
539    
540                  default:                  default:
541                          DEBUG("Pointer message 0x%x\n", message_type);                          DEBUG("Pointer message 0x%x\n", message_type);
542          }          }
543  }  }
544    
545  /* Process bitmap updates */  /* Process bitmap updates */
546  static void process_bitmap_updates(STREAM s)  static void
547    process_bitmap_updates(STREAM s)
548  {  {
549          uint16 num_updates;          uint16 num_updates;
550          uint16 left, top, right, bottom, width, height;          uint16 left, top, right, bottom, width, height;
551          uint16 cx, cy, bpp, compress, bufsize, size;          uint16 cx, cy, bpp, compress, bufsize, size;
552          uint8 *data, *rawdata;          uint8 *data, *bmpdata;
553          int i;          int i;
554    
555          in_uint16_le(s, num_updates);          in_uint16_le(s, num_updates);
# Line 497  static void process_bitmap_updates(STREA Line 570  static void process_bitmap_updates(STREA
570                  cy = bottom - top + 1;                  cy = bottom - top + 1;
571    
572                  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",
573                          left, top, right, bottom, width, height, compress);                        left, top, right, bottom, width, height, compress);
574    
575                  if (!compress)                  if (!compress)
576                  {                  {
577                          in_uint8p(s, data, bufsize);                          int y;
578                          ui_paint_bitmap(left, top, cx, cy, width, height, data);                          bmpdata = xmalloc(width * height);
579                          return;                          for (y = 0; y < height; y++)
580                            {
581                                    in_uint8a(s,
582                                              &bmpdata[(height - y - 1) * width],
583                                              width);
584                            }
585                            ui_paint_bitmap(left, top, cx, cy, width, height,
586                                            bmpdata);
587                            xfree(bmpdata);
588                            continue;
589                  }                  }
590    
591                  in_uint8s(s, 2); /* pad */                  in_uint8s(s, 2);        /* pad */
592                  in_uint16_le(s, size);                  in_uint16_le(s, size);
593                  in_uint8s(s, 4); /* line_size, final_size */                  in_uint8s(s, 4);        /* line_size, final_size */
594                  in_uint8p(s, data, size);                  in_uint8p(s, data, size);
595    
596                  rawdata = xmalloc(width * height);                  bmpdata = xmalloc(width * height);
597                  if (bitmap_decompress(rawdata, width, height, data, size))                  if (bitmap_decompress(bmpdata, width, height, data, size))
598                  {                  {
599                          ui_paint_bitmap(left, top, cx, cy, width, height,                          ui_paint_bitmap(left, top, cx, cy, width, height,
600                                          rawdata);                                          bmpdata);
601                  }                  }
602    
603                  xfree(rawdata);                  xfree(bmpdata);
604          }          }
605  }  }
606    
607  /* Process a palette update */  /* Process a palette update */
608  static void process_palette(STREAM s)  static void
609    process_palette(STREAM s)
610  {  {
611          HCOLOURMAP hmap;          HCOLOURMAP hmap;
612          COLOURMAP map;          COLOURMAP map;
613    
614          in_uint8s(s, 2); /* pad */          in_uint8s(s, 2);        /* pad */
615          in_uint16_le(s, map.ncolours);          in_uint16_le(s, map.ncolours);
616          in_uint8s(s, 2); /* pad */          in_uint8s(s, 2);        /* pad */
617          in_uint8p(s, (uint8 *)map.colours, (map.ncolours * 3));          in_uint8p(s, (uint8 *) map.colours, (map.ncolours * 3));
618    
619          hmap = ui_create_colourmap(&map);          hmap = ui_create_colourmap(&map);
620          ui_set_colourmap(hmap);          ui_set_colourmap(hmap);
621  }  }
622    
623  /* Process an update PDU */  /* Process an update PDU */
624  static void process_update_pdu(STREAM s)  static void
625    process_update_pdu(STREAM s)
626  {  {
627          uint16 update_type;          uint16 update_type;
628    
# Line 568  static void process_update_pdu(STREAM s) Line 652  static void process_update_pdu(STREAM s)
652  }  }
653    
654  /* Process data PDU */  /* Process data PDU */
655  static void process_data_pdu(STREAM s)  static void
656    process_data_pdu(STREAM s)
657  {  {
658          uint8 data_pdu_type;          uint8 data_pdu_type;
659    
660          in_uint8s(s, 8); /* shareid, pad, streamid, length */          in_uint8s(s, 8);        /* shareid, pad, streamid, length */
661          in_uint8(s, data_pdu_type);          in_uint8(s, data_pdu_type);
662          in_uint8s(s, 3); /* compress_type, compress_len */          in_uint8s(s, 3);        /* compress_type, compress_len */
663    
664          switch (data_pdu_type)          switch (data_pdu_type)
665          {          {
# Line 600  static void process_data_pdu(STREAM s) Line 685  static void process_data_pdu(STREAM s)
685  }  }
686    
687  /* Process incoming packets */  /* Process incoming packets */
688  void rdp_main_loop()  void
689    rdp_main_loop()
690  {  {
691          uint8 type;          uint8 type;
692          STREAM s;          STREAM s;
# Line 627  void rdp_main_loop() Line 713  void rdp_main_loop()
713  }  }
714    
715  /* Establish a connection up to the RDP layer */  /* Establish a connection up to the RDP layer */
716  BOOL rdp_connect(char *server)  BOOL
717    rdp_connect(char *server, uint32 flags, char *domain, char *password,
718                char *command, char *directory)
719  {  {
720          if (!sec_connect(server))          if (!sec_connect(server))
721                  return False;                  return False;
722    
723          rdp_send_logon_info(0x33, "", username, "", "", "");          rdp_send_logon_info(flags, domain, username, password,
724                                command, directory);
725          return True;          return True;
726  }  }
727    
728  /* Disconnect from the RDP layer */  /* Disconnect from the RDP layer */
729  void rdp_disconnect()  void
730    rdp_disconnect()
731  {  {
732          sec_disconnect();          sec_disconnect();
733  }  }
   

Legend:
Removed from v.10  
changed lines
  Added in v.28

  ViewVC Help
Powered by ViewVC 1.1.26