/[rdesktop]/jpeg/rdesktop/trunk/rdesktop.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 /jpeg/rdesktop/trunk/rdesktop.c

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

sourceforge.net/trunk/rdesktop/rdesktop.c revision 857 by stargo, Sun Mar 13 13:36:04 2005 UTC jpeg/rdesktop/trunk/rdesktop.c revision 1508 by dpavlin, Mon Jul 20 16:47:49 2009 UTC
# Line 1  Line 1 
1  /* -*- c-basic-offset: 8 -*-  /* -*- c-basic-offset: 8 -*-
2     rdesktop: A Remote Desktop Protocol client.     rdesktop: A Remote Desktop Protocol client.
3     Entrypoint and utility functions     Entrypoint and utility functions
4     Copyright (C) Matthew Chapman 1999-2005     Copyright (C) Matthew Chapman 1999-2008
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 30  Line 30 
30  #include <errno.h>  #include <errno.h>
31  #include "rdesktop.h"  #include "rdesktop.h"
32    
 #ifdef HAVE_ICONV  
33  #ifdef HAVE_LOCALE_H  #ifdef HAVE_LOCALE_H
34  #include <locale.h>  #include <locale.h>
35  #endif  #endif
36    #ifdef HAVE_ICONV
37  #ifdef HAVE_LANGINFO_H  #ifdef HAVE_LANGINFO_H
38  #include <langinfo.h>  #include <langinfo.h>
39  #endif  #endif
40  #endif  #endif
41    
42  #ifdef EGD_SOCKET  #ifdef EGD_SOCKET
43    #include <sys/types.h>
44  #include <sys/socket.h>         /* socket connect */  #include <sys/socket.h>         /* socket connect */
45  #include <sys/un.h>             /* sockaddr_un */  #include <sys/un.h>             /* sockaddr_un */
46  #endif  #endif
47    
48  #include <openssl/md5.h>  #include "ssl.h"
49    
50    /* DJ globals begin */
51    unsigned long long g_time_last_write = 0;
52    unsigned long long g_time_last_change = 0;
53    uint32 g_pixels_changed;
54    uint8 * g_bitmap_data = 0;
55    uint8 * g_bitmap_data_last_write = 0;
56    /* DJ globals end */
57    
58  char g_title[64] = "";  char g_title[64] = "";
59  char g_username[64];  char *g_username;
60  char g_hostname[16];  char g_hostname[16];
61  char keymapname[16];  char g_keymapname[PATH_MAX] = "";
62  int g_keylayout = 0x409;        /* Defaults to US keyboard layout */  unsigned int g_keylayout = 0x409;       /* Defaults to US keyboard layout */
63    int g_keyboard_type = 0x4;      /* Defaults to US keyboard layout */
64    int g_keyboard_subtype = 0x0;   /* Defaults to US keyboard layout */
65    int g_keyboard_functionkeys = 0xc;      /* Defaults to US keyboard layout */
66    
67  int g_width = 800;              /* width is special: If 0, the  int g_width = 800;              /* width is special: If 0, the
68                                     geometry will be fetched from                                     geometry will be fetched from
# Line 60  int g_width = 800;             /* width is special: Line 72  int g_width = 800;             /* width is special:
72  int g_height = 600;  int g_height = 600;
73  int g_xpos = 0;  int g_xpos = 0;
74  int g_ypos = 0;  int g_ypos = 0;
75    int g_pos = 0;                  /* 0 position unspecified,
76                                       1 specified,
77                                       2 xpos neg,
78                                       4 ypos neg  */
79  extern int g_tcp_port_rdp;  extern int g_tcp_port_rdp;
80  int g_server_bpp = 8;  int g_server_depth = -1;
81  int g_win_button_size = 0;      /* If zero, disable single app mode */  int g_win_button_size = 0;      /* If zero, disable single app mode */
82  BOOL g_bitmap_compression = True;  RD_BOOL g_bitmap_compression = True;
83  BOOL g_sendmotion = True;  RD_BOOL g_sendmotion = True;
84  BOOL g_bitmap_cache = True;  RD_BOOL g_bitmap_cache = True;
85  BOOL g_bitmap_cache_persist_enable = False;  RD_BOOL g_bitmap_cache_persist_enable = False;
86  BOOL g_bitmap_cache_precache = True;  RD_BOOL g_bitmap_cache_precache = True;
87  BOOL g_encryption = True;  RD_BOOL g_encryption = True;
88  BOOL packet_encryption = True;  RD_BOOL g_packet_encryption = True;
89  BOOL g_desktop_save = True;     /* desktop save order */  RD_BOOL g_desktop_save = True;  /* desktop save order */
90  BOOL g_polygon_ellipse_orders = True;   /* polygon / ellipse orders */  RD_BOOL g_polygon_ellipse_orders = True;        /* polygon / ellipse orders */
91  BOOL g_fullscreen = False;  RD_BOOL g_fullscreen = False;
92  BOOL g_grab_keyboard = True;  RD_BOOL g_grab_keyboard = True;
93  BOOL g_hide_decorations = False;  RD_BOOL g_hide_decorations = False;
94  BOOL g_use_rdp5 = True;  RD_BOOL g_use_rdp5 = True;
95  BOOL g_console_session = False;  RD_BOOL g_rdpclip = True;
96  BOOL g_numlock_sync = False;  RD_BOOL g_console_session = False;
97  BOOL g_owncolmap = False;  RD_BOOL g_numlock_sync = False;
98  BOOL g_ownbackstore = True;     /* We can't rely on external BackingStore */  RD_BOOL g_lspci_enabled = False;
99    RD_BOOL g_owncolmap = False;
100    RD_BOOL g_ownbackstore = True;  /* We can't rely on external BackingStore */
101    RD_BOOL g_seamless_rdp = False;
102  uint32 g_embed_wnd;  uint32 g_embed_wnd;
103  uint32 g_rdp5_performanceflags =  uint32 g_rdp5_performanceflags =
104          RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS;          RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS;
105    /* Session Directory redirection */
106    RD_BOOL g_redirect = False;
107    char g_redirect_server[64];
108    char g_redirect_domain[16];
109    char g_redirect_password[64];
110    char *g_redirect_username;
111    char g_redirect_cookie[128];
112    uint32 g_redirect_flags = 0;
113    
114  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
115  BOOL g_rdpsnd = False;  RD_BOOL g_rdpsnd = False;
116  #endif  #endif
117    
118  #ifdef HAVE_ICONV  #ifdef HAVE_ICONV
# Line 108  static void Line 135  static void
135  usage(char *program)  usage(char *program)
136  {  {
137          fprintf(stderr, "rdesktop: A Remote Desktop Protocol client.\n");          fprintf(stderr, "rdesktop: A Remote Desktop Protocol client.\n");
138          fprintf(stderr, "Version " VERSION ". Copyright (C) 1999-2005 Matt Chapman.\n");          fprintf(stderr, "Version " VERSION ". Copyright (C) 1999-2008 Matthew Chapman.\n");
139          fprintf(stderr, "See http://www.rdesktop.org/ for more information.\n\n");          fprintf(stderr, "See http://www.rdesktop.org/ for more information.\n\n");
140    
141          fprintf(stderr, "Usage: %s [options] server[:port]\n", program);          fprintf(stderr, "Usage: %s [options] server[:port]\n", program);
# Line 129  usage(char *program) Line 156  usage(char *program)
156  #ifdef HAVE_ICONV  #ifdef HAVE_ICONV
157          fprintf(stderr, "   -L: local codepage\n");          fprintf(stderr, "   -L: local codepage\n");
158  #endif  #endif
159            fprintf(stderr, "   -A: enable SeamlessRDP mode\n");
160          fprintf(stderr, "   -B: use BackingStore of X-server (if available)\n");          fprintf(stderr, "   -B: use BackingStore of X-server (if available)\n");
161          fprintf(stderr, "   -e: disable encryption (French TS)\n");          fprintf(stderr, "   -e: disable encryption (French TS)\n");
162          fprintf(stderr, "   -E: disable encryption from client to server\n");          fprintf(stderr, "   -E: disable encryption from client to server\n");
# Line 159  usage(char *program) Line 187  usage(char *program)
187          fprintf(stderr, "         '-r printer:mydeskjet': enable printer redirection\n");          fprintf(stderr, "         '-r printer:mydeskjet': enable printer redirection\n");
188          fprintf(stderr,          fprintf(stderr,
189                  "             or      mydeskjet=\"HP LaserJet IIIP\" to enter server driver as well\n");                  "             or      mydeskjet=\"HP LaserJet IIIP\" to enter server driver as well\n");
190          fprintf(stderr, "         '-r sound:[local|off|remote]': enable sound redirection\n");  #ifdef WITH_RDPSND
191            fprintf(stderr,
192                    "         '-r sound:[local[:driver[:device]]|off|remote]': enable sound redirection\n");
193          fprintf(stderr, "                     remote would leave sound on server\n");          fprintf(stderr, "                     remote would leave sound on server\n");
194            fprintf(stderr, "                     available drivers for 'local':\n");
195            rdpsnd_show_help();
196    #endif
197            fprintf(stderr,
198                    "         '-r clipboard:[off|PRIMARYCLIPBOARD|CLIPBOARD]': enable clipboard\n");
199            fprintf(stderr, "                      redirection.\n");
200            fprintf(stderr,
201                    "                      'PRIMARYCLIPBOARD' looks at both PRIMARY and CLIPBOARD\n");
202            fprintf(stderr, "                      when sending data to server.\n");
203            fprintf(stderr, "                      'CLIPBOARD' looks at only CLIPBOARD.\n");
204    #ifdef WITH_SCARD
205            fprintf(stderr, "         '-r scard[:\"Scard Name\"=\"Alias Name[;Vendor Name]\"[,...]]\n");
206            fprintf(stderr, "          example: -r scard:\"eToken PRO 00 00\"=\"AKS ifdh 0\"\n");
207            fprintf(stderr,
208                    "                   \"eToken PRO 00 00\" -> Device in Linux/Unix enviroment\n");
209            fprintf(stderr,
210                    "                   \"AKS ifdh 0\"       -> Device shown in Windows enviroment \n");
211            fprintf(stderr, "          example: -r scard:\"eToken PRO 00 00\"=\"AKS ifdh 0;AKS\"\n");
212            fprintf(stderr,
213                    "                   \"eToken PRO 00 00\" -> Device in Linux/Unix enviroment\n");
214            fprintf(stderr,
215                    "                   \"AKS ifdh 0\"       -> Device shown in Windows enviroment \n");
216            fprintf(stderr,
217                    "                   \"AKS\"              -> Device vendor name                 \n");
218    #endif
219          fprintf(stderr, "   -0: attach to console\n");          fprintf(stderr, "   -0: attach to console\n");
220          fprintf(stderr, "   -4: use RDP version 4\n");          fprintf(stderr, "   -4: use RDP version 4\n");
221          fprintf(stderr, "   -5: use RDP version 5 (default)\n");          fprintf(stderr, "   -5: use RDP version 5 (default)\n");
222  }  }
223    
224  void  static void
225  print_disconnect_reason(uint16 reason)  print_disconnect_reason(uint16 reason)
226  {  {
227          char *text;          char *text;
# Line 266  print_disconnect_reason(uint16 reason) Line 321  print_disconnect_reason(uint16 reason)
321          fprintf(stderr, "disconnect: %s.\n", text);          fprintf(stderr, "disconnect: %s.\n", text);
322  }  }
323    
324  static BOOL  static void
325    rdesktop_reset_state(void)
326    {
327            rdp_reset_state();
328    }
329    
330    static RD_BOOL
331  read_password(char *password, int size)  read_password(char *password, int size)
332  {  {
333          struct termios tios;          struct termios tios;
334          BOOL ret = False;          RD_BOOL ret = False;
335          int istty = 0;          int istty = 0;
336          char *p;          char *p;
337    
# Line 358  main(int argc, char *argv[]) Line 419  main(int argc, char *argv[])
419          char fullhostname[64];          char fullhostname[64];
420          char domain[16];          char domain[16];
421          char password[64];          char password[64];
422          char shell[128];          char shell[256];
423          char directory[32];          char directory[256];
424          BOOL prompt_password, deactivated;          RD_BOOL prompt_password, deactivated;
425          struct passwd *pw;          struct passwd *pw;
426          uint32 flags, ext_disc_reason = 0;          uint32 flags, ext_disc_reason = 0;
427          char *p;          char *p;
428          int c;          int c;
429            char *locale = NULL;
430          int username_option = 0;          int username_option = 0;
431            RD_BOOL geometry_option = False;
432            int run_count = 0;      /* Session Directory support */
433            RD_BOOL continue_connect = True;        /* Session Directory support */
434    #ifdef WITH_RDPSND
435            char *rdpsnd_optarg = NULL;
436    #endif
437    
438    #ifdef HAVE_LOCALE_H
439            /* Set locale according to environment */
440            locale = setlocale(LC_ALL, "");
441            if (locale)
442            {
443                    locale = xstrdup(locale);
444            }
445    
446    #endif
447          flags = RDP_LOGON_NORMAL;          flags = RDP_LOGON_NORMAL;
448          prompt_password = False;          prompt_password = False;
449          domain[0] = password[0] = shell[0] = directory[0] = 0;          domain[0] = password[0] = shell[0] = directory[0] = 0;
         strcpy(keymapname, "en-us");  
450          g_embed_wnd = 0;          g_embed_wnd = 0;
451    
452          g_num_devices = 0;          g_num_devices = 0;
# Line 383  main(int argc, char *argv[]) Line 458  main(int argc, char *argv[])
458  #endif  #endif
459    
460          while ((c = getopt(argc, argv,          while ((c = getopt(argc, argv,
461                             VNCOPT "u:L:d:s:c:p:n:k:g:fbBeEmzCDKS:T:NX:a:x:Pr:045h?")) != -1)                             VNCOPT "Au:L:d:s:c:p:n:k:g:fbBeEmzCDKS:T:NX:a:x:Pr:045h?")) != -1)
462          {          {
463                  switch (c)                  switch (c)
464                  {                  {
# Line 401  main(int argc, char *argv[]) Line 476  main(int argc, char *argv[])
476                                  break;                                  break;
477  #endif  #endif
478    
479                            case 'A':
480                                    g_seamless_rdp = True;
481                                    break;
482    
483                          case 'u':                          case 'u':
484                                  STRNCPY(g_username, optarg, sizeof(g_username));                                  g_username = (char *) xmalloc(strlen(optarg) + 1);
485                                    STRNCPY(g_username, optarg, strlen(optarg) + 1);
486                                  username_option = 1;                                  username_option = 1;
487                                  break;                                  break;
488    
# Line 447  main(int argc, char *argv[]) Line 527  main(int argc, char *argv[])
527                                  break;                                  break;
528    
529                          case 'k':                          case 'k':
530                                  STRNCPY(keymapname, optarg, sizeof(keymapname));                                  STRNCPY(g_keymapname, optarg, sizeof(g_keymapname));
531                                  break;                                  break;
532    
533                          case 'g':                          case 'g':
534                                    geometry_option = True;
535                                  g_fullscreen = False;                                  g_fullscreen = False;
536                                  if (!strcmp(optarg, "workarea"))                                  if (!strcmp(optarg, "workarea"))
537                                  {                                  {
# Line 481  main(int argc, char *argv[]) Line 562  main(int argc, char *argv[])
562                                  }                                  }
563    
564                                  if (*p == '+' || *p == '-')                                  if (*p == '+' || *p == '-')
565                                    {
566                                            g_pos |= (*p == '-') ? 2 : 1;
567                                          g_xpos = strtol(p, &p, 10);                                          g_xpos = strtol(p, &p, 10);
568    
569                                    }
570                                  if (*p == '+' || *p == '-')                                  if (*p == '+' || *p == '-')
571                                    {
572                                            g_pos |= (*p == '-') ? 4 : 1;
573                                          g_ypos = strtol(p, NULL, 10);                                          g_ypos = strtol(p, NULL, 10);
574                                    }
575    
576                                  break;                                  break;
577    
# Line 504  main(int argc, char *argv[]) Line 591  main(int argc, char *argv[])
591                                  g_encryption = False;                                  g_encryption = False;
592                                  break;                                  break;
593                          case 'E':                          case 'E':
594                                  packet_encryption = False;                                  g_packet_encryption = False;
595                                  break;                                  break;
596                          case 'm':                          case 'm':
597                                  g_sendmotion = False;                                  g_sendmotion = False;
# Line 548  main(int argc, char *argv[]) Line 635  main(int argc, char *argv[])
635                                  break;                                  break;
636    
637                          case 'X':                          case 'X':
638                                  g_embed_wnd = strtol(optarg, NULL, 10);                                  g_embed_wnd = strtol(optarg, NULL, 0);
639                                  break;                                  break;
640    
641                          case 'a':                          case 'a':
642                                  g_server_bpp = strtol(optarg, NULL, 10);                                  g_server_depth = strtol(optarg, NULL, 10);
643                                  if (g_server_bpp != 8 && g_server_bpp != 16 && g_server_bpp != 15                                  if (g_server_depth != 8 &&
644                                      && g_server_bpp != 24)                                      g_server_depth != 16 &&
645                                        g_server_depth != 15 && g_server_depth != 24
646                                        && g_server_depth != 32)
647                                  {                                  {
648                                          error("invalid server bpp\n");                                          error("Invalid server colour depth.\n");
649                                          return 1;                                          return 1;
650                                  }                                  }
651                                  break;                                  break;
652    
653                          case 'z':                          case 'z':
654                                  DEBUG(("rdp compression enabled\n"));                                  DEBUG(("rdp compression enabled\n"));
655                                  flags |= RDP_COMPRESSION;                                  flags |= (RDP_LOGON_COMPRESSION | RDP_LOGON_COMPRESSION2);
656                                  break;                                  break;
657    
658                          case 'x':                          case 'x':
659                                  if (strncmp("modem", optarg, 1) == 0)                                  if (str_startswith(optarg, "m"))        /* modem */
660                                  {                                  {
661                                          g_rdp5_performanceflags =                                          g_rdp5_performanceflags =
662                                                  RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG |                                                  RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG |
663                                                  RDP5_NO_MENUANIMATIONS | RDP5_NO_THEMING;                                                  RDP5_NO_MENUANIMATIONS | RDP5_NO_THEMING;
664                                  }                                  }
665                                  else if (strncmp("broadband", optarg, 1) == 0)                                  else if (str_startswith(optarg, "b"))   /* broadband */
666                                  {                                  {
667                                          g_rdp5_performanceflags = RDP5_NO_WALLPAPER;                                          g_rdp5_performanceflags = RDP5_NO_WALLPAPER;
668                                  }                                  }
669                                  else if (strncmp("lan", optarg, 1) == 0)                                  else if (str_startswith(optarg, "l"))   /* lan */
670                                  {                                  {
671                                          g_rdp5_performanceflags = RDP5_DISABLE_NOTHING;                                          g_rdp5_performanceflags = RDP5_DISABLE_NOTHING;
672                                  }                                  }
# Line 593  main(int argc, char *argv[]) Line 682  main(int argc, char *argv[])
682    
683                          case 'r':                          case 'r':
684    
685                                  if (strncmp("sound", optarg, 5) == 0)                                  if (str_startswith(optarg, "sound"))
686                                  {                                  {
687                                          optarg += 5;                                          optarg += 5;
688    
689                                          if (*optarg == ':')                                          if (*optarg == ':')
690                                          {                                          {
691                                                  *optarg++;                                                  optarg++;
692                                                  while ((p = next_arg(optarg, ',')))                                                  while ((p = next_arg(optarg, ',')))
693                                                  {                                                  {
694                                                          if (strncmp("remote", optarg, 6) == 0)                                                          if (str_startswith(optarg, "remote"))
695                                                                  flags |= RDP_LOGON_LEAVE_AUDIO;                                                                  flags |= RDP_LOGON_LEAVE_AUDIO;
696    
697                                                          if (strncmp("local", optarg, 5) == 0)                                                          if (str_startswith(optarg, "local"))
698  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
699                                                            {
700                                                                    rdpsnd_optarg =
701                                                                            next_arg(optarg, ':');
702                                                                  g_rdpsnd = True;                                                                  g_rdpsnd = True;
703                                                            }
704    
705  #else  #else
706                                                                  warning("Not compiled with sound support\n");                                                                  warning("Not compiled with sound support\n");
707  #endif  #endif
708    
709                                                          if (strncmp("off", optarg, 3) == 0)                                                          if (str_startswith(optarg, "off"))
710  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
711                                                                  g_rdpsnd = False;                                                                  g_rdpsnd = False;
712  #else  #else
# Line 631  main(int argc, char *argv[]) Line 725  main(int argc, char *argv[])
725  #endif  #endif
726                                          }                                          }
727                                  }                                  }
728                                  else if (strncmp("disk", optarg, 4) == 0)                                  else if (str_startswith(optarg, "disk"))
729                                  {                                  {
730                                          /* -r disk:h:=/mnt/floppy */                                          /* -r disk:h:=/mnt/floppy */
731                                          disk_enum_devices(&g_num_devices, optarg + 4);                                          disk_enum_devices(&g_num_devices, optarg + 4);
732                                  }                                  }
733                                  else if (strncmp("comport", optarg, 7) == 0)                                  else if (str_startswith(optarg, "comport"))
734                                  {                                  {
735                                          serial_enum_devices(&g_num_devices, optarg + 7);                                          serial_enum_devices(&g_num_devices, optarg + 7);
736                                  }                                  }
737                                  else if (strncmp("lptport", optarg, 7) == 0)                                  else if (str_startswith(optarg, "lspci"))
738                                    {
739                                            g_lspci_enabled = True;
740                                    }
741                                    else if (str_startswith(optarg, "lptport"))
742                                  {                                  {
743                                          parallel_enum_devices(&g_num_devices, optarg + 7);                                          parallel_enum_devices(&g_num_devices, optarg + 7);
744                                  }                                  }
745                                  else if (strncmp("printer", optarg, 7) == 0)                                  else if (str_startswith(optarg, "printer"))
746                                  {                                  {
747                                          printer_enum_devices(&g_num_devices, optarg + 7);                                          printer_enum_devices(&g_num_devices, optarg + 7);
748                                  }                                  }
749                                  else if (strncmp("clientname", optarg, 7) == 0)                                  else if (str_startswith(optarg, "clientname"))
750                                  {                                  {
751                                          g_rdpdr_clientname = xmalloc(strlen(optarg + 11) + 1);                                          g_rdpdr_clientname = xmalloc(strlen(optarg + 11) + 1);
752                                          strcpy(g_rdpdr_clientname, optarg + 11);                                          strcpy(g_rdpdr_clientname, optarg + 11);
753                                  }                                  }
754                                    else if (str_startswith(optarg, "clipboard"))
755                                    {
756                                            optarg += 9;
757    
758                                            if (*optarg == ':')
759                                            {
760                                                    optarg++;
761    
762                                                    if (str_startswith(optarg, "off"))
763                                                            g_rdpclip = False;
764                                                    else
765                                                            cliprdr_set_mode(optarg);
766                                            }
767                                            else
768                                                    g_rdpclip = True;
769                                    }
770                                    else if (strncmp("scard", optarg, 5) == 0)
771                                    {
772    #ifdef WITH_SCARD
773                                            scard_enum_devices(&g_num_devices, optarg + 5);
774    #else
775                                            warning("Not compiled with smartcard support\n");
776    #endif
777                                    }
778                                  else                                  else
779                                  {                                  {
780                                          warning("Unknown -r argument\n\n\tPossible arguments are: comport, disk, lptport, printer, sound\n");                                          warning("Unknown -r argument\n\n\tPossible arguments are: comport, disk, lptport, printer, sound, clipboard, scard\n");
781                                  }                                  }
782                                  break;                                  break;
783    
# Line 688  main(int argc, char *argv[]) Line 810  main(int argc, char *argv[])
810          STRNCPY(server, argv[optind], sizeof(server));          STRNCPY(server, argv[optind], sizeof(server));
811          parse_server_and_port(server);          parse_server_and_port(server);
812    
813            if (g_seamless_rdp)
814            {
815                    if (g_win_button_size)
816                    {
817                            error("You cannot use -S and -A at the same time\n");
818                            return 1;
819                    }
820                    g_rdp5_performanceflags &= ~RDP5_NO_FULLWINDOWDRAG;
821                    if (geometry_option)
822                    {
823                            error("You cannot use -g and -A at the same time\n");
824                            return 1;
825                    }
826                    if (g_fullscreen)
827                    {
828                            error("You cannot use -f and -A at the same time\n");
829                            return 1;
830                    }
831                    if (g_hide_decorations)
832                    {
833                            error("You cannot use -D and -A at the same time\n");
834                            return 1;
835                    }
836                    if (g_embed_wnd)
837                    {
838                            error("You cannot use -X and -A at the same time\n");
839                            return 1;
840                    }
841                    if (!g_use_rdp5)
842                    {
843                            error("You cannot use -4 and -A at the same time\n");
844                            return 1;
845                    }
846                    g_width = -100;
847                    g_grab_keyboard = False;
848            }
849    
850          if (!username_option)          if (!username_option)
851          {          {
852                  pw = getpwuid(getuid());                  pw = getpwuid(getuid());
# Line 696  main(int argc, char *argv[]) Line 855  main(int argc, char *argv[])
855                          error("could not determine username, use -u\n");                          error("could not determine username, use -u\n");
856                          return 1;                          return 1;
857                  }                  }
858                    /* +1 for trailing \0 */
859                  STRNCPY(g_username, pw->pw_name, sizeof(g_username));                  int pwlen = strlen(pw->pw_name) + 1;
860                    g_username = (char *) xmalloc(pwlen);
861                    STRNCPY(g_username, pw->pw_name, pwlen);
862          }          }
863    
864  #ifdef HAVE_ICONV  #ifdef HAVE_ICONV
# Line 713  main(int argc, char *argv[]) Line 874  main(int argc, char *argv[])
874                  }                  }
875          }          }
876  #endif  #endif
877    
878          if (g_hostname[0] == 0)          if (g_hostname[0] == 0)
879          {          {
880                  if (gethostname(fullhostname, sizeof(fullhostname)) == -1)                  if (gethostname(fullhostname, sizeof(fullhostname)) == -1)
# Line 729  main(int argc, char *argv[]) Line 890  main(int argc, char *argv[])
890                  STRNCPY(g_hostname, fullhostname, sizeof(g_hostname));                  STRNCPY(g_hostname, fullhostname, sizeof(g_hostname));
891          }          }
892    
893          if ((flags & RDP_COMPRESSION) && (g_server_bpp > 8))          if (g_keymapname[0] == 0)
894          {          {
895                  warning("rdp compression not supported for bpp > 8, compression disabled\n");                  if (locale && xkeymap_from_locale(locale))
896                  flags ^= RDP_COMPRESSION;                  {
897                            fprintf(stderr, "Autoselected keyboard map %s\n", g_keymapname);
898                    }
899                    else
900                    {
901                            STRNCPY(g_keymapname, "en-us", sizeof(g_keymapname));
902                    }
903          }          }
904            if (locale)
905                    xfree(locale);
906    
907    
908          if (prompt_password && read_password(password, sizeof(password)))          if (prompt_password && read_password(password, sizeof(password)))
909                  flags |= RDP_LOGON_AUTO;                  flags |= RDP_LOGON_AUTO;
# Line 754  main(int argc, char *argv[]) Line 924  main(int argc, char *argv[])
924    
925  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
926          if (g_rdpsnd)          if (g_rdpsnd)
927                  rdpsnd_init();          {
928                    if (!rdpsnd_init(rdpsnd_optarg))
929                    {
930                            warning("Initializing sound-support failed!\n");
931                    }
932            }
933  #endif  #endif
934    
935            if (g_lspci_enabled)
936                    lspci_init();
937    
938          rdpdr_init();          rdpdr_init();
939    
940          if (!rdp_connect(server, flags, domain, password, shell, directory))          while (run_count < 2 && continue_connect)       /* add support for Session Directory; only reconnect once */
941                  return 1;          {
942                    if (run_count == 0)
943                    {
944                            if (!rdp_connect(server, flags, domain, password, shell, directory))
945                                    return 1;
946                    }
947                    else if (!rdp_reconnect
948                             (server, flags, domain, password, shell, directory, g_redirect_cookie))
949                            return 1;
950    
951          /* By setting encryption to False here, we have an encrypted login                  /* By setting encryption to False here, we have an encrypted login
952             packet but unencrypted transfer of other packets */                     packet but unencrypted transfer of other packets */
953          if (!packet_encryption)                  if (!g_packet_encryption)
954                  g_encryption = False;                          g_encryption = False;
955    
956    
957          DEBUG(("Connection successful.\n"));                  DEBUG(("Connection successful.\n"));
958          memset(password, 0, sizeof(password));                  memset(password, 0, sizeof(password));
959    
960          if (ui_create_window())                  if (run_count == 0)
961          {                          if (!ui_create_window())
962                  rdp_main_loop(&deactivated, &ext_disc_reason);                                  continue_connect = False;
963                  ui_destroy_window();  
964                    if (continue_connect)
965                            rdp_main_loop(&deactivated, &ext_disc_reason);
966    
967                    DEBUG(("Disconnecting...\n"));
968                    rdp_disconnect();
969    
970                    if ((g_redirect == True) && (run_count == 0))   /* Support for Session Directory */
971                    {
972                            /* reset state of major globals */
973                            rdesktop_reset_state();
974    
975                            STRNCPY(domain, g_redirect_domain, sizeof(domain));
976                            xfree(g_username);
977                            g_username = (char *) xmalloc(strlen(g_redirect_username) + 1);
978                            STRNCPY(g_username, g_redirect_username, sizeof(g_username));
979                            STRNCPY(password, g_redirect_password, sizeof(password));
980                            STRNCPY(server, g_redirect_server, sizeof(server));
981                            flags |= RDP_LOGON_AUTO;
982    
983                            g_redirect = False;
984                    }
985                    else
986                    {
987                            continue_connect = False;
988                            ui_destroy_window();
989                            break;
990                    }
991    
992                    run_count++;
993          }          }
994    
         DEBUG(("Disconnecting...\n"));  
         rdp_disconnect();  
995          cache_save_state();          cache_save_state();
996          ui_deinit();          ui_deinit();
997    
# Line 805  main(int argc, char *argv[]) Line 1019  main(int argc, char *argv[])
1019          }          }
1020    
1021  #endif  #endif
1022            if (g_redirect_username)
1023                    xfree(g_redirect_username);
1024    
1025            xfree(g_username);
1026  }  }
1027    
1028  #ifdef EGD_SOCKET  #ifdef EGD_SOCKET
1029  /* Read 32 random bytes from PRNGD or EGD socket (based on OpenSSL RAND_egd) */  /* Read 32 random bytes from PRNGD or EGD socket (based on OpenSSL RAND_egd) */
1030  static BOOL  static RD_BOOL
1031  generate_random_egd(uint8 * buf)  generate_random_egd(uint8 * buf)
1032  {  {
1033          struct sockaddr_un addr;          struct sockaddr_un addr;
1034          BOOL ret = False;          RD_BOOL ret = False;
1035          int fd;          int fd;
1036    
1037          fd = socket(AF_UNIX, SOCK_STREAM, 0);          fd = socket(AF_UNIX, SOCK_STREAM, 0);
# Line 852  generate_random(uint8 * random) Line 1069  generate_random(uint8 * random)
1069  {  {
1070          struct stat st;          struct stat st;
1071          struct tms tmsbuf;          struct tms tmsbuf;
1072          MD5_CTX md5;          SSL_MD5 md5;
1073          uint32 *r;          uint32 *r;
1074          int fd, n;          int fd, n;
1075    
# Line 884  generate_random(uint8 * random) Line 1101  generate_random(uint8 * random)
1101          r[7] = st.st_ctime;          r[7] = st.st_ctime;
1102    
1103          /* Hash both halves with MD5 to obscure possible patterns */          /* Hash both halves with MD5 to obscure possible patterns */
1104          MD5_Init(&md5);          ssl_md5_init(&md5);
1105          MD5_Update(&md5, random, 16);          ssl_md5_update(&md5, random, 16);
1106          MD5_Final(random, &md5);          ssl_md5_final(&md5, random);
1107          MD5_Update(&md5, random + 16, 16);          ssl_md5_update(&md5, random + 16, 16);
1108          MD5_Final(random + 16, &md5);          ssl_md5_final(&md5, random + 16);
1109  }  }
1110    
1111  /* malloc; exit if out of memory */  /* malloc; exit if out of memory */
# Line 904  xmalloc(int size) Line 1121  xmalloc(int size)
1121          return mem;          return mem;
1122  }  }
1123    
1124    /* Exit on NULL pointer. Use to verify result from XGetImage etc */
1125    void
1126    exit_if_null(void *ptr)
1127    {
1128            if (ptr == NULL)
1129            {
1130                    error("unexpected null pointer. Out of memory?\n");
1131                    exit(1);
1132            }
1133    }
1134    
1135    /* strdup */
1136    char *
1137    xstrdup(const char *s)
1138    {
1139            char *mem = strdup(s);
1140            if (mem == NULL)
1141            {
1142                    perror("strdup");
1143                    exit(1);
1144            }
1145            return mem;
1146    }
1147    
1148  /* realloc; exit if out of memory */  /* realloc; exit if out of memory */
1149  void *  void *
1150  xrealloc(void *oldmem, int size)  xrealloc(void *oldmem, size_t size)
1151  {  {
1152          void *mem;          void *mem;
1153    
1154          if (size < 1)          if (size == 0)
1155                  size = 1;                  size = 1;
1156          mem = realloc(oldmem, size);          mem = realloc(oldmem, size);
1157          if (mem == NULL)          if (mem == NULL)
1158          {          {
1159                  error("xrealloc %d\n", size);                  error("xrealloc %ld\n", size);
1160                  exit(1);                  exit(1);
1161          }          }
1162          return mem;          return mem;
# Line 1039  next_arg(char *src, char needle) Line 1280  next_arg(char *src, char needle)
1280                          while (*(mvp + 1) != (char) 0x00)                          while (*(mvp + 1) != (char) 0x00)
1281                          {                          {
1282                                  *mvp = *(mvp + 1);                                  *mvp = *(mvp + 1);
1283                                  *mvp++;                                  mvp++;
1284                          }                          }
1285                          *mvp = (char) 0x00;                          *mvp = (char) 0x00;
1286                          p = nextval;                          p = nextval;
# Line 1077  toupper_str(char *p) Line 1318  toupper_str(char *p)
1318  }  }
1319    
1320    
1321    RD_BOOL
1322    str_startswith(const char *s, const char *prefix)
1323    {
1324            return (strncmp(s, prefix, strlen(prefix)) == 0);
1325    }
1326    
1327    
1328    /* Split input into lines, and call linehandler for each
1329       line. Incomplete lines are saved in the rest variable, which should
1330       initially point to NULL. When linehandler returns False, stop and
1331       return False. Otherwise, return True.  */
1332    RD_BOOL
1333    str_handle_lines(const char *input, char **rest, str_handle_lines_t linehandler, void *data)
1334    {
1335            char *buf, *p;
1336            char *oldrest;
1337            size_t inputlen;
1338            size_t buflen;
1339            size_t restlen = 0;
1340            RD_BOOL ret = True;
1341    
1342            /* Copy data to buffer */
1343            inputlen = strlen(input);
1344            if (*rest)
1345                    restlen = strlen(*rest);
1346            buflen = restlen + inputlen + 1;
1347            buf = (char *) xmalloc(buflen);
1348            buf[0] = '\0';
1349            if (*rest)
1350                    STRNCPY(buf, *rest, buflen);
1351            strncat(buf, input, inputlen);
1352            p = buf;
1353    
1354            while (1)
1355            {
1356                    char *newline = strchr(p, '\n');
1357                    if (newline)
1358                    {
1359                            *newline = '\0';
1360                            if (!linehandler(p, data))
1361                            {
1362                                    p = newline + 1;
1363                                    ret = False;
1364                                    break;
1365                            }
1366                            p = newline + 1;
1367                    }
1368                    else
1369                    {
1370                            break;
1371    
1372                    }
1373            }
1374    
1375            /* Save in rest */
1376            oldrest = *rest;
1377            restlen = buf + buflen - p;
1378            *rest = (char *) xmalloc(restlen);
1379            STRNCPY((*rest), p, restlen);
1380            xfree(oldrest);
1381    
1382            xfree(buf);
1383            return ret;
1384    }
1385    
1386    /* Execute the program specified by argv. For each line in
1387       stdout/stderr output, call linehandler. Returns false on failure. */
1388    RD_BOOL
1389    subprocess(char *const argv[], str_handle_lines_t linehandler, void *data)
1390    {
1391            pid_t child;
1392            int fd[2];
1393            int n = 1;
1394            char output[256];
1395            char *rest = NULL;
1396    
1397            if (pipe(fd) < 0)
1398            {
1399                    perror("pipe");
1400                    return False;
1401            }
1402    
1403            if ((child = fork()) < 0)
1404            {
1405                    perror("fork");
1406                    return False;
1407            }
1408    
1409            /* Child */
1410            if (child == 0)
1411            {
1412                    /* Close read end */
1413                    close(fd[0]);
1414    
1415                    /* Redirect stdout and stderr to pipe */
1416                    dup2(fd[1], 1);
1417                    dup2(fd[1], 2);
1418    
1419                    /* Execute */
1420                    execvp(argv[0], argv);
1421                    perror("Error executing child");
1422                    _exit(128);
1423            }
1424    
1425            /* Parent. Close write end. */
1426            close(fd[1]);
1427            while (n > 0)
1428            {
1429                    n = read(fd[0], output, 255);
1430                    output[n] = '\0';
1431                    str_handle_lines(output, &rest, linehandler, data);
1432            }
1433            xfree(rest);
1434    
1435            return True;
1436    }
1437    
1438    
1439  /* not all clibs got ltoa */  /* not all clibs got ltoa */
1440  #define LTOA_BUFSIZE (sizeof(long) * 8 + 1)  #define LTOA_BUFSIZE (sizeof(long) * 8 + 1)
1441    
# Line 1192  save_licence(unsigned char *data, int le Line 1551  save_licence(unsigned char *data, int le
1551  }  }
1552    
1553  /* Create the bitmap cache directory */  /* Create the bitmap cache directory */
1554  BOOL  RD_BOOL
1555  rd_pstcache_mkdir(void)  rd_pstcache_mkdir(void)
1556  {  {
1557          char *home;          char *home;
# Line 1269  rd_lseek_file(int fd, int offset) Line 1628  rd_lseek_file(int fd, int offset)
1628  }  }
1629    
1630  /* do a write lock on a file */  /* do a write lock on a file */
1631  BOOL  RD_BOOL
1632  rd_lock_file(int fd, int start, int len)  rd_lock_file(int fd, int start, int len)
1633  {  {
1634          struct flock lock;          struct flock lock;

Legend:
Removed from v.857  
changed lines
  Added in v.1508

  ViewVC Help
Powered by ViewVC 1.1.26