/[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 21 by matty, Mon Oct 16 08:44:48 2000 UTC revision 24 by matty, Sat Jan 6 03:12:10 2001 UTC
# Line 47  static void rdp_send(STREAM s, uint8 pdu Line 47  static void rdp_send(STREAM s, uint8 pdu
47          length = s->end - s->p;          length = s->end - s->p;
48    
49          out_uint16_le(s, length);          out_uint16_le(s, length);
50          out_uint16_le(s, (pdu_type | 0x10)); /* Version 1 */          out_uint16_le(s, (pdu_type | 0x10));    /* Version 1 */
51          out_uint16_le(s, (mcs_userid + 1001));          out_uint16_le(s, (mcs_userid + 1001));
52    
53          sec_send(s, SEC_ENCRYPT);          sec_send(s, SEC_ENCRYPT);
# Line 74  static STREAM rdp_recv(uint8 *type) Line 74  static STREAM rdp_recv(uint8 *type)
74    
75          in_uint16_le(rdp_s, length);          in_uint16_le(rdp_s, length);
76          in_uint16_le(rdp_s, pdu_type);          in_uint16_le(rdp_s, pdu_type);
77          in_uint8s(rdp_s, 2); /* userid */          in_uint8s(rdp_s, 2);    /* userid */
78    
79          next_packet += length;          next_packet += length;
80          *type = pdu_type & 0xf;          *type = pdu_type & 0xf;
# Line 111  static void rdp_send_data(STREAM s, uint Line 111  static void rdp_send_data(STREAM s, uint
111          out_uint16_le(s, (mcs_userid + 1001));          out_uint16_le(s, (mcs_userid + 1001));
112    
113          out_uint32_le(s, rdp_shareid);          out_uint32_le(s, rdp_shareid);
114          out_uint8(s, 0);  /* pad */          out_uint8(s, 0);        /* pad */
115          out_uint8(s, 1);  /* streamid */          out_uint8(s, 1);        /* streamid */
116          out_uint16(s, (length - 14));          out_uint16(s, (length - 14));
117          out_uint8(s, data_pdu_type);          out_uint8(s, data_pdu_type);
118          out_uint8(s, 0);  /* compress_type */          out_uint8(s, 0);        /* compress_type */
119          out_uint16(s, 0); /* compress_len */          out_uint16(s, 0);       /* compress_len */
120    
121          sec_send(s, SEC_ENCRYPT);          sec_send(s, SEC_ENCRYPT);
122  }  }
# Line 139  void rdp_out_unistr(STREAM s, char *stri Line 139  void rdp_out_unistr(STREAM s, char *stri
139    
140  /* Parse a logon info packet */  /* Parse a logon info packet */
141  static void rdp_send_logon_info(uint32 flags, char *domain, char *user,  static void rdp_send_logon_info(uint32 flags, char *domain, char *user,
142                                  char *password, char *program, char *directory)                                  char *password, char *program,
143                                    char *directory)
144  {  {
145          int len_domain    = 2 * strlen(domain);          int len_domain = 2 * strlen(domain);
146          int len_user      = 2 * strlen(user);          int len_user = 2 * strlen(user);
147          int len_password  = 2 * strlen(password);          int len_password = 2 * strlen(password);
148          int len_program   = 2 * strlen(program);          int len_program = 2 * strlen(program);
149          int len_directory = 2 * strlen(directory);          int len_directory = 2 * strlen(directory);
150          uint32 sec_flags = SEC_LOGON_INFO | SEC_ENCRYPT;          uint32 sec_flags = SEC_LOGON_INFO | SEC_ENCRYPT;
151          STREAM s;          STREAM s;
152    
153          s = sec_init(sec_flags, 18 + len_domain + len_user + len_password          s = sec_init(sec_flags, 18 + len_domain + len_user + len_password
154                                          + len_program + len_directory + 10);                       + len_program + len_directory + 10);
155    
156          out_uint32(s, 0);          out_uint32(s, 0);
157          out_uint32_le(s, flags);          out_uint32_le(s, flags);
# Line 159  static void rdp_send_logon_info(uint32 f Line 160  static void rdp_send_logon_info(uint32 f
160          out_uint16_le(s, len_password);          out_uint16_le(s, len_password);
161          out_uint16_le(s, len_program);          out_uint16_le(s, len_program);
162          out_uint16_le(s, len_directory);          out_uint16_le(s, len_directory);
163          rdp_out_unistr(s, domain,    len_domain);          rdp_out_unistr(s, domain, len_domain);
164          rdp_out_unistr(s, user,      len_user);          rdp_out_unistr(s, user, len_user);
165          rdp_out_unistr(s, password,  len_password);          rdp_out_unistr(s, password, len_password);
166          rdp_out_unistr(s, program,   len_program);          rdp_out_unistr(s, program, len_program);
167          rdp_out_unistr(s, directory, len_directory);          rdp_out_unistr(s, directory, len_directory);
168    
169          s_mark_end(s);          s_mark_end(s);
# Line 177  static void rdp_send_control(uint16 acti Line 178  static void rdp_send_control(uint16 acti
178          s = rdp_init_data(8);          s = rdp_init_data(8);
179    
180          out_uint16_le(s, action);          out_uint16_le(s, action);
181          out_uint16(s, 0); /* userid */          out_uint16(s, 0);       /* userid */
182          out_uint32(s, 0); /* control id */          out_uint32(s, 0);       /* control id */
183    
184          s_mark_end(s);          s_mark_end(s);
185          rdp_send_data(s, RDP_DATA_PDU_CONTROL);          rdp_send_data(s, RDP_DATA_PDU_CONTROL);
# Line 191  static void rdp_send_synchronise() Line 192  static void rdp_send_synchronise()
192    
193          s = rdp_init_data(4);          s = rdp_init_data(4);
194    
195          out_uint16_le(s, 1); /* type */          out_uint16_le(s, 1);    /* type */
196          out_uint16_le(s, 1002);          out_uint16_le(s, 1002);
197    
198          s_mark_end(s);          s_mark_end(s);
# Line 206  void rdp_send_input(uint32 time, uint16 Line 207  void rdp_send_input(uint32 time, uint16
207    
208          s = rdp_init_data(16);          s = rdp_init_data(16);
209    
210          out_uint16_le(s, 1); /* number of events */          out_uint16_le(s, 1);    /* number of events */
211          out_uint16(s, 0);    /* pad */          out_uint16(s, 0);       /* pad */
212    
213          out_uint32_le(s, time);          out_uint32_le(s, time);
214          out_uint16_le(s, message_type);          out_uint16_le(s, message_type);
# Line 243  static void rdp_out_general_caps(STREAM Line 244  static void rdp_out_general_caps(STREAM
244    
245          out_uint16_le(s, 1);    /* OS major type */          out_uint16_le(s, 1);    /* OS major type */
246          out_uint16_le(s, 3);    /* OS minor type */          out_uint16_le(s, 3);    /* OS minor type */
247          out_uint16_le(s, 0x200); /* Protocol version */          out_uint16_le(s, 0x200);        /* Protocol version */
248          out_uint16(s, 0);       /* Pad */          out_uint16(s, 0);       /* Pad */
249          out_uint16(s, 0);       /* Compression types */          out_uint16(s, 0);       /* Compression types */
250          out_uint16(s, 0);       /* Pad */          out_uint16(s, 0);       /* Pad */
# Line 289  static void rdp_out_order_caps(STREAM s) Line 290  static void rdp_out_order_caps(STREAM s)
290          out_uint16(s, 0);       /* Pad */          out_uint16(s, 0);       /* Pad */
291          out_uint16_le(s, 1);    /* Max order level */          out_uint16_le(s, 1);    /* Max order level */
292          out_uint16_le(s, 0x147);        /* Number of fonts */          out_uint16_le(s, 0x147);        /* Number of fonts */
293          out_uint16_le(s, 0x2a);         /* Capability flags */          out_uint16_le(s, 0x2a); /* Capability flags */
294          out_uint8p(s, order_caps, 32);  /* Orders supported */          out_uint8p(s, order_caps, 32);  /* Orders supported */
295          out_uint16_le(s, 0x6a1);        /* Text capability flags */          out_uint16_le(s, 0x6a1);        /* Text capability flags */
296          out_uint8s(s, 6);       /* Pad */          out_uint8s(s, 6);       /* Pad */
# Line 304  static void rdp_out_bmpcache_caps(STREAM Line 305  static void rdp_out_bmpcache_caps(STREAM
305          out_uint16_le(s, RDP_CAPSET_BMPCACHE);          out_uint16_le(s, RDP_CAPSET_BMPCACHE);
306          out_uint16_le(s, RDP_CAPLEN_BMPCACHE);          out_uint16_le(s, RDP_CAPLEN_BMPCACHE);
307    
308          out_uint8s(s, 24); /* unused */          out_uint8s(s, 24);      /* unused */
309          out_uint16_le(s, 0x258); /* entries */          out_uint16_le(s, 0x258);        /* entries */
310          out_uint16_le(s, 0x100); /* max cell size */          out_uint16_le(s, 0x100);        /* max cell size */
311          out_uint16_le(s, 0x12c); /* entries */          out_uint16_le(s, 0x12c);        /* entries */
312          out_uint16_le(s, 0x400); /* max cell size */          out_uint16_le(s, 0x400);        /* max cell size */
313          out_uint16_le(s, 0x106); /* entries */          out_uint16_le(s, 0x106);        /* entries */
314          out_uint16_le(s, 0x1000); /* max cell size */          out_uint16_le(s, 0x1000);       /* max cell size */
315  }  }
316    
317  /* Output control capability set */  /* Output control capability set */
# Line 368  static void rdp_out_colcache_caps(STREAM Line 369  static void rdp_out_colcache_caps(STREAM
369  }  }
370    
371  static uint8 canned_caps[] = {  static uint8 canned_caps[] = {
372  0x01,0x00,0x00,0x00,0x09,0x04,0x00,0x00,0x04,          0x01, 0x00, 0x00, 0x00, 0x09, 0x04, 0x00, 0x00, 0x04,
373  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,
374  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,                  0x00, 0x00, 0x00, 0x00, 0x00,
375  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,
376  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,                  0x00, 0x00, 0x00, 0x00, 0x00,
377  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,
378  0x00,0x00,0x00,0x0E,0x00,0x08,0x00,0x01,0x00,0x00,0x00,0x10,0x00,0x34,0x00,0xFE,                  0x00, 0x00, 0x00, 0x00, 0x00,
379  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,
380  0x00,0x10,0x00,0xFE,0x00,0x20,0x00,0xFE,0x00,0x40,0x00,0xFE,0x00,0x80,0x00,0xFE,                  0x00, 0x00, 0x00, 0x00, 0x00,
381  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,
382                    0x0C, 0x00, 0x08, 0x00, 0x01,
383            0x00, 0x00, 0x00, 0x0E, 0x00, 0x08, 0x00, 0x01, 0x00, 0x00, 0x00,
384                    0x10, 0x00, 0x34, 0x00, 0xFE,
385            0x00, 0x04, 0x00, 0xFE, 0x00, 0x04, 0x00, 0xFE, 0x00, 0x08, 0x00,
386                    0xFE, 0x00, 0x08, 0x00, 0xFE,
387            0x00, 0x10, 0x00, 0xFE, 0x00, 0x20, 0x00, 0xFE, 0x00, 0x40, 0x00,
388                    0xFE, 0x00, 0x80, 0x00, 0xFE,
389            0x00, 0x00, 0x01, 0x40, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00, 0x01,
390                    0x02, 0x00, 0x00, 0x00
391  };  };
392    
393  /* Output unknown capability set */  /* Output unknown capability set */
# Line 385  static void rdp_out_unknown_caps(STREAM Line 395  static void rdp_out_unknown_caps(STREAM
395  {  {
396          out_uint16_le(s, RDP_CAPSET_UNKNOWN);          out_uint16_le(s, RDP_CAPSET_UNKNOWN);
397          out_uint16_le(s, 0x58);          out_uint16_le(s, 0x58);
398            
399          out_uint8p(s, canned_caps, RDP_CAPLEN_UNKNOWN-4);          out_uint8p(s, canned_caps, RDP_CAPLEN_UNKNOWN - 4);
400  }  }
401    
402  /* Send a confirm active PDU */  /* Send a confirm active PDU */
403  static void rdp_send_confirm_active()  static void rdp_send_confirm_active()
404  {  {
405          STREAM s;          STREAM s;
406          uint16 caplen = RDP_CAPLEN_GENERAL + RDP_CAPLEN_BITMAP + RDP_CAPLEN_ORDER          uint16 caplen =
407                  + RDP_CAPLEN_BMPCACHE + RDP_CAPLEN_COLCACHE + RDP_CAPLEN_ACTIVATE                  RDP_CAPLEN_GENERAL + RDP_CAPLEN_BITMAP + RDP_CAPLEN_ORDER +
408                  + RDP_CAPLEN_CONTROL + RDP_CAPLEN_POINTER + RDP_CAPLEN_SHARE                  RDP_CAPLEN_BMPCACHE + RDP_CAPLEN_COLCACHE +
409                  + RDP_CAPLEN_UNKNOWN;                  RDP_CAPLEN_ACTIVATE + RDP_CAPLEN_CONTROL +
410                    RDP_CAPLEN_POINTER + RDP_CAPLEN_SHARE + RDP_CAPLEN_UNKNOWN;
411    
412          s = rdp_init(14 + caplen + sizeof(RDP_SOURCE));          s = rdp_init(14 + caplen + sizeof(RDP_SOURCE));
413    
414          out_uint32_le(s, rdp_shareid);          out_uint32_le(s, rdp_shareid);
415          out_uint16_le(s, 0x3ea); /* userid */          out_uint16_le(s, 0x3ea);        /* userid */
416          out_uint16_le(s, sizeof(RDP_SOURCE));          out_uint16_le(s, sizeof(RDP_SOURCE));
417          out_uint16_le(s, caplen);          out_uint16_le(s, caplen);
418    
419          out_uint8p(s, RDP_SOURCE, sizeof(RDP_SOURCE));          out_uint8p(s, RDP_SOURCE, sizeof(RDP_SOURCE));
420          out_uint16_le(s, 0xd); /* num_caps */          out_uint16_le(s, 0xd);  /* num_caps */
421          out_uint8s(s, 2);     /* pad */          out_uint8s(s, 2);       /* pad */
422    
423          rdp_out_general_caps(s);          rdp_out_general_caps(s);
424          rdp_out_bitmap_caps(s);          rdp_out_bitmap_caps(s);
# Line 437  static void process_demand_active(STREAM Line 448  static void process_demand_active(STREAM
448          rdp_send_synchronise();          rdp_send_synchronise();
449          rdp_send_control(RDP_CTL_COOPERATE);          rdp_send_control(RDP_CTL_COOPERATE);
450          rdp_send_control(RDP_CTL_REQUEST_CONTROL);          rdp_send_control(RDP_CTL_REQUEST_CONTROL);
451          rdp_recv(&type); // RDP_PDU_SYNCHRONIZE          rdp_recv(&type);        // RDP_PDU_SYNCHRONIZE
452          rdp_recv(&type); // RDP_CTL_COOPERATE          rdp_recv(&type);        // RDP_CTL_COOPERATE
453          rdp_recv(&type); // RDP_CTL_GRANT_CONTROL          rdp_recv(&type);        // RDP_CTL_GRANT_CONTROL
454          rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, 0, 0);          rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, 0, 0);
455          rdp_send_fonts(1);          rdp_send_fonts(1);
456          rdp_send_fonts(2);          rdp_send_fonts(2);
457          rdp_recv(&type); // RDP_PDU_UNKNOWN 0x28          rdp_recv(&type);        // RDP_PDU_UNKNOWN 0x28
458          reset_order_state();          reset_order_state();
459  }  }
460    
# Line 454  static void process_pointer_pdu(STREAM s Line 465  static void process_pointer_pdu(STREAM s
465          uint16 x, y;          uint16 x, y;
466    
467          in_uint16_le(s, message_type);          in_uint16_le(s, message_type);
468          in_uint8s(s, 2); /* pad */          in_uint8s(s, 2);        /* pad */
469    
470          switch (message_type)          switch (message_type)
471          {          {
# Line 497  static void process_bitmap_updates(STREA Line 508  static void process_bitmap_updates(STREA
508                  cy = bottom - top + 1;                  cy = bottom - top + 1;
509    
510                  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",
511                          left, top, right, bottom, width, height, compress);                        left, top, right, bottom, width, height, compress);
512    
513                  if (!compress)                  if (!compress)
514                  {                  {
515                          in_uint8p(s, data, bufsize);                          in_uint8p(s, data, bufsize);
516                          ui_paint_bitmap(left, top, cx, cy, width, height, data);                          ui_paint_bitmap(left, top, cx, cy, width, height,
517                                            data);
518                          return;                          return;
519                  }                  }
520    
521                  in_uint8s(s, 2); /* pad */                  in_uint8s(s, 2);        /* pad */
522                  in_uint16_le(s, size);                  in_uint16_le(s, size);
523                  in_uint8s(s, 4); /* line_size, final_size */                  in_uint8s(s, 4);        /* line_size, final_size */
524                  in_uint8p(s, data, size);                  in_uint8p(s, data, size);
525    
526                  rawdata = xmalloc(width * height);                  rawdata = xmalloc(width * height);
# Line 528  static void process_palette(STREAM s) Line 540  static void process_palette(STREAM s)
540          HCOLOURMAP hmap;          HCOLOURMAP hmap;
541          COLOURMAP map;          COLOURMAP map;
542    
543          in_uint8s(s, 2); /* pad */          in_uint8s(s, 2);        /* pad */
544          in_uint16_le(s, map.ncolours);          in_uint16_le(s, map.ncolours);
545          in_uint8s(s, 2); /* pad */          in_uint8s(s, 2);        /* pad */
546          in_uint8p(s, (uint8 *)map.colours, (map.ncolours * 3));          in_uint8p(s, (uint8 *) map.colours, (map.ncolours * 3));
547    
548          hmap = ui_create_colourmap(&map);          hmap = ui_create_colourmap(&map);
549          ui_set_colourmap(hmap);          ui_set_colourmap(hmap);
# Line 572  static void process_data_pdu(STREAM s) Line 584  static void process_data_pdu(STREAM s)
584  {  {
585          uint8 data_pdu_type;          uint8 data_pdu_type;
586    
587          in_uint8s(s, 8); /* shareid, pad, streamid, length */          in_uint8s(s, 8);        /* shareid, pad, streamid, length */
588          in_uint8(s, data_pdu_type);          in_uint8(s, data_pdu_type);
589          in_uint8s(s, 3); /* compress_type, compress_len */          in_uint8s(s, 3);        /* compress_type, compress_len */
590    
591          switch (data_pdu_type)          switch (data_pdu_type)
592          {          {
# Line 628  void rdp_main_loop() Line 640  void rdp_main_loop()
640    
641  /* Establish a connection up to the RDP layer */  /* Establish a connection up to the RDP layer */
642  BOOL rdp_connect(char *server, uint32 flags, char *domain, char *password,  BOOL rdp_connect(char *server, uint32 flags, char *domain, char *password,
643                          char *command, char *directory)                   char *command, char *directory)
644  {  {
645          if (!sec_connect(server))          if (!sec_connect(server))
646                  return False;                  return False;
647    
648          rdp_send_logon_info(flags, domain, username, password,          rdp_send_logon_info(flags, domain, username, password,
649                                  command, directory);                              command, directory);
650          return True;          return True;
651  }  }
652    
# Line 643  void rdp_disconnect() Line 655  void rdp_disconnect()
655  {  {
656          sec_disconnect();          sec_disconnect();
657  }  }
   

Legend:
Removed from v.21  
changed lines
  Added in v.24

  ViewVC Help
Powered by ViewVC 1.1.26