/[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 801 by astrand, Tue Nov 23 13:29:12 2004 UTC revision 1272 by stargo, Thu Sep 21 19:00:11 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 51  int g_width = 800;             /* width is special: Line 64  int g_width = 800;             /* width is special:
64  int g_height = 600;  int g_height = 600;
65  int g_xpos = 0;  int g_xpos = 0;
66  int g_ypos = 0;  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 = -1;
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 61  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 94  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 112  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 179  usage(char *program)
179          fprintf(stderr, "         '-r printer:mydeskjet': enable printer redirection\n");          fprintf(stderr, "         '-r printer:mydeskjet': enable printer redirection\n");
180          fprintf(stderr,          fprintf(stderr,
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");  #ifdef WITH_RDPSND
183            fprintf(stderr,
184                    "         '-r sound:[local[:driver[:device]]|off|remote]': enable sound redirection\n");
185          fprintf(stderr, "                     remote would leave sound on server\n");          fprintf(stderr, "                     remote would leave sound on server\n");
186            fprintf(stderr, "                     available drivers for 'local':\n");
187            rdpsnd_show_help();
188    #endif
189            fprintf(stderr,
190                    "         '-r clipboard:[off|PRIMARYCLIPBOARD|CLIPBOARD]': enable clipboard\n");
191            fprintf(stderr, "                      redirection.\n");
192            fprintf(stderr,
193                    "                      'PRIMARYCLIPBOARD' looks at both PRIMARY and CLIPBOARD\n");
194            fprintf(stderr, "                      when sending data to server.\n");
195            fprintf(stderr, "                      'CLIPBOARD' looks at only CLIPBOARD.\n");
196          fprintf(stderr, "   -0: attach to console\n");          fprintf(stderr, "   -0: attach to console\n");
197          fprintf(stderr, "   -4: use RDP version 4\n");          fprintf(stderr, "   -4: use RDP version 4\n");
198          fprintf(stderr, "   -5: use RDP version 5 (default)\n");          fprintf(stderr, "   -5: use RDP version 5 (default)\n");
199  }  }
200    
201  void  static void
202  print_disconnect_reason(uint16 reason)  print_disconnect_reason(uint16 reason)
203  {  {
204          char *text;          char *text;
# Line 249  print_disconnect_reason(uint16 reason) Line 298  print_disconnect_reason(uint16 reason)
298          fprintf(stderr, "disconnect: %s.\n", text);          fprintf(stderr, "disconnect: %s.\n", text);
299  }  }
300    
301    static void
302    rdesktop_reset_state(void)
303    {
304            rdp_reset_state();
305    }
306    
307  static BOOL  static BOOL
308  read_password(char *password, int size)  read_password(char *password, int size)
309  {  {
# Line 341  main(int argc, char *argv[]) Line 396  main(int argc, char *argv[])
396          char fullhostname[64];          char fullhostname[64];
397          char domain[16];          char domain[16];
398          char password[64];          char password[64];
399          char shell[128];          char shell[256];
400          char directory[32];          char directory[256];
401          BOOL prompt_password, deactivated;          BOOL prompt_password, deactivated;
402          struct passwd *pw;          struct passwd *pw;
403          uint32 flags, ext_disc_reason = 0;          uint32 flags, ext_disc_reason = 0;
404          char *p;          char *p;
405          int c;          int c;
406            char *locale = NULL;
407          int username_option = 0;          int username_option = 0;
408            BOOL geometry_option = False;
409            int run_count = 0;      /* Session Directory support */
410            BOOL continue_connect = True;   /* Session Directory support */
411            char *rdpsnd_optarg = NULL;
412    
413    #ifdef HAVE_LOCALE_H
414            /* Set locale according to environment */
415            locale = setlocale(LC_ALL, "");
416            if (locale)
417            {
418                    locale = xstrdup(locale);
419            }
420    
421    #endif
422          flags = RDP_LOGON_NORMAL;          flags = RDP_LOGON_NORMAL;
423          prompt_password = False;          prompt_password = False;
424          domain[0] = password[0] = shell[0] = directory[0] = 0;          domain[0] = password[0] = shell[0] = directory[0] = 0;
         strcpy(keymapname, "en-us");  
425          g_embed_wnd = 0;          g_embed_wnd = 0;
426    
427          g_num_devices = 0;          g_num_devices = 0;
# Line 366  main(int argc, char *argv[]) Line 433  main(int argc, char *argv[])
433  #endif  #endif
434    
435          while ((c = getopt(argc, argv,          while ((c = getopt(argc, argv,
436                             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)
437          {          {
438                  switch (c)                  switch (c)
439                  {                  {
# Line 384  main(int argc, char *argv[]) Line 451  main(int argc, char *argv[])
451                                  break;                                  break;
452  #endif  #endif
453    
454                            case 'A':
455                                    g_seamless_rdp = True;
456                                    break;
457    
458                          case 'u':                          case 'u':
459                                  STRNCPY(g_username, optarg, sizeof(g_username));                                  STRNCPY(g_username, optarg, sizeof(g_username));
460                                  username_option = 1;                                  username_option = 1;
461                                  break;                                  break;
462    
463                            case 'L':
464    #ifdef HAVE_ICONV
465                                    STRNCPY(g_codepage, optarg, sizeof(g_codepage));
466    #else
467                                    error("iconv support not available\n");
468    #endif
469                                    break;
470    
471                          case 'd':                          case 'd':
472                                  STRNCPY(domain, optarg, sizeof(domain));                                  STRNCPY(domain, optarg, sizeof(domain));
473                                  break;                                  break;
# Line 422  main(int argc, char *argv[]) Line 501  main(int argc, char *argv[])
501                                  break;                                  break;
502    
503                          case 'k':                          case 'k':
504                                  STRNCPY(keymapname, optarg, sizeof(keymapname));                                  STRNCPY(g_keymapname, optarg, sizeof(g_keymapname));
505                                  break;                                  break;
506    
507                          case 'g':                          case 'g':
508                                    geometry_option = True;
509                                  g_fullscreen = False;                                  g_fullscreen = False;
510                                  if (!strcmp(optarg, "workarea"))                                  if (!strcmp(optarg, "workarea"))
511                                  {                                  {
# Line 456  main(int argc, char *argv[]) Line 536  main(int argc, char *argv[])
536                                  }                                  }
537    
538                                  if (*p == '+' || *p == '-')                                  if (*p == '+' || *p == '-')
539                                    {
540                                            g_pos |= (*p == '-') ? 2 : 1;
541                                          g_xpos = strtol(p, &p, 10);                                          g_xpos = strtol(p, &p, 10);
542    
543                                    }
544                                  if (*p == '+' || *p == '-')                                  if (*p == '+' || *p == '-')
545                                    {
546                                            g_pos |= (*p == '-') ? 4 : 1;
547                                          g_ypos = strtol(p, NULL, 10);                                          g_ypos = strtol(p, NULL, 10);
548                                    }
549    
550                                  break;                                  break;
551    
# Line 523  main(int argc, char *argv[]) Line 609  main(int argc, char *argv[])
609                                  break;                                  break;
610    
611                          case 'X':                          case 'X':
612                                  g_embed_wnd = strtol(optarg, NULL, 10);                                  g_embed_wnd = strtol(optarg, NULL, 0);
613                                  break;                                  break;
614    
615                          case 'a':                          case 'a':
616                                  g_server_bpp = strtol(optarg, NULL, 10);                                  g_server_depth = strtol(optarg, NULL, 10);
617                                  if (g_server_bpp != 8 && g_server_bpp != 16 && g_server_bpp != 15                                  if (g_server_depth != 8 &&
618                                      && g_server_bpp != 24)                                      g_server_depth != 16 &&
619                                        g_server_depth != 15 && g_server_depth != 24)
620                                  {                                  {
621                                          error("invalid server bpp\n");                                          error("Invalid server colour depth.\n");
622                                          return 1;                                          return 1;
623                                  }                                  }
624                                  break;                                  break;
625    
626                          case 'z':                          case 'z':
627                                  DEBUG(("rdp compression enabled\n"));                                  DEBUG(("rdp compression enabled\n"));
628                                  flags |= RDP_COMPRESSION;                                  flags |= (RDP_LOGON_COMPRESSION | RDP_LOGON_COMPRESSION2);
629                                  break;                                  break;
630    
631                          case 'x':                          case 'x':
632                                  if (strncmp("modem", optarg, 1) == 0)                                  if (str_startswith(optarg, "m"))        /* modem */
633                                  {                                  {
634                                          g_rdp5_performanceflags =                                          g_rdp5_performanceflags =
635                                                  RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG |                                                  RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG |
636                                                  RDP5_NO_MENUANIMATIONS | RDP5_NO_THEMING;                                                  RDP5_NO_MENUANIMATIONS | RDP5_NO_THEMING;
637                                  }                                  }
638                                  else if (strncmp("broadband", optarg, 1) == 0)                                  else if (str_startswith(optarg, "b"))   /* broadband */
639                                  {                                  {
640                                          g_rdp5_performanceflags = RDP5_NO_WALLPAPER;                                          g_rdp5_performanceflags = RDP5_NO_WALLPAPER;
641                                  }                                  }
642                                  else if (strncmp("lan", optarg, 1) == 0)                                  else if (str_startswith(optarg, "l"))   /* lan */
643                                  {                                  {
644                                          g_rdp5_performanceflags = RDP5_DISABLE_NOTHING;                                          g_rdp5_performanceflags = RDP5_DISABLE_NOTHING;
645                                  }                                  }
# Line 568  main(int argc, char *argv[]) Line 655  main(int argc, char *argv[])
655    
656                          case 'r':                          case 'r':
657    
658                                  if (strncmp("sound", optarg, 5) == 0)                                  if (str_startswith(optarg, "sound"))
659                                  {                                  {
660                                          optarg += 5;                                          optarg += 5;
661    
662                                          if (*optarg == ':')                                          if (*optarg == ':')
663                                          {                                          {
664                                                  *optarg++;                                                  optarg++;
665                                                  while ((p = next_arg(optarg, ',')))                                                  while ((p = next_arg(optarg, ',')))
666                                                  {                                                  {
667                                                          if (strncmp("remote", optarg, 6) == 0)                                                          if (str_startswith(optarg, "remote"))
668                                                                  flags |= RDP_LOGON_LEAVE_AUDIO;                                                                  flags |= RDP_LOGON_LEAVE_AUDIO;
669    
670                                                          if (strncmp("local", optarg, 5) == 0)                                                          if (str_startswith(optarg, "local"))
671  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
672                                                            {
673                                                                    rdpsnd_optarg =
674                                                                            next_arg(optarg, ':');
675                                                                  g_rdpsnd = True;                                                                  g_rdpsnd = True;
676                                                            }
677    
678  #else  #else
679                                                                  warning("Not compiled with sound support\n");                                                                  warning("Not compiled with sound support\n");
680  #endif  #endif
681    
682                                                          if (strncmp("off", optarg, 3) == 0)                                                          if (str_startswith(optarg, "off"))
683  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
684                                                                  g_rdpsnd = False;                                                                  g_rdpsnd = False;
685  #else  #else
# Line 606  main(int argc, char *argv[]) Line 698  main(int argc, char *argv[])
698  #endif  #endif
699                                          }                                          }
700                                  }                                  }
701                                  else if (strncmp("disk", optarg, 4) == 0)                                  else if (str_startswith(optarg, "disk"))
702                                  {                                  {
703                                          /* -r disk:h:=/mnt/floppy */                                          /* -r disk:h:=/mnt/floppy */
704                                          disk_enum_devices(&g_num_devices, optarg + 4);                                          disk_enum_devices(&g_num_devices, optarg + 4);
705                                  }                                  }
706                                  else if (strncmp("comport", optarg, 7) == 0)                                  else if (str_startswith(optarg, "comport"))
707                                  {                                  {
708                                          serial_enum_devices(&g_num_devices, optarg + 7);                                          serial_enum_devices(&g_num_devices, optarg + 7);
709                                  }                                  }
710                                  else if (strncmp("lptport", optarg, 7) == 0)                                  else if (str_startswith(optarg, "lspci"))
711                                    {
712                                            lspci_enabled = True;
713                                    }
714                                    else if (str_startswith(optarg, "lptport"))
715                                  {                                  {
716                                          parallel_enum_devices(&g_num_devices, optarg + 7);                                          parallel_enum_devices(&g_num_devices, optarg + 7);
717                                  }                                  }
718                                  else if (strncmp("printer", optarg, 7) == 0)                                  else if (str_startswith(optarg, "printer"))
719                                  {                                  {
720                                          printer_enum_devices(&g_num_devices, optarg + 7);                                          printer_enum_devices(&g_num_devices, optarg + 7);
721                                  }                                  }
722                                  else if (strncmp("clientname", optarg, 7) == 0)                                  else if (str_startswith(optarg, "clientname"))
723                                  {                                  {
724                                          g_rdpdr_clientname = xmalloc(strlen(optarg + 11) + 1);                                          g_rdpdr_clientname = xmalloc(strlen(optarg + 11) + 1);
725                                          strcpy(g_rdpdr_clientname, optarg + 11);                                          strcpy(g_rdpdr_clientname, optarg + 11);
726                                  }                                  }
727                                    else if (str_startswith(optarg, "clipboard"))
728                                    {
729                                            optarg += 9;
730    
731                                            if (*optarg == ':')
732                                            {
733                                                    optarg++;
734    
735                                                    if (str_startswith(optarg, "off"))
736                                                            g_rdpclip = False;
737                                                    else
738                                                            cliprdr_set_mode(optarg);
739                                            }
740                                            else
741                                                    g_rdpclip = True;
742                                    }
743                                  else                                  else
744                                  {                                  {
745                                          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");
746                                  }                                  }
747                                  break;                                  break;
748    
# Line 663  main(int argc, char *argv[]) Line 775  main(int argc, char *argv[])
775          STRNCPY(server, argv[optind], sizeof(server));          STRNCPY(server, argv[optind], sizeof(server));
776          parse_server_and_port(server);          parse_server_and_port(server);
777    
778            if (g_seamless_rdp)
779            {
780                    if (g_win_button_size)
781                    {
782                            error("You cannot use -S and -A at the same time\n");
783                            return 1;
784                    }
785                    g_rdp5_performanceflags &= ~RDP5_NO_FULLWINDOWDRAG;
786                    if (geometry_option)
787                    {
788                            error("You cannot use -g and -A at the same time\n");
789                            return 1;
790                    }
791                    if (g_fullscreen)
792                    {
793                            error("You cannot use -f and -A at the same time\n");
794                            return 1;
795                    }
796                    if (g_hide_decorations)
797                    {
798                            error("You cannot use -D and -A at the same time\n");
799                            return 1;
800                    }
801                    if (g_embed_wnd)
802                    {
803                            error("You cannot use -X and -A at the same time\n");
804                            return 1;
805                    }
806                    if (!g_use_rdp5)
807                    {
808                            error("You cannot use -4 and -A at the same time\n");
809                            return 1;
810                    }
811                    g_width = -100;
812                    g_grab_keyboard = False;
813            }
814    
815          if (!username_option)          if (!username_option)
816          {          {
817                  pw = getpwuid(getuid());                  pw = getpwuid(getuid());
# Line 675  main(int argc, char *argv[]) Line 824  main(int argc, char *argv[])
824                  STRNCPY(g_username, pw->pw_name, sizeof(g_username));                  STRNCPY(g_username, pw->pw_name, sizeof(g_username));
825          }          }
826    
827    #ifdef HAVE_ICONV
828            if (g_codepage[0] == 0)
829            {
830                    if (setlocale(LC_CTYPE, ""))
831                    {
832                            STRNCPY(g_codepage, nl_langinfo(CODESET), sizeof(g_codepage));
833                    }
834                    else
835                    {
836                            STRNCPY(g_codepage, DEFAULT_CODEPAGE, sizeof(g_codepage));
837                    }
838            }
839    #endif
840    
841          if (g_hostname[0] == 0)          if (g_hostname[0] == 0)
842          {          {
843                  if (gethostname(fullhostname, sizeof(fullhostname)) == -1)                  if (gethostname(fullhostname, sizeof(fullhostname)) == -1)
# Line 690  main(int argc, char *argv[]) Line 853  main(int argc, char *argv[])
853                  STRNCPY(g_hostname, fullhostname, sizeof(g_hostname));                  STRNCPY(g_hostname, fullhostname, sizeof(g_hostname));
854          }          }
855    
856            if (g_keymapname[0] == 0)
857            {
858                    if (locale && xkeymap_from_locale(locale))
859                    {
860                            fprintf(stderr, "Autoselected keyboard map %s\n", g_keymapname);
861                    }
862                    else
863                    {
864                            STRNCPY(g_keymapname, "en-us", sizeof(g_keymapname));
865                    }
866            }
867            if (locale)
868                    xfree(locale);
869    
870    
871          if (prompt_password && read_password(password, sizeof(password)))          if (prompt_password && read_password(password, sizeof(password)))
872                  flags |= RDP_LOGON_AUTO;                  flags |= RDP_LOGON_AUTO;
873    
# Line 709  main(int argc, char *argv[]) Line 887  main(int argc, char *argv[])
887    
888  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
889          if (g_rdpsnd)          if (g_rdpsnd)
890                  rdpsnd_init();          {
891                    if (!rdpsnd_init(rdpsnd_optarg))
892                    {
893                            warning("Initializing sound-support failed!\n");
894                    }
895            }
896  #endif  #endif
897    
898            if (lspci_enabled)
899                    lspci_init();
900    
901          rdpdr_init();          rdpdr_init();
902    
903          if (!rdp_connect(server, flags, domain, password, shell, directory))          while (run_count < 2 && continue_connect)       /* add support for Session Directory; only reconnect once */
904                  return 1;          {
905                    if (run_count == 0)
906                    {
907                            if (!rdp_connect(server, flags, domain, password, shell, directory))
908                                    return 1;
909                    }
910                    else if (!rdp_reconnect
911                             (server, flags, domain, password, shell, directory, g_redirect_cookie))
912                            return 1;
913    
914          /* By setting encryption to False here, we have an encrypted login                  /* By setting encryption to False here, we have an encrypted login
915             packet but unencrypted transfer of other packets */                     packet but unencrypted transfer of other packets */
916          if (!packet_encryption)                  if (!packet_encryption)
917                  g_encryption = False;                          g_encryption = False;
918    
919    
920          DEBUG(("Connection successful.\n"));                  DEBUG(("Connection successful.\n"));
921          memset(password, 0, sizeof(password));                  memset(password, 0, sizeof(password));
922    
923          if (ui_create_window())                  if (run_count == 0)
924          {                          if (!ui_create_window())
925                  rdp_main_loop(&deactivated, &ext_disc_reason);                                  continue_connect = False;
926                  ui_destroy_window();  
927                    if (continue_connect)
928                            rdp_main_loop(&deactivated, &ext_disc_reason);
929    
930                    DEBUG(("Disconnecting...\n"));
931                    rdp_disconnect();
932    
933                    if ((g_redirect == True) && (run_count == 0))   /* Support for Session Directory */
934                    {
935                            /* reset state of major globals */
936                            rdesktop_reset_state();
937    
938                            STRNCPY(domain, g_redirect_domain, sizeof(domain));
939                            STRNCPY(g_username, g_redirect_username, sizeof(g_username));
940                            STRNCPY(password, g_redirect_password, sizeof(password));
941                            STRNCPY(server, g_redirect_server, sizeof(server));
942                            flags |= RDP_LOGON_AUTO;
943    
944                            g_redirect = False;
945                    }
946                    else
947                    {
948                            continue_connect = False;
949                            ui_destroy_window();
950                            break;
951                    }
952    
953                    run_count++;
954          }          }
955    
         DEBUG(("Disconnecting...\n"));  
         rdp_disconnect();  
956          cache_save_state();          cache_save_state();
957          ui_deinit();          ui_deinit();
958    
# Line 859  xmalloc(int size) Line 1079  xmalloc(int size)
1079          return mem;          return mem;
1080  }  }
1081    
1082    /* strdup */
1083    char *
1084    xstrdup(const char *s)
1085    {
1086            char *mem = strdup(s);
1087            if (mem == NULL)
1088            {
1089                    perror("strdup");
1090                    exit(1);
1091            }
1092            return mem;
1093    }
1094    
1095  /* realloc; exit if out of memory */  /* realloc; exit if out of memory */
1096  void *  void *
1097  xrealloc(void *oldmem, int size)  xrealloc(void *oldmem, int size)
# Line 994  next_arg(char *src, char needle) Line 1227  next_arg(char *src, char needle)
1227                          while (*(mvp + 1) != (char) 0x00)                          while (*(mvp + 1) != (char) 0x00)
1228                          {                          {
1229                                  *mvp = *(mvp + 1);                                  *mvp = *(mvp + 1);
1230                                  *mvp++;                                  mvp++;
1231                          }                          }
1232                          *mvp = (char) 0x00;                          *mvp = (char) 0x00;
1233                          p = nextval;                          p = nextval;
# Line 1032  toupper_str(char *p) Line 1265  toupper_str(char *p)
1265  }  }
1266    
1267    
1268    BOOL
1269    str_startswith(const char *s, const char *prefix)
1270    {
1271            return (strncmp(s, prefix, strlen(prefix)) == 0);
1272    }
1273    
1274    
1275    /* Split input into lines, and call linehandler for each
1276       line. Incomplete lines are saved in the rest variable, which should
1277       initially point to NULL. When linehandler returns False, stop and
1278       return False. Otherwise, return True.  */
1279    BOOL
1280    str_handle_lines(const char *input, char **rest, str_handle_lines_t linehandler, void *data)
1281    {
1282            char *buf, *p;
1283            char *oldrest;
1284            size_t inputlen;
1285            size_t buflen;
1286            size_t restlen = 0;
1287            BOOL ret = True;
1288    
1289            /* Copy data to buffer */
1290            inputlen = strlen(input);
1291            if (*rest)
1292                    restlen = strlen(*rest);
1293            buflen = restlen + inputlen + 1;
1294            buf = (char *) xmalloc(buflen);
1295            buf[0] = '\0';
1296            if (*rest)
1297                    STRNCPY(buf, *rest, buflen);
1298            strncat(buf, input, inputlen);
1299            p = buf;
1300    
1301            while (1)
1302            {
1303                    char *newline = strchr(p, '\n');
1304                    if (newline)
1305                    {
1306                            *newline = '\0';
1307                            if (!linehandler(p, data))
1308                            {
1309                                    p = newline + 1;
1310                                    ret = False;
1311                                    break;
1312                            }
1313                            p = newline + 1;
1314                    }
1315                    else
1316                    {
1317                            break;
1318    
1319                    }
1320            }
1321    
1322            /* Save in rest */
1323            oldrest = *rest;
1324            restlen = buf + buflen - p;
1325            *rest = (char *) xmalloc(restlen);
1326            STRNCPY((*rest), p, restlen);
1327            xfree(oldrest);
1328    
1329            xfree(buf);
1330            return ret;
1331    }
1332    
1333    /* Execute the program specified by argv. For each line in
1334       stdout/stderr output, call linehandler. Returns false on failure. */
1335    BOOL
1336    subprocess(char *const argv[], str_handle_lines_t linehandler, void *data)
1337    {
1338            pid_t child;
1339            int fd[2];
1340            int n = 1;
1341            char output[256];
1342            char *rest = NULL;
1343    
1344            if (pipe(fd) < 0)
1345            {
1346                    perror("pipe");
1347                    return False;
1348            }
1349    
1350            if ((child = fork()) < 0)
1351            {
1352                    perror("fork");
1353                    return False;
1354            }
1355    
1356            /* Child */
1357            if (child == 0)
1358            {
1359                    /* Close read end */
1360                    close(fd[0]);
1361    
1362                    /* Redirect stdout and stderr to pipe */
1363                    dup2(fd[1], 1);
1364                    dup2(fd[1], 2);
1365    
1366                    /* Execute */
1367                    execvp(argv[0], argv);
1368                    perror("Error executing child");
1369                    _exit(128);
1370            }
1371    
1372            /* Parent. Close write end. */
1373            close(fd[1]);
1374            while (n > 0)
1375            {
1376                    n = read(fd[0], output, 255);
1377                    output[n] = '\0';
1378                    str_handle_lines(output, &rest, linehandler, data);
1379            }
1380            xfree(rest);
1381    
1382            return True;
1383    }
1384    
1385    
1386  /* not all clibs got ltoa */  /* not all clibs got ltoa */
1387  #define LTOA_BUFSIZE (sizeof(long) * 8 + 1)  #define LTOA_BUFSIZE (sizeof(long) * 8 + 1)
1388    

Legend:
Removed from v.801  
changed lines
  Added in v.1272

  ViewVC Help
Powered by ViewVC 1.1.26