/[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 25 by matty, Sat Jan 6 03:47:04 2001 UTC revision 82 by astrand, Tue Jul 30 07:18:48 2002 UTC
# Line 1  Line 1 
1  /*  /*
2     rdesktop: A Remote Desktop Protocol client.     rdesktop: A Remote Desktop Protocol client.
3     Protocol services - RDP layer     Protocol services - RDP layer
4     Copyright (C) Matthew Chapman 1999-2000     Copyright (C) Matthew Chapman 1999-2001
5        
6     This program is free software; you can redistribute it and/or modify     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by     it under the terms of the GNU General Public License as published by
# 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 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 */
# Line 33  rdp_init(int maxlen) Line 36  rdp_init(int maxlen)
36  {  {
37          STREAM s;          STREAM s;
38    
39          s = sec_init(SEC_ENCRYPT, maxlen + 6);          s = sec_init(encryption ? SEC_ENCRYPT : 0, maxlen + 6);
40          s_push_layer(s, rdp_hdr, 6);          s_push_layer(s, rdp_hdr, 6);
41    
42          return s;          return s;
# Line 52  rdp_send(STREAM s, uint8 pdu_type) Line 55  rdp_send(STREAM s, uint8 pdu_type)
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, encryption ? SEC_ENCRYPT : 0);
59  }  }
60    
61  /* Receive an RDP packet */  /* Receive an RDP packet */
62  static STREAM  static STREAM
63  rdp_recv(uint8 *type)  rdp_recv(uint8 * type)
64  {  {
65          static STREAM rdp_s;          static STREAM rdp_s;
66          uint16 length, pdu_type;          uint16 length, pdu_type;
# Line 78  rdp_recv(uint8 *type) Line 81  rdp_recv(uint8 *type)
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 WITH_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    
# Line 96  rdp_init_data(int maxlen) Line 98  rdp_init_data(int maxlen)
98  {  {
99          STREAM s;          STREAM s;
100    
101          s = sec_init(SEC_ENCRYPT, maxlen + 18);          s = sec_init(encryption ? SEC_ENCRYPT : 0, maxlen + 18);
102          s_push_layer(s, rdp_hdr, 18);          s_push_layer(s, rdp_hdr, 18);
103    
104          return s;          return s;
# Line 123  rdp_send_data(STREAM s, uint8 data_pdu_t Line 125  rdp_send_data(STREAM s, uint8 data_pdu_t
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, encryption ? SEC_ENCRYPT : 0);
129  }  }
130    
131  /* Output a string in Unicode */  /* Output a string in Unicode */
# Line 153  rdp_send_logon_info(uint32 flags, char * Line 155  rdp_send_logon_info(uint32 flags, char *
155          int len_password = 2 * strlen(password);          int len_password = 2 * strlen(password);
156          int len_program = 2 * strlen(program);          int len_program = 2 * strlen(program);
157          int len_directory = 2 * strlen(directory);          int len_directory = 2 * strlen(directory);
158          uint32 sec_flags = SEC_LOGON_INFO | SEC_ENCRYPT;          uint32 sec_flags = encryption ? (SEC_LOGON_INFO | SEC_ENCRYPT) : SEC_LOGON_INFO;
159          STREAM s;          STREAM s;
160    
161          s = sec_init(sec_flags, 18 + len_domain + len_user + len_password          s = sec_init(sec_flags, 18 + len_domain + len_user + len_password
# Line 209  rdp_send_synchronise() Line 211  rdp_send_synchronise()
211    
212  /* Send a single input event */  /* Send a single input event */
213  void  void
214  rdp_send_input(uint32 time, uint16 message_type, uint16 device_flags,  rdp_send_input(uint32 time, uint16 message_type, uint16 device_flags, uint16 param1, uint16 param2)
                uint16 param1, uint16 param2)  
215  {  {
216          STREAM s;          STREAM s;
217    
# Line 280  rdp_out_bitmap_caps(STREAM s) Line 281  rdp_out_bitmap_caps(STREAM s)
281          out_uint16_le(s, 600);  /* Desktop height */          out_uint16_le(s, 600);  /* Desktop height */
282          out_uint16(s, 0);       /* Pad */          out_uint16(s, 0);       /* Pad */
283          out_uint16(s, 0);       /* Allow resize */          out_uint16(s, 0);       /* Allow resize */
284          out_uint16_le(s, 1);    /* Support compression */          out_uint16_le(s, bitmap_compression ? 1 : 0);   /* Support compression */
285          out_uint16(s, 0);       /* Unknown */          out_uint16(s, 0);       /* Unknown */
286          out_uint16_le(s, 1);    /* Unknown */          out_uint16_le(s, 1);    /* Unknown */
287          out_uint16(s, 0);       /* Pad */          out_uint16(s, 0);       /* Pad */
# Line 292  rdp_out_order_caps(STREAM s) Line 293  rdp_out_order_caps(STREAM s)
293  {  {
294          uint8 order_caps[32];          uint8 order_caps[32];
295    
         memset(order_caps, orders, 32);  
296    
297            memset(order_caps, 0, 32);
298            order_caps[0] = 1;      /* dest blt */
299            order_caps[1] = 1;      /* pat blt */
300            order_caps[2] = 1;      /* screen blt */
301            order_caps[8] = 1;      /* line */
302            order_caps[9] = 1;      /* line */
303            order_caps[10] = 1;     /* rect */
304            order_caps[11] = (desktop_save == False ? 0 : 1);       /* desksave */
305            order_caps[13] = 1;     /* memblt */
306            order_caps[14] = 1;     /* triblt */
307            order_caps[22] = 1;     /* polyline */
308            order_caps[27] = 1;     /* text2 */
309          out_uint16_le(s, RDP_CAPSET_ORDER);          out_uint16_le(s, RDP_CAPSET_ORDER);
310          out_uint16_le(s, RDP_CAPLEN_ORDER);          out_uint16_le(s, RDP_CAPLEN_ORDER);
311    
# Line 307  rdp_out_order_caps(STREAM s) Line 319  rdp_out_order_caps(STREAM s)
319          out_uint8p(s, order_caps, 32);  /* Orders supported */          out_uint8p(s, order_caps, 32);  /* Orders supported */
320          out_uint16_le(s, 0x6a1);        /* Text capability flags */          out_uint16_le(s, 0x6a1);        /* Text capability flags */
321          out_uint8s(s, 6);       /* Pad */          out_uint8s(s, 6);       /* Pad */
322          out_uint32(s, 0x38400); /* Desktop cache size */          out_uint32(s, desktop_save == False ? 0 : 0x38400);     /* Desktop cache size */
323          out_uint32(s, 0);       /* Unknown */          out_uint32(s, 0);       /* Unknown */
324          out_uint32(s, 0x4e4);   /* Unknown */          out_uint32(s, 0x4e4);   /* Unknown */
325  }  }
# Line 428  rdp_send_confirm_active() Line 440  rdp_send_confirm_active()
440                  RDP_CAPLEN_GENERAL + RDP_CAPLEN_BITMAP + RDP_CAPLEN_ORDER +                  RDP_CAPLEN_GENERAL + RDP_CAPLEN_BITMAP + RDP_CAPLEN_ORDER +
441                  RDP_CAPLEN_BMPCACHE + RDP_CAPLEN_COLCACHE +                  RDP_CAPLEN_BMPCACHE + RDP_CAPLEN_COLCACHE +
442                  RDP_CAPLEN_ACTIVATE + RDP_CAPLEN_CONTROL +                  RDP_CAPLEN_ACTIVATE + RDP_CAPLEN_CONTROL +
443                  RDP_CAPLEN_POINTER + RDP_CAPLEN_SHARE + RDP_CAPLEN_UNKNOWN;                  RDP_CAPLEN_POINTER + RDP_CAPLEN_SHARE + RDP_CAPLEN_UNKNOWN + 4 /* w2k fix, why? */ ;
444    
445          s = rdp_init(14 + caplen + sizeof(RDP_SOURCE));          s = rdp_init(14 + caplen + sizeof(RDP_SOURCE));
446    
# Line 464  process_demand_active(STREAM s) Line 476  process_demand_active(STREAM s)
476    
477          in_uint32_le(s, rdp_shareid);          in_uint32_le(s, rdp_shareid);
478    
479          DEBUG("DEMAND_ACTIVE(id=0x%x)\n", rdp_shareid);          DEBUG(("DEMAND_ACTIVE(id=0x%x)\n", rdp_shareid));
480    
481          rdp_send_confirm_active();          rdp_send_confirm_active();
482          rdp_send_synchronise();          rdp_send_synchronise();
483          rdp_send_control(RDP_CTL_COOPERATE);          rdp_send_control(RDP_CTL_COOPERATE);
484          rdp_send_control(RDP_CTL_REQUEST_CONTROL);          rdp_send_control(RDP_CTL_REQUEST_CONTROL);
485          rdp_recv(&type);        // RDP_PDU_SYNCHRONIZE          rdp_recv(&type);        /* RDP_PDU_SYNCHRONIZE */
486          rdp_recv(&type);        // RDP_CTL_COOPERATE          rdp_recv(&type);        /* RDP_CTL_COOPERATE */
487          rdp_recv(&type);        // RDP_CTL_GRANT_CONTROL          rdp_recv(&type);        /* RDP_CTL_GRANT_CONTROL */
488          rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, 0, 0);          rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, 0, 0);
489          rdp_send_fonts(1);          rdp_send_fonts(1);
490          rdp_send_fonts(2);          rdp_send_fonts(2);
491          rdp_recv(&type);        // RDP_PDU_UNKNOWN 0x28          rdp_recv(&type);        /* RDP_PDU_UNKNOWN 0x28 */
492          reset_order_state();          reset_order_state();
493  }  }
494    
# Line 485  static void Line 497  static void
497  process_pointer_pdu(STREAM s)  process_pointer_pdu(STREAM s)
498  {  {
499          uint16 message_type;          uint16 message_type;
500          uint16 x, y;          uint16 x, y, width, height, cache_idx, masklen, datalen;
501            uint8 *mask, *data;
502            HCURSOR cursor;
503    
504          in_uint16_le(s, message_type);          in_uint16_le(s, message_type);
505          in_uint8s(s, 2);        /* pad */          in_uint8s(s, 2);        /* pad */
# Line 499  process_pointer_pdu(STREAM s) Line 513  process_pointer_pdu(STREAM s)
513                                  ui_move_pointer(x, y);                                  ui_move_pointer(x, y);
514                          break;                          break;
515    
516                    case RDP_POINTER_COLOR:
517                            in_uint16_le(s, cache_idx);
518                            in_uint16_le(s, x);
519                            in_uint16_le(s, y);
520                            in_uint16_le(s, width);
521                            in_uint16_le(s, height);
522                            in_uint16_le(s, masklen);
523                            in_uint16_le(s, datalen);
524                            in_uint8p(s, data, datalen);
525                            in_uint8p(s, mask, masklen);
526                            cursor = ui_create_cursor(x, y, width, height, mask, data);
527                            ui_set_cursor(cursor);
528                            cache_put_cursor(cache_idx, cursor);
529                            break;
530    
531                    case RDP_POINTER_CACHED:
532                            in_uint16_le(s, cache_idx);
533                            ui_set_cursor(cache_get_cursor(cache_idx));
534                            break;
535    
536                  default:                  default:
537                          DEBUG("Pointer message 0x%x\n", message_type);                          DEBUG(("Pointer message 0x%x\n", message_type));
538          }          }
539  }  }
540    
# Line 511  process_bitmap_updates(STREAM s) Line 545  process_bitmap_updates(STREAM s)
545          uint16 num_updates;          uint16 num_updates;
546          uint16 left, top, right, bottom, width, height;          uint16 left, top, right, bottom, width, height;
547          uint16 cx, cy, bpp, compress, bufsize, size;          uint16 cx, cy, bpp, compress, bufsize, size;
548          uint8 *data, *rawdata;          uint8 *data, *bmpdata;
549          int i;          int i;
550    
551          in_uint16_le(s, num_updates);          in_uint16_le(s, num_updates);
# Line 531  process_bitmap_updates(STREAM s) Line 565  process_bitmap_updates(STREAM s)
565                  cx = right - left + 1;                  cx = right - left + 1;
566                  cy = bottom - top + 1;                  cy = bottom - top + 1;
567    
568                  DEBUG("UPDATE(l=%d,t=%d,r=%d,b=%d,w=%d,h=%d,cmp=%d)\n",                  DEBUG(("UPDATE(l=%d,t=%d,r=%d,b=%d,w=%d,h=%d,cmp=%d)\n",
569                        left, top, right, bottom, width, height, compress);                         left, top, right, bottom, width, height, compress));
570    
571                  if (!compress)                  if (!compress)
572                  {                  {
573                          in_uint8p(s, data, bufsize);                          int y;
574                          ui_paint_bitmap(left, top, cx, cy, width, height,                          bmpdata = xmalloc(width * height);
575                                          data);                          for (y = 0; y < height; y++)
576                          return;                          {
577                                    in_uint8a(s, &bmpdata[(height - y - 1) * width], width);
578                            }
579                            ui_paint_bitmap(left, top, cx, cy, width, height, bmpdata);
580                            xfree(bmpdata);
581                            continue;
582                  }                  }
583    
584                  in_uint8s(s, 2);        /* pad */                  in_uint8s(s, 2);        /* pad */
# Line 547  process_bitmap_updates(STREAM s) Line 586  process_bitmap_updates(STREAM s)
586                  in_uint8s(s, 4);        /* line_size, final_size */                  in_uint8s(s, 4);        /* line_size, final_size */
587                  in_uint8p(s, data, size);                  in_uint8p(s, data, size);
588    
589                  rawdata = xmalloc(width * height);                  bmpdata = xmalloc(width * height);
590                  if (bitmap_decompress(rawdata, width, height, data, size))                  if (bitmap_decompress(bmpdata, width, height, data, size))
591                  {                  {
592                          ui_paint_bitmap(left, top, cx, cy, width, height,                          ui_paint_bitmap(left, top, cx, cy, width, height, bmpdata);
                                         rawdata);  
593                  }                  }
594    
595                  xfree(rawdata);                  xfree(bmpdata);
596          }          }
597  }  }
598    
# Line 564  process_palette(STREAM s) Line 602  process_palette(STREAM s)
602  {  {
603          HCOLOURMAP hmap;          HCOLOURMAP hmap;
604          COLOURMAP map;          COLOURMAP map;
605            uint8 *colours;
606    
607          in_uint8s(s, 2);        /* pad */          in_uint8s(s, 2);        /* pad */
608          in_uint16_le(s, map.ncolours);          in_uint16_le(s, map.ncolours);
609          in_uint8s(s, 2);        /* pad */          in_uint8s(s, 2);        /* pad */
610          in_uint8p(s, (uint8 *) map.colours, (map.ncolours * 3));          in_uint8p(s, colours, (map.ncolours * 3));
611            map.colours = (COLOURENTRY *) colours;
612    
613          hmap = ui_create_colourmap(&map);          hmap = ui_create_colourmap(&map);
614          ui_set_colourmap(hmap);          ui_set_colourmap(hmap);
# Line 600  process_update_pdu(STREAM s) Line 640  process_update_pdu(STREAM s)
640                          break;                          break;
641    
642                  default:                  default:
643                          NOTIMP("update %d\n", update_type);                          unimpl("update %d\n", update_type);
644          }          }
645    
646  }  }
# Line 634  process_data_pdu(STREAM s) Line 674  process_data_pdu(STREAM s)
674                          break;                          break;
675    
676                  default:                  default:
677                          NOTIMP("data PDU %d\n", data_pdu_type);                          unimpl("data PDU %d\n", data_pdu_type);
678          }          }
679  }  }
680    
# Line 661  rdp_main_loop() Line 701  rdp_main_loop()
701                                  break;                                  break;
702    
703                          default:                          default:
704                                  NOTIMP("PDU %d\n", type);                                  unimpl("PDU %d\n", type);
705                  }                  }
706          }          }
707  }  }
# Line 674  rdp_connect(char *server, uint32 flags, Line 714  rdp_connect(char *server, uint32 flags,
714          if (!sec_connect(server))          if (!sec_connect(server))
715                  return False;                  return False;
716    
717          rdp_send_logon_info(flags, domain, username, password,          rdp_send_logon_info(flags, domain, username, password, command, directory);
                             command, directory);  
718          return True;          return True;
719  }  }
720    

Legend:
Removed from v.25  
changed lines
  Added in v.82

  ViewVC Help
Powered by ViewVC 1.1.26