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

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

revision 782 by astrand, Thu Oct 7 13:00:29 2004 UTC revision 1207 by ossman_, Mon Mar 27 09:20:24 2006 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-2003     Copyright (C) Matthew Chapman 1999-2005
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    
33    #ifdef HAVE_LOCALE_H
34    #include <locale.h>
35    #endif
36    #ifdef HAVE_ICONV
37    #ifdef HAVE_LANGINFO_H
38    #include <langinfo.h>
39    #endif
40    #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
# Line 40  Line 50 
50  char g_title[64] = "";  char g_title[64] = "";
51  char g_username[64];  char g_username[64];
52  char g_hostname[16];  char g_hostname[16];
53  char keymapname[16];  char g_keymapname[PATH_MAX] = "";
54  int g_keylayout = 0x409;        /* Defaults to US keyboard layout */  unsigned int g_keylayout = 0x409;       /* Defaults to US keyboard layout */
55    int g_keyboard_type = 0x4;      /* Defaults to US keyboard layout */
56    int g_keyboard_subtype = 0x0;   /* Defaults to US keyboard layout */
57    int g_keyboard_functionkeys = 0xc;      /* Defaults to US keyboard layout */
58    
59  int g_width = 800;              /* width is special: If 0, the  int g_width = 800;              /* width is special: If 0, the
60                                     geometry will be fetched from                                     geometry will be fetched from
# Line 49  int g_width = 800;             /* width is special: Line 62  int g_width = 800;             /* width is special:
62                                     absolute value specifies the                                     absolute value specifies the
63                                     percent of the whole screen. */                                     percent of the whole screen. */
64  int g_height = 600;  int g_height = 600;
65    int g_xpos = 0;
66    int g_ypos = 0;
67    int g_pos = 0;                  /* 0 position unspecified,
68                                       1 specified,
69                                       2 xpos neg,
70                                       4 ypos neg  */
71  extern int g_tcp_port_rdp;  extern int g_tcp_port_rdp;
72  int g_server_bpp = 8;  int g_server_depth = 8;
73  int g_win_button_size = 0;      /* If zero, disable single app mode */  int g_win_button_size = 0;      /* If zero, disable single app mode */
74  BOOL g_bitmap_compression = True;  BOOL g_bitmap_compression = True;
75  BOOL g_sendmotion = True;  BOOL g_sendmotion = True;
# Line 59  BOOL g_bitmap_cache_persist_enable = Fal Line 78  BOOL g_bitmap_cache_persist_enable = Fal
78  BOOL g_bitmap_cache_precache = True;  BOOL g_bitmap_cache_precache = True;
79  BOOL g_encryption = True;  BOOL g_encryption = True;
80  BOOL packet_encryption = True;  BOOL packet_encryption = True;
81  BOOL g_desktop_save = True;  BOOL g_desktop_save = True;     /* desktop save order */
82    BOOL g_polygon_ellipse_orders = True;   /* polygon / ellipse orders */
83  BOOL g_fullscreen = False;  BOOL g_fullscreen = False;
84  BOOL g_grab_keyboard = True;  BOOL g_grab_keyboard = True;
85  BOOL g_hide_decorations = False;  BOOL g_hide_decorations = False;
86  BOOL g_use_rdp5 = True;  BOOL g_use_rdp5 = True;
87    BOOL g_rdpclip = True;
88  BOOL g_console_session = False;  BOOL g_console_session = False;
89  BOOL g_numlock_sync = False;  BOOL g_numlock_sync = False;
90    BOOL lspci_enabled = False;
91  BOOL g_owncolmap = False;  BOOL g_owncolmap = False;
92  BOOL g_ownbackstore = True;     /* We can't rely on external BackingStore */  BOOL g_ownbackstore = True;     /* We can't rely on external BackingStore */
93    BOOL g_seamless_rdp = False;
94  uint32 g_embed_wnd;  uint32 g_embed_wnd;
95  uint32 g_rdp5_performanceflags =  uint32 g_rdp5_performanceflags =
96          RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS;          RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS;
97    /* Session Directory redirection */
98    BOOL g_redirect = False;
99    char g_redirect_server[64];
100    char g_redirect_domain[16];
101    char g_redirect_password[64];
102    char g_redirect_username[64];
103    char g_redirect_cookie[128];
104    uint32 g_redirect_flags = 0;
105    
106  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
107  BOOL g_rdpsnd = False;  BOOL g_rdpsnd = False;
108  #endif  #endif
109    
110    #ifdef HAVE_ICONV
111    char g_codepage[16] = "";
112    #endif
113    
114  extern RDPDR_DEVICE g_rdpdr_device[];  extern RDPDR_DEVICE g_rdpdr_device[];
115  extern uint32 g_num_devices;  extern uint32 g_num_devices;
116  extern char *g_rdpdr_clientname;  extern char *g_rdpdr_clientname;
# Line 92  static void Line 127  static void
127  usage(char *program)  usage(char *program)
128  {  {
129          fprintf(stderr, "rdesktop: A Remote Desktop Protocol client.\n");          fprintf(stderr, "rdesktop: A Remote Desktop Protocol client.\n");
130          fprintf(stderr, "Version " VERSION ". Copyright (C) 1999-2003 Matt Chapman.\n");          fprintf(stderr, "Version " VERSION ". Copyright (C) 1999-2005 Matt Chapman.\n");
131          fprintf(stderr, "See http://www.rdesktop.org/ for more information.\n\n");          fprintf(stderr, "See http://www.rdesktop.org/ for more information.\n\n");
132    
133          fprintf(stderr, "Usage: %s [options] server[:port]\n", program);          fprintf(stderr, "Usage: %s [options] server[:port]\n", program);
# Line 110  usage(char *program) Line 145  usage(char *program)
145          fprintf(stderr, "   -g: desktop geometry (WxH)\n");          fprintf(stderr, "   -g: desktop geometry (WxH)\n");
146          fprintf(stderr, "   -f: full-screen mode\n");          fprintf(stderr, "   -f: full-screen mode\n");
147          fprintf(stderr, "   -b: force bitmap updates\n");          fprintf(stderr, "   -b: force bitmap updates\n");
148    #ifdef HAVE_ICONV
149            fprintf(stderr, "   -L: local codepage\n");
150    #endif
151            fprintf(stderr, "   -A: enable SeamlessRDP mode\n");
152          fprintf(stderr, "   -B: use BackingStore of X-server (if available)\n");          fprintf(stderr, "   -B: use BackingStore of X-server (if available)\n");
153          fprintf(stderr, "   -e: disable encryption (French TS)\n");          fprintf(stderr, "   -e: disable encryption (French TS)\n");
154          fprintf(stderr, "   -E: disable encryption from client to server\n");          fprintf(stderr, "   -E: disable encryption from client to server\n");
# Line 142  usage(char *program) Line 181  usage(char *program)
181                  "             or      mydeskjet=\"HP LaserJet IIIP\" to enter server driver as well\n");                  "             or      mydeskjet=\"HP LaserJet IIIP\" to enter server driver as well\n");
182          fprintf(stderr, "         '-r sound:[local|off|remote]': enable sound redirection\n");          fprintf(stderr, "         '-r sound:[local|off|remote]': enable sound redirection\n");
183          fprintf(stderr, "                     remote would leave sound on server\n");          fprintf(stderr, "                     remote would leave sound on server\n");
184            fprintf(stderr,
185                    "         '-r clipboard:[on|off|auto|PRIMARYCLIPBOARD|CLIPBOARD]': enable clip-\n");
186            fprintf(stderr, "                      board redirection.\n");
187            fprintf(stderr,
188                    "                      'on|auto|PRIMARYCLIPBOARD' looks at both PRIMARY and\n");
189            fprintf(stderr, "                      CLIPBOARD when sending data to server.\n");
190            fprintf(stderr, "                      'CLIPBOARD' looks at only CLIPBOARD.\n");
191          fprintf(stderr, "   -0: attach to console\n");          fprintf(stderr, "   -0: attach to console\n");
192          fprintf(stderr, "   -4: use RDP version 4\n");          fprintf(stderr, "   -4: use RDP version 4\n");
193          fprintf(stderr, "   -5: use RDP version 5 (default)\n");          fprintf(stderr, "   -5: use RDP version 5 (default)\n");
194  }  }
195    
196  void  static void
197  print_disconnect_reason(uint16 reason)  print_disconnect_reason(uint16 reason)
198  {  {
199          char *text;          char *text;
# Line 247  print_disconnect_reason(uint16 reason) Line 293  print_disconnect_reason(uint16 reason)
293          fprintf(stderr, "disconnect: %s.\n", text);          fprintf(stderr, "disconnect: %s.\n", text);
294  }  }
295    
296    static void
297    rdesktop_reset_state(void)
298    {
299            rdp_reset_state();
300    }
301    
302  static BOOL  static BOOL
303  read_password(char *password, int size)  read_password(char *password, int size)
304  {  {
# Line 339  main(int argc, char *argv[]) Line 391  main(int argc, char *argv[])
391          char fullhostname[64];          char fullhostname[64];
392          char domain[16];          char domain[16];
393          char password[64];          char password[64];
394          char shell[128];          char shell[256];
395          char directory[32];          char directory[256];
396          BOOL prompt_password, deactivated;          BOOL prompt_password, deactivated;
397          struct passwd *pw;          struct passwd *pw;
398          uint32 flags, ext_disc_reason = 0;          uint32 flags, ext_disc_reason = 0;
399          char *p;          char *p;
400          int c;          int c;
401            char *locale = NULL;
402          int username_option = 0;          int username_option = 0;
403            BOOL geometry_option = False;
404            int run_count = 0;      /* Session Directory support */
405            BOOL continue_connect = True;   /* Session Directory support */
406    
407    #ifdef HAVE_LOCALE_H
408            /* Set locale according to environment */
409            locale = setlocale(LC_ALL, "");
410            if (locale)
411            {
412                    locale = xstrdup(locale);
413            }
414    
415    #endif
416          flags = RDP_LOGON_NORMAL;          flags = RDP_LOGON_NORMAL;
417          prompt_password = False;          prompt_password = False;
418          domain[0] = password[0] = shell[0] = directory[0] = 0;          domain[0] = password[0] = shell[0] = directory[0] = 0;
         strcpy(keymapname, "en-us");  
419          g_embed_wnd = 0;          g_embed_wnd = 0;
420    
421          g_num_devices = 0;          g_num_devices = 0;
# Line 364  main(int argc, char *argv[]) Line 427  main(int argc, char *argv[])
427  #endif  #endif
428    
429          while ((c = getopt(argc, argv,          while ((c = getopt(argc, argv,
430                             VNCOPT "u: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)
431          {          {
432                  switch (c)                  switch (c)
433                  {                  {
# Line 382  main(int argc, char *argv[]) Line 445  main(int argc, char *argv[])
445                                  break;                                  break;
446  #endif  #endif
447    
448                            case 'A':
449                                    g_seamless_rdp = True;
450                                    break;
451    
452                          case 'u':                          case 'u':
453                                  STRNCPY(g_username, optarg, sizeof(g_username));                                  STRNCPY(g_username, optarg, sizeof(g_username));
454                                  username_option = 1;                                  username_option = 1;
455                                  break;                                  break;
456    
457                            case 'L':
458    #ifdef HAVE_ICONV
459                                    STRNCPY(g_codepage, optarg, sizeof(g_codepage));
460    #else
461                                    error("iconv support not available\n");
462    #endif
463                                    break;
464    
465                          case 'd':                          case 'd':
466                                  STRNCPY(domain, optarg, sizeof(domain));                                  STRNCPY(domain, optarg, sizeof(domain));
467                                  break;                                  break;
# Line 420  main(int argc, char *argv[]) Line 495  main(int argc, char *argv[])
495                                  break;                                  break;
496    
497                          case 'k':                          case 'k':
498                                  STRNCPY(keymapname, optarg, sizeof(keymapname));                                  STRNCPY(g_keymapname, optarg, sizeof(g_keymapname));
499                                  break;                                  break;
500    
501                          case 'g':                          case 'g':
502                                    geometry_option = True;
503                                  g_fullscreen = False;                                  g_fullscreen = False;
504                                  if (!strcmp(optarg, "workarea"))                                  if (!strcmp(optarg, "workarea"))
505                                  {                                  {
# Line 439  main(int argc, char *argv[]) Line 515  main(int argc, char *argv[])
515                                  }                                  }
516    
517                                  if (*p == 'x')                                  if (*p == 'x')
518                                          g_height = strtol(p + 1, NULL, 10);                                          g_height = strtol(p + 1, &p, 10);
519    
520                                  if (g_height <= 0)                                  if (g_height <= 0)
521                                  {                                  {
# Line 448  main(int argc, char *argv[]) Line 524  main(int argc, char *argv[])
524                                  }                                  }
525    
526                                  if (*p == '%')                                  if (*p == '%')
527                                    {
528                                          g_width = -g_width;                                          g_width = -g_width;
529                                            p++;
530                                    }
531    
532                                    if (*p == '+' || *p == '-')
533                                    {
534                                            g_pos |= (*p == '-') ? 2 : 1;
535                                            g_xpos = strtol(p, &p, 10);
536    
537                                    }
538                                    if (*p == '+' || *p == '-')
539                                    {
540                                            g_pos |= (*p == '-') ? 4 : 1;
541                                            g_ypos = strtol(p, NULL, 10);
542                                    }
543    
544                                  break;                                  break;
545    
# Line 512  main(int argc, char *argv[]) Line 603  main(int argc, char *argv[])
603                                  break;                                  break;
604    
605                          case 'X':                          case 'X':
606                                  g_embed_wnd = strtol(optarg, NULL, 10);                                  g_embed_wnd = strtol(optarg, NULL, 0);
607                                  break;                                  break;
608    
609                          case 'a':                          case 'a':
610                                  g_server_bpp = strtol(optarg, NULL, 10);                                  g_server_depth = strtol(optarg, NULL, 10);
611                                  if (g_server_bpp != 8 && g_server_bpp != 16 && g_server_bpp != 15                                  if (g_server_depth != 8 &&
612                                      && g_server_bpp != 24)                                      g_server_depth != 16 &&
613                                        g_server_depth != 15 && g_server_depth != 24)
614                                  {                                  {
615                                          error("invalid server bpp\n");                                          error("Invalid server colour depth.\n");
616                                          return 1;                                          return 1;
617                                  }                                  }
618                                  break;                                  break;
619    
620                          case 'z':                          case 'z':
621                                  DEBUG(("rdp compression enabled\n"));                                  DEBUG(("rdp compression enabled\n"));
622                                  flags |= RDP_COMPRESSION;                                  flags |= (RDP_LOGON_COMPRESSION | RDP_LOGON_COMPRESSION2);
623                                  break;                                  break;
624    
625                          case 'x':                          case 'x':
626                                  if (strncmp("modem", optarg, 1) == 0)                                  if (str_startswith(optarg, "m"))        /* modem */
627                                  {                                  {
628                                          g_rdp5_performanceflags =                                          g_rdp5_performanceflags =
629                                                  RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG |                                                  RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG |
630                                                  RDP5_NO_MENUANIMATIONS | RDP5_NO_THEMING;                                                  RDP5_NO_MENUANIMATIONS | RDP5_NO_THEMING;
631                                  }                                  }
632                                  else if (strncmp("broadband", optarg, 1) == 0)                                  else if (str_startswith(optarg, "b"))   /* broadband */
633                                  {                                  {
634                                          g_rdp5_performanceflags = RDP5_NO_WALLPAPER;                                          g_rdp5_performanceflags = RDP5_NO_WALLPAPER;
635                                  }                                  }
636                                  else if (strncmp("lan", optarg, 1) == 0)                                  else if (str_startswith(optarg, "l"))   /* lan */
637                                  {                                  {
638                                          g_rdp5_performanceflags = RDP5_DISABLE_NOTHING;                                          g_rdp5_performanceflags = RDP5_DISABLE_NOTHING;
639                                  }                                  }
# Line 557  main(int argc, char *argv[]) Line 649  main(int argc, char *argv[])
649    
650                          case 'r':                          case 'r':
651    
652                                  if (strncmp("sound", optarg, 5) == 0)                                  if (str_startswith(optarg, "sound"))
653                                  {                                  {
654                                          optarg += 5;                                          optarg += 5;
655    
# Line 566  main(int argc, char *argv[]) Line 658  main(int argc, char *argv[])
658                                                  *optarg++;                                                  *optarg++;
659                                                  while ((p = next_arg(optarg, ',')))                                                  while ((p = next_arg(optarg, ',')))
660                                                  {                                                  {
661                                                          if (strncmp("remote", optarg, 6) == 0)                                                          if (str_startswith(optarg, "remote"))
662                                                                  flags |= RDP_LOGON_LEAVE_AUDIO;                                                                  flags |= RDP_LOGON_LEAVE_AUDIO;
663    
664                                                          if (strncmp("local", optarg, 5) == 0)                                                          if (str_startswith(optarg, "local"))
665  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
666                                                                  g_rdpsnd = True;                                                                  g_rdpsnd = True;
667  #else  #else
668                                                                  warning("Not compiled with sound support\n");                                                                  warning("Not compiled with sound support\n");
669  #endif  #endif
670    
671                                                          if (strncmp("off", optarg, 3) == 0)                                                          if (str_startswith(optarg, "off"))
672  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
673                                                                  g_rdpsnd = False;                                                                  g_rdpsnd = False;
674  #else  #else
# Line 595  main(int argc, char *argv[]) Line 687  main(int argc, char *argv[])
687  #endif  #endif
688                                          }                                          }
689                                  }                                  }
690                                  else if (strncmp("disk", optarg, 4) == 0)                                  else if (str_startswith(optarg, "disk"))
691                                  {                                  {
692                                          /* -r disk:h:=/mnt/floppy */                                          /* -r disk:h:=/mnt/floppy */
693                                          disk_enum_devices(&g_num_devices, optarg + 4);                                          disk_enum_devices(&g_num_devices, optarg + 4);
694                                  }                                  }
695                                  else if (strncmp("comport", optarg, 7) == 0)                                  else if (str_startswith(optarg, "comport"))
696                                  {                                  {
697                                          serial_enum_devices(&g_num_devices, optarg + 7);                                          serial_enum_devices(&g_num_devices, optarg + 7);
698                                  }                                  }
699                                  else if (strncmp("lptport", optarg, 7) == 0)                                  else if (str_startswith(optarg, "lspci"))
700                                    {
701                                            lspci_enabled = True;
702                                    }
703                                    else if (str_startswith(optarg, "lptport"))
704                                  {                                  {
705                                          parallel_enum_devices(&g_num_devices, optarg + 7);                                          parallel_enum_devices(&g_num_devices, optarg + 7);
706                                  }                                  }
707                                  else if (strncmp("printer", optarg, 7) == 0)                                  else if (str_startswith(optarg, "printer"))
708                                  {                                  {
709                                          printer_enum_devices(&g_num_devices, optarg + 7);                                          printer_enum_devices(&g_num_devices, optarg + 7);
710                                  }                                  }
711                                  else if (strncmp("clientname", optarg, 7) == 0)                                  else if (str_startswith(optarg, "clientname"))
712                                  {                                  {
713                                          g_rdpdr_clientname = xmalloc(strlen(optarg + 11) + 1);                                          g_rdpdr_clientname = xmalloc(strlen(optarg + 11) + 1);
714                                          strcpy(g_rdpdr_clientname, optarg + 11);                                          strcpy(g_rdpdr_clientname, optarg + 11);
715                                  }                                  }
716                                    else if (str_startswith(optarg, "clipboard"))
717                                    {
718                                            optarg += 9;
719    
720                                            if (*optarg == ':')
721                                            {
722                                                    optarg++;
723    
724                                                    if (str_startswith(optarg, "off"))
725                                                            g_rdpclip = False;
726                                                    else
727                                                            cliprdr_set_mode(optarg);
728                                            }
729                                            else
730                                                    g_rdpclip = True;
731                                    }
732                                  else                                  else
733                                  {                                  {
734                                          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\n");
735                                  }                                  }
736                                  break;                                  break;
737    
# Line 652  main(int argc, char *argv[]) Line 764  main(int argc, char *argv[])
764          STRNCPY(server, argv[optind], sizeof(server));          STRNCPY(server, argv[optind], sizeof(server));
765          parse_server_and_port(server);          parse_server_and_port(server);
766    
767            if (g_seamless_rdp)
768            {
769                    if (g_win_button_size)
770                    {
771                            error("You cannot use -S and -A at the same time\n");
772                            return 1;
773                    }
774                    g_rdp5_performanceflags &= ~RDP5_NO_FULLWINDOWDRAG;
775                    if (geometry_option)
776                    {
777                            error("You cannot use -g and -A at the same time\n");
778                            return 1;
779                    }
780                    if (g_fullscreen)
781                    {
782                            error("You cannot use -f and -A at the same time\n");
783                            return 1;
784                    }
785                    if (g_hide_decorations)
786                    {
787                            error("You cannot use -D and -A at the same time\n");
788                            return 1;
789                    }
790                    if (g_embed_wnd)
791                    {
792                            error("You cannot use -X and -A at the same time\n");
793                            return 1;
794                    }
795                    if (!g_use_rdp5)
796                    {
797                            error("You cannot use -4 and -A at the same time\n");
798                            return 1;
799                    }
800                    g_width = -100;
801                    g_grab_keyboard = False;
802            }
803    
804          if (!username_option)          if (!username_option)
805          {          {
806                  pw = getpwuid(getuid());                  pw = getpwuid(getuid());
# Line 664  main(int argc, char *argv[]) Line 813  main(int argc, char *argv[])
813                  STRNCPY(g_username, pw->pw_name, sizeof(g_username));                  STRNCPY(g_username, pw->pw_name, sizeof(g_username));
814          }          }
815    
816    #ifdef HAVE_ICONV
817            if (g_codepage[0] == 0)
818            {
819                    if (setlocale(LC_CTYPE, ""))
820                    {
821                            STRNCPY(g_codepage, nl_langinfo(CODESET), sizeof(g_codepage));
822                    }
823                    else
824                    {
825                            STRNCPY(g_codepage, DEFAULT_CODEPAGE, sizeof(g_codepage));
826                    }
827            }
828    #endif
829    
830          if (g_hostname[0] == 0)          if (g_hostname[0] == 0)
831          {          {
832                  if (gethostname(fullhostname, sizeof(fullhostname)) == -1)                  if (gethostname(fullhostname, sizeof(fullhostname)) == -1)
# Line 679  main(int argc, char *argv[]) Line 842  main(int argc, char *argv[])
842                  STRNCPY(g_hostname, fullhostname, sizeof(g_hostname));                  STRNCPY(g_hostname, fullhostname, sizeof(g_hostname));
843          }          }
844    
845            if (g_keymapname[0] == 0)
846            {
847                    if (locale && xkeymap_from_locale(locale))
848                    {
849                            fprintf(stderr, "Autoselected keyboard map %s\n", g_keymapname);
850                    }
851                    else
852                    {
853                            STRNCPY(g_keymapname, "en-us", sizeof(g_keymapname));
854                    }
855            }
856            if (locale)
857                    xfree(locale);
858    
859    
860          if (prompt_password && read_password(password, sizeof(password)))          if (prompt_password && read_password(password, sizeof(password)))
861                  flags |= RDP_LOGON_AUTO;                  flags |= RDP_LOGON_AUTO;
862    
# Line 700  main(int argc, char *argv[]) Line 878  main(int argc, char *argv[])
878          if (g_rdpsnd)          if (g_rdpsnd)
879                  rdpsnd_init();                  rdpsnd_init();
880  #endif  #endif
881    
882            if (lspci_enabled)
883                    lspci_init();
884    
885          rdpdr_init();          rdpdr_init();
886    
887          if (!rdp_connect(server, flags, domain, password, shell, directory))          while (run_count < 2 && continue_connect)       /* add support for Session Directory; only reconnect once */
888                  return 1;          {
889                    if (run_count == 0)
890                    {
891                            if (!rdp_connect(server, flags, domain, password, shell, directory))
892                                    return 1;
893                    }
894                    else if (!rdp_reconnect
895                             (server, flags, domain, password, shell, directory, g_redirect_cookie))
896                            return 1;
897    
898          /* By setting encryption to False here, we have an encrypted login                  /* By setting encryption to False here, we have an encrypted login
899             packet but unencrypted transfer of other packets */                     packet but unencrypted transfer of other packets */
900          if (!packet_encryption)                  if (!packet_encryption)
901                  g_encryption = False;                          g_encryption = False;
902    
903    
904          DEBUG(("Connection successful.\n"));                  DEBUG(("Connection successful.\n"));
905          memset(password, 0, sizeof(password));                  memset(password, 0, sizeof(password));
906    
907          if (ui_create_window())                  if (run_count == 0)
908          {                          if (!ui_create_window())
909                  rdp_main_loop(&deactivated, &ext_disc_reason);                                  continue_connect = False;
910                  ui_destroy_window();  
911                    if (continue_connect)
912                            rdp_main_loop(&deactivated, &ext_disc_reason);
913    
914                    DEBUG(("Disconnecting...\n"));
915                    rdp_disconnect();
916    
917                    if ((g_redirect == True) && (run_count == 0))   /* Support for Session Directory */
918                    {
919                            /* reset state of major globals */
920                            rdesktop_reset_state();
921    
922                            STRNCPY(domain, g_redirect_domain, sizeof(domain));
923                            STRNCPY(g_username, g_redirect_username, sizeof(g_username));
924                            STRNCPY(password, g_redirect_password, sizeof(password));
925                            STRNCPY(server, g_redirect_server, sizeof(server));
926                            flags |= RDP_LOGON_AUTO;
927    
928                            g_redirect = False;
929                    }
930                    else
931                    {
932                            continue_connect = False;
933                            ui_destroy_window();
934                            break;
935                    }
936    
937                    run_count++;
938          }          }
939    
         DEBUG(("Disconnecting...\n"));  
         rdp_disconnect();  
940          cache_save_state();          cache_save_state();
941          ui_deinit();          ui_deinit();
942    
# Line 848  xmalloc(int size) Line 1063  xmalloc(int size)
1063          return mem;          return mem;
1064  }  }
1065    
1066    /* strdup */
1067    char *
1068    xstrdup(const char *s)
1069    {
1070            char *mem = strdup(s);
1071            if (mem == NULL)
1072            {
1073                    perror("strdup");
1074                    exit(1);
1075            }
1076            return mem;
1077    }
1078    
1079  /* realloc; exit if out of memory */  /* realloc; exit if out of memory */
1080  void *  void *
1081  xrealloc(void *oldmem, int size)  xrealloc(void *oldmem, int size)
# Line 1021  toupper_str(char *p) Line 1249  toupper_str(char *p)
1249  }  }
1250    
1251    
1252    BOOL
1253    str_startswith(const char *s, const char *prefix)
1254    {
1255            return (strncmp(s, prefix, strlen(prefix)) == 0);
1256    }
1257    
1258    
1259    /* Split input into lines, and call linehandler for each
1260       line. Incomplete lines are saved in the rest variable, which should
1261       initially point to NULL. When linehandler returns False, stop and
1262       return False. Otherwise, return True.  */
1263    BOOL
1264    str_handle_lines(const char *input, char **rest, str_handle_lines_t linehandler, void *data)
1265    {
1266            char *buf, *p;
1267            char *oldrest;
1268            size_t inputlen;
1269            size_t buflen;
1270            size_t restlen = 0;
1271            BOOL ret = True;
1272    
1273            /* Copy data to buffer */
1274            inputlen = strlen(input);
1275            if (*rest)
1276                    restlen = strlen(*rest);
1277            buflen = restlen + inputlen + 1;
1278            buf = (char *) xmalloc(buflen);
1279            buf[0] = '\0';
1280            if (*rest)
1281                    STRNCPY(buf, *rest, buflen);
1282            strncat(buf, input, inputlen);
1283            p = buf;
1284    
1285            while (1)
1286            {
1287                    char *newline = strchr(p, '\n');
1288                    if (newline)
1289                    {
1290                            *newline = '\0';
1291                            if (!linehandler(p, data))
1292                            {
1293                                    p = newline + 1;
1294                                    ret = False;
1295                                    break;
1296                            }
1297                            p = newline + 1;
1298                    }
1299                    else
1300                    {
1301                            break;
1302    
1303                    }
1304            }
1305    
1306            /* Save in rest */
1307            oldrest = *rest;
1308            restlen = buf + buflen - p;
1309            *rest = (char *) xmalloc(restlen);
1310            STRNCPY((*rest), p, restlen);
1311            xfree(oldrest);
1312    
1313            xfree(buf);
1314            return ret;
1315    }
1316    
1317    /* Execute the program specified by argv. For each line in
1318       stdout/stderr output, call linehandler. Returns false on failure. */
1319    BOOL
1320    subprocess(char *const argv[], str_handle_lines_t linehandler, void *data)
1321    {
1322            pid_t child;
1323            int fd[2];
1324            int n = 1;
1325            char output[256];
1326            char *rest = NULL;
1327    
1328            if (pipe(fd) < 0)
1329            {
1330                    perror("pipe");
1331                    return False;
1332            }
1333    
1334            if ((child = fork()) < 0)
1335            {
1336                    perror("fork");
1337                    return False;
1338            }
1339    
1340            /* Child */
1341            if (child == 0)
1342            {
1343                    /* Close read end */
1344                    close(fd[0]);
1345    
1346                    /* Redirect stdout and stderr to pipe */
1347                    dup2(fd[1], 1);
1348                    dup2(fd[1], 2);
1349    
1350                    /* Execute */
1351                    execvp(argv[0], argv);
1352                    perror("Error executing child");
1353                    _exit(128);
1354            }
1355    
1356            /* Parent. Close write end. */
1357            close(fd[1]);
1358            while (n > 0)
1359            {
1360                    n = read(fd[0], output, 255);
1361                    output[n] = '\0';
1362                    str_handle_lines(output, &rest, linehandler, data);
1363            }
1364            xfree(rest);
1365    
1366            return True;
1367    }
1368    
1369    
1370  /* not all clibs got ltoa */  /* not all clibs got ltoa */
1371  #define LTOA_BUFSIZE (sizeof(long) * 8 + 1)  #define LTOA_BUFSIZE (sizeof(long) * 8 + 1)
1372    

Legend:
Removed from v.782  
changed lines
  Added in v.1207

  ViewVC Help
Powered by ViewVC 1.1.26