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

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

revision 738 by astrand, Mon Jul 12 21:07:39 2004 UTC revision 980 by stargo, Mon Aug 15 12:06:59 2005 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
47    
 #ifdef WITH_OPENSSL  
48  #include <openssl/md5.h>  #include <openssl/md5.h>
 #else  
 #include "crypto/md5.h"  
 #endif  
49    
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 */  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 53  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_bpp = 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 */
# Line 63  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;
# Line 75  BOOL g_ownbackstore = True;    /* We can't Line 91  BOOL g_ownbackstore = True;    /* We can't
91  uint32 g_embed_wnd;  uint32 g_embed_wnd;
92  uint32 g_rdp5_performanceflags =  uint32 g_rdp5_performanceflags =
93          RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS;          RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS;
94    /* Session Directory redirection */
95    BOOL g_redirect = False;
96    char g_redirect_server[64];
97    char g_redirect_domain[16];
98    char g_redirect_password[64];
99    char g_redirect_username[64];
100    char g_redirect_cookie[128];
101    uint32 g_redirect_flags = 0;
102    
103  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
104  BOOL g_rdpsnd = False;  BOOL g_rdpsnd = False;
105  #endif  #endif
106    
107    #ifdef HAVE_ICONV
108    char g_codepage[16] = "";
109    #endif
110    
111  extern RDPDR_DEVICE g_rdpdr_device[];  extern RDPDR_DEVICE g_rdpdr_device[];
112  extern uint32 g_num_devices;  extern uint32 g_num_devices;
113  extern char *g_rdpdr_clientname;  extern char *g_rdpdr_clientname;
# Line 96  static void Line 124  static void
124  usage(char *program)  usage(char *program)
125  {  {
126          fprintf(stderr, "rdesktop: A Remote Desktop Protocol client.\n");          fprintf(stderr, "rdesktop: A Remote Desktop Protocol client.\n");
127          fprintf(stderr, "Version " VERSION ". Copyright (C) 1999-2003 Matt Chapman.\n");          fprintf(stderr, "Version " VERSION ". Copyright (C) 1999-2005 Matt Chapman.\n");
128          fprintf(stderr, "See http://www.rdesktop.org/ for more information.\n\n");          fprintf(stderr, "See http://www.rdesktop.org/ for more information.\n\n");
129    
130          fprintf(stderr, "Usage: %s [options] server[:port]\n", program);          fprintf(stderr, "Usage: %s [options] server[:port]\n", program);
# Line 114  usage(char *program) Line 142  usage(char *program)
142          fprintf(stderr, "   -g: desktop geometry (WxH)\n");          fprintf(stderr, "   -g: desktop geometry (WxH)\n");
143          fprintf(stderr, "   -f: full-screen mode\n");          fprintf(stderr, "   -f: full-screen mode\n");
144          fprintf(stderr, "   -b: force bitmap updates\n");          fprintf(stderr, "   -b: force bitmap updates\n");
145    #ifdef HAVE_ICONV
146            fprintf(stderr, "   -L: local codepage\n");
147    #endif
148          fprintf(stderr, "   -B: use BackingStore of X-server (if available)\n");          fprintf(stderr, "   -B: use BackingStore of X-server (if available)\n");
149          fprintf(stderr, "   -e: disable encryption (French TS)\n");          fprintf(stderr, "   -e: disable encryption (French TS)\n");
150          fprintf(stderr, "   -E: disable encryption from client to server\n");          fprintf(stderr, "   -E: disable encryption from client to server\n");
# Line 126  usage(char *program) Line 157  usage(char *program)
157          fprintf(stderr, "   -N: enable numlock syncronization\n");          fprintf(stderr, "   -N: enable numlock syncronization\n");
158          fprintf(stderr, "   -X: embed into another window with a given id.\n");          fprintf(stderr, "   -X: embed into another window with a given id.\n");
159          fprintf(stderr, "   -a: connection colour depth\n");          fprintf(stderr, "   -a: connection colour depth\n");
160            fprintf(stderr, "   -z: enable rdp compression\n");
161          fprintf(stderr, "   -x: RDP5 experience (m[odem 28.8], b[roadband], l[an] or hex nr.)\n");          fprintf(stderr, "   -x: RDP5 experience (m[odem 28.8], b[roadband], l[an] or hex nr.)\n");
162          fprintf(stderr, "   -P: use persistent bitmap caching\n");          fprintf(stderr, "   -P: use persistent bitmap caching\n");
163          fprintf(stderr, "   -r: enable specified device redirection (this flag can be repeated)\n");          fprintf(stderr, "   -r: enable specified device redirection (this flag can be repeated)\n");
# Line 133  usage(char *program) Line 165  usage(char *program)
165                  "         '-r comport:COM1=/dev/ttyS0': enable serial redirection of /dev/ttyS0 to COM1\n");                  "         '-r comport:COM1=/dev/ttyS0': enable serial redirection of /dev/ttyS0 to COM1\n");
166          fprintf(stderr, "             or      COM1=/dev/ttyS0,COM2=/dev/ttyS1\n");          fprintf(stderr, "             or      COM1=/dev/ttyS0,COM2=/dev/ttyS1\n");
167          fprintf(stderr,          fprintf(stderr,
168                  "         '-r disk:A=/mnt/floppy': enable redirection of /mnt/floppy to A:\n");                  "         '-r disk:floppy=/mnt/floppy': enable redirection of /mnt/floppy to 'floppy' share\n");
169          fprintf(stderr, "             or   A=/mnt/floppy,D=/mnt/cdrom'\n");          fprintf(stderr, "             or   'floppy=/mnt/floppy,cdrom=/mnt/cdrom'\n");
170          fprintf(stderr, "         '-r clientname=<client name>': Set the client name displayed\n");          fprintf(stderr, "         '-r clientname=<client name>': Set the client name displayed\n");
171          fprintf(stderr, "             for redirected disks\n");          fprintf(stderr, "             for redirected disks\n");
172          fprintf(stderr,          fprintf(stderr,
# Line 150  usage(char *program) Line 182  usage(char *program)
182          fprintf(stderr, "   -5: use RDP version 5 (default)\n");          fprintf(stderr, "   -5: use RDP version 5 (default)\n");
183  }  }
184    
185  void  static void
186  print_disconnect_reason(uint16 reason)  print_disconnect_reason(uint16 reason)
187  {  {
188          char *text;          char *text;
# Line 250  print_disconnect_reason(uint16 reason) Line 282  print_disconnect_reason(uint16 reason)
282          fprintf(stderr, "disconnect: %s.\n", text);          fprintf(stderr, "disconnect: %s.\n", text);
283  }  }
284    
285    static void
286    rdesktop_reset_state(void)
287    {
288            rdp_reset_state();
289    }
290    
291  static BOOL  static BOOL
292  read_password(char *password, int size)  read_password(char *password, int size)
293  {  {
# Line 349  main(int argc, char *argv[]) Line 387  main(int argc, char *argv[])
387          uint32 flags, ext_disc_reason = 0;          uint32 flags, ext_disc_reason = 0;
388          char *p;          char *p;
389          int c;          int c;
390            char *locale = NULL;
391          int username_option = 0;          int username_option = 0;
392            int run_count = 0;      /* Session Directory support */
393            BOOL continue_connect = True;   /* Session Directory support */
394    
395    #ifdef HAVE_LOCALE_H
396            /* Set locale according to environment */
397            locale = setlocale(LC_ALL, "");
398            if (locale)
399            {
400                    locale = xstrdup(locale);
401            }
402    
403    #endif
404          flags = RDP_LOGON_NORMAL;          flags = RDP_LOGON_NORMAL;
405          prompt_password = False;          prompt_password = False;
406          domain[0] = password[0] = shell[0] = directory[0] = 0;          domain[0] = password[0] = shell[0] = directory[0] = 0;
         strcpy(keymapname, "en-us");  
407          g_embed_wnd = 0;          g_embed_wnd = 0;
408    
409          g_num_devices = 0;          g_num_devices = 0;
# Line 367  main(int argc, char *argv[]) Line 415  main(int argc, char *argv[])
415  #endif  #endif
416    
417          while ((c = getopt(argc, argv,          while ((c = getopt(argc, argv,
418                             VNCOPT "u:d:s:c:p:n:k:g:fbBeEmCDKS:T:NX:a:x:Pr:045h?")) != -1)                             VNCOPT "u:L:d:s:c:p:n:k:g:fbBeEmzCDKS:T:NX:a:x:Pr:045h?")) != -1)
419          {          {
420                  switch (c)                  switch (c)
421                  {                  {
# Line 390  main(int argc, char *argv[]) Line 438  main(int argc, char *argv[])
438                                  username_option = 1;                                  username_option = 1;
439                                  break;                                  break;
440    
441                            case 'L':
442    #ifdef HAVE_ICONV
443                                    STRNCPY(g_codepage, optarg, sizeof(g_codepage));
444    #else
445                                    error("iconv support not available\n");
446    #endif
447                                    break;
448    
449                          case 'd':                          case 'd':
450                                  STRNCPY(domain, optarg, sizeof(domain));                                  STRNCPY(domain, optarg, sizeof(domain));
451                                  break;                                  break;
# Line 423  main(int argc, char *argv[]) Line 479  main(int argc, char *argv[])
479                                  break;                                  break;
480    
481                          case 'k':                          case 'k':
482                                  STRNCPY(keymapname, optarg, sizeof(keymapname));                                  STRNCPY(g_keymapname, optarg, sizeof(g_keymapname));
483                                  break;                                  break;
484    
485                          case 'g':                          case 'g':
# Line 442  main(int argc, char *argv[]) Line 498  main(int argc, char *argv[])
498                                  }                                  }
499    
500                                  if (*p == 'x')                                  if (*p == 'x')
501                                          g_height = strtol(p + 1, NULL, 10);                                          g_height = strtol(p + 1, &p, 10);
502    
503                                  if (g_height <= 0)                                  if (g_height <= 0)
504                                  {                                  {
# Line 451  main(int argc, char *argv[]) Line 507  main(int argc, char *argv[])
507                                  }                                  }
508    
509                                  if (*p == '%')                                  if (*p == '%')
510                                    {
511                                          g_width = -g_width;                                          g_width = -g_width;
512                                            p++;
513                                    }
514    
515                                    if (*p == '+' || *p == '-')
516                                    {
517                                            g_pos |= (*p == '-') ? 2 : 1;
518                                            g_xpos = strtol(p, &p, 10);
519    
520                                    }
521                                    if (*p == '+' || *p == '-')
522                                    {
523                                            g_pos |= (*p == '-') ? 4 : 1;
524                                            g_ypos = strtol(p, NULL, 10);
525                                    }
526    
527                                  break;                                  break;
528    
# Line 515  main(int argc, char *argv[]) Line 586  main(int argc, char *argv[])
586                                  break;                                  break;
587    
588                          case 'X':                          case 'X':
589                                  g_embed_wnd = strtol(optarg, NULL, 10);                                  g_embed_wnd = strtol(optarg, NULL, 0);
590                                  break;                                  break;
591    
592                          case 'a':                          case 'a':
# Line 528  main(int argc, char *argv[]) Line 599  main(int argc, char *argv[])
599                                  }                                  }
600                                  break;                                  break;
601    
602                          case 'x':                          case 'z':
603                                    DEBUG(("rdp compression enabled\n"));
604                                    flags |= (RDP_LOGON_COMPRESSION | RDP_LOGON_COMPRESSION2);
605                                    break;
606    
607                            case 'x':
608                                  if (strncmp("modem", optarg, 1) == 0)                                  if (strncmp("modem", optarg, 1) == 0)
609                                  {                                  {
610                                          g_rdp5_performanceflags =                                          g_rdp5_performanceflags =
# Line 572  main(int argc, char *argv[]) Line 647  main(int argc, char *argv[])
647  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
648                                                                  g_rdpsnd = True;                                                                  g_rdpsnd = True;
649  #else  #else
650                                                                  warning("Not compiled with sound support");                                                                  warning("Not compiled with sound support\n");
651  #endif  #endif
652    
653                                                          if (strncmp("off", optarg, 3) == 0)                                                          if (strncmp("off", optarg, 3) == 0)
654  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
655                                                                  g_rdpsnd = False;                                                                  g_rdpsnd = False;
656  #else  #else
657                                                                  warning("Not compiled with sound support");                                                                  warning("Not compiled with sound support\n");
658  #endif  #endif
659    
660                                                          optarg = p;                                                          optarg = p;
# Line 590  main(int argc, char *argv[]) Line 665  main(int argc, char *argv[])
665  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
666                                                  g_rdpsnd = True;                                                  g_rdpsnd = True;
667  #else  #else
668                                                  warning("Not compiled with sound support");                                                  warning("Not compiled with sound support\n");
669  #endif  #endif
670                                          }                                          }
671                                  }                                  }
# Line 663  main(int argc, char *argv[]) Line 738  main(int argc, char *argv[])
738                  STRNCPY(g_username, pw->pw_name, sizeof(g_username));                  STRNCPY(g_username, pw->pw_name, sizeof(g_username));
739          }          }
740    
741    #ifdef HAVE_ICONV
742            if (g_codepage[0] == 0)
743            {
744                    if (setlocale(LC_CTYPE, ""))
745                    {
746                            STRNCPY(g_codepage, nl_langinfo(CODESET), sizeof(g_codepage));
747                    }
748                    else
749                    {
750                            STRNCPY(g_codepage, DEFAULT_CODEPAGE, sizeof(g_codepage));
751                    }
752            }
753    #endif
754    
755          if (g_hostname[0] == 0)          if (g_hostname[0] == 0)
756          {          {
757                  if (gethostname(fullhostname, sizeof(fullhostname)) == -1)                  if (gethostname(fullhostname, sizeof(fullhostname)) == -1)
# Line 678  main(int argc, char *argv[]) Line 767  main(int argc, char *argv[])
767                  STRNCPY(g_hostname, fullhostname, sizeof(g_hostname));                  STRNCPY(g_hostname, fullhostname, sizeof(g_hostname));
768          }          }
769    
770            if (g_keymapname[0] == 0)
771            {
772                    if (locale && xkeymap_from_locale(locale))
773                    {
774                            fprintf(stderr, "Autoselected keyboard map %s\n", g_keymapname);
775                    }
776                    else
777                    {
778                            STRNCPY(g_keymapname, "en-us", sizeof(g_keymapname));
779                    }
780            }
781            if (locale)
782                    xfree(locale);
783    
784    
785          if (prompt_password && read_password(password, sizeof(password)))          if (prompt_password && read_password(password, sizeof(password)))
786                  flags |= RDP_LOGON_AUTO;                  flags |= RDP_LOGON_AUTO;
787    
# Line 701  main(int argc, char *argv[]) Line 805  main(int argc, char *argv[])
805  #endif  #endif
806          rdpdr_init();          rdpdr_init();
807    
808          if (!rdp_connect(server, flags, domain, password, shell, directory))          while (run_count < 2 && continue_connect)       /* add support for Session Directory; only reconnect once */
809                  return 1;          {
810                    if (run_count == 0)
811                    {
812                            if (!rdp_connect(server, flags, domain, password, shell, directory))
813                                    return 1;
814                    }
815                    else if (!rdp_reconnect
816                             (server, flags, domain, password, shell, directory, g_redirect_cookie))
817                            return 1;
818    
819          /* By setting encryption to False here, we have an encrypted login                  /* By setting encryption to False here, we have an encrypted login
820             packet but unencrypted transfer of other packets */                     packet but unencrypted transfer of other packets */
821          if (!packet_encryption)                  if (!packet_encryption)
822                  g_encryption = False;                          g_encryption = False;
823    
824    
825          DEBUG(("Connection successful.\n"));                  DEBUG(("Connection successful.\n"));
826          memset(password, 0, sizeof(password));                  memset(password, 0, sizeof(password));
827    
828          if (ui_create_window())                  if (run_count == 0)
829          {                          if (!ui_create_window())
830                  rdp_main_loop(&deactivated, &ext_disc_reason);                                  continue_connect = False;
831                  ui_destroy_window();  
832                    if (continue_connect)
833                            rdp_main_loop(&deactivated, &ext_disc_reason);
834    
835                    DEBUG(("Disconnecting...\n"));
836                    rdp_disconnect();
837    
838                    if ((g_redirect == True) && (run_count == 0))   /* Support for Session Directory */
839                    {
840                            /* reset state of major globals */
841                            rdesktop_reset_state();
842    
843                            STRNCPY(domain, g_redirect_domain, sizeof(domain));
844                            STRNCPY(g_username, g_redirect_username, sizeof(g_username));
845                            STRNCPY(password, g_redirect_password, sizeof(password));
846                            STRNCPY(server, g_redirect_server, sizeof(server));
847                            flags |= RDP_LOGON_AUTO;
848    
849                            g_redirect = False;
850                    }
851                    else
852                    {
853                            continue_connect = False;
854                            ui_destroy_window();
855                            break;
856                    }
857    
858                    run_count++;
859          }          }
860    
         DEBUG(("Disconnecting...\n"));  
         rdp_disconnect();  
861          cache_save_state();          cache_save_state();
862          ui_deinit();          ui_deinit();
863    
# Line 847  xmalloc(int size) Line 984  xmalloc(int size)
984          return mem;          return mem;
985  }  }
986    
987    /* strdup */
988    char *
989    xstrdup(const char *s)
990    {
991            char *mem = strdup(s);
992            if (mem == NULL)
993            {
994                    perror("strdup");
995                    exit(1);
996            }
997            return mem;
998    }
999    
1000  /* realloc; exit if out of memory */  /* realloc; exit if out of memory */
1001  void *  void *
1002  xrealloc(void *oldmem, int size)  xrealloc(void *oldmem, int size)
1003  {  {
1004          void *mem = realloc(oldmem, size);          void *mem;
1005    
1006            if (size < 1)
1007                    size = 1;
1008            mem = realloc(oldmem, size);
1009          if (mem == NULL)          if (mem == NULL)
1010          {          {
1011                  error("xrealloc %d\n", size);                  error("xrealloc %d\n", size);

Legend:
Removed from v.738  
changed lines
  Added in v.980

  ViewVC Help
Powered by ViewVC 1.1.26