/[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 977 by astrand, Mon Aug 8 19:15:57 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 27  Line 27 
27  #include <sys/time.h>           /* gettimeofday */  #include <sys/time.h>           /* gettimeofday */
28  #include <sys/times.h>          /* times */  #include <sys/times.h>          /* times */
29  #include <ctype.h>              /* toupper */  #include <ctype.h>              /* toupper */
30    #include <limits.h>             /* PATH_MAX */
31  #include <errno.h>  #include <errno.h>
32  #include "rdesktop.h"  #include "rdesktop.h"
33    
34    #ifdef HAVE_LOCALE_H
35    #include <locale.h>
36    #endif
37    #ifdef HAVE_ICONV
38    #ifdef HAVE_LANGINFO_H
39    #include <langinfo.h>
40    #endif
41    #endif
42    
43  #ifdef EGD_SOCKET  #ifdef EGD_SOCKET
44    #include <sys/types.h>
45  #include <sys/socket.h>         /* socket connect */  #include <sys/socket.h>         /* socket connect */
46  #include <sys/un.h>             /* sockaddr_un */  #include <sys/un.h>             /* sockaddr_un */
47  #endif  #endif
48    
 #ifdef WITH_OPENSSL  
49  #include <openssl/md5.h>  #include <openssl/md5.h>
 #else  
 #include "crypto/md5.h"  
 #endif  
50    
51  char g_title[64] = "";  char g_title[64] = "";
52  char g_username[64];  char g_username[64];
53  char g_hostname[16];  char g_hostname[16];
54  char keymapname[16];  char g_keymapname[PATH_MAX] = "";
55  int g_keylayout = 0x409;        /* Defaults to US keyboard layout */  int g_keylayout = 0x409;        /* Defaults to US keyboard layout */
56    int g_keyboard_type = 0x4;      /* Defaults to US keyboard layout */
57    int g_keyboard_subtype = 0x0;   /* Defaults to US keyboard layout */
58    int g_keyboard_functionkeys = 0xc;      /* Defaults to US keyboard layout */
59    
60  int g_width = 800;              /* width is special: If 0, the  int g_width = 800;              /* width is special: If 0, the
61                                     geometry will be fetched from                                     geometry will be fetched from
# Line 53  int g_width = 800;             /* width is special: Line 63  int g_width = 800;             /* width is special:
63                                     absolute value specifies the                                     absolute value specifies the
64                                     percent of the whole screen. */                                     percent of the whole screen. */
65  int g_height = 600;  int g_height = 600;
66    int g_xpos = 0;
67    int g_ypos = 0;
68    int g_pos = 0;                  /* 0 position unspecified,
69                                       1 specified,
70                                       2 xpos neg,
71                                       4 ypos neg  */
72  extern int g_tcp_port_rdp;  extern int g_tcp_port_rdp;
73  int g_server_bpp = 8;  int g_server_bpp = 8;
74  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 79  BOOL g_bitmap_cache_persist_enable = Fal
79  BOOL g_bitmap_cache_precache = True;  BOOL g_bitmap_cache_precache = True;
80  BOOL g_encryption = True;  BOOL g_encryption = True;
81  BOOL packet_encryption = True;  BOOL packet_encryption = True;
82  BOOL g_desktop_save = True;  BOOL g_desktop_save = True;     /* desktop save order */
83    BOOL g_polygon_ellipse_orders = True;   /* polygon / ellipse orders */
84  BOOL g_fullscreen = False;  BOOL g_fullscreen = False;
85  BOOL g_grab_keyboard = True;  BOOL g_grab_keyboard = True;
86  BOOL g_hide_decorations = False;  BOOL g_hide_decorations = False;
# Line 75  BOOL g_ownbackstore = True;    /* We can't Line 92  BOOL g_ownbackstore = True;    /* We can't
92  uint32 g_embed_wnd;  uint32 g_embed_wnd;
93  uint32 g_rdp5_performanceflags =  uint32 g_rdp5_performanceflags =
94          RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS;          RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS;
95    /* Session Directory redirection */
96    BOOL g_redirect = False;
97    char g_redirect_server[64];
98    char g_redirect_domain[16];
99    char g_redirect_password[64];
100    char g_redirect_username[64];
101    char g_redirect_cookie[128];
102    uint32 g_redirect_flags = 0;
103    
104  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
105  BOOL g_rdpsnd = False;  BOOL g_rdpsnd = False;
106  #endif  #endif
107    
108    #ifdef HAVE_ICONV
109    char g_codepage[16] = "";
110    #endif
111    
112  extern RDPDR_DEVICE g_rdpdr_device[];  extern RDPDR_DEVICE g_rdpdr_device[];
113  extern uint32 g_num_devices;  extern uint32 g_num_devices;
114  extern char *g_rdpdr_clientname;  extern char *g_rdpdr_clientname;
# Line 96  static void Line 125  static void
125  usage(char *program)  usage(char *program)
126  {  {
127          fprintf(stderr, "rdesktop: A Remote Desktop Protocol client.\n");          fprintf(stderr, "rdesktop: A Remote Desktop Protocol client.\n");
128          fprintf(stderr, "Version " VERSION ". Copyright (C) 1999-2003 Matt Chapman.\n");          fprintf(stderr, "Version " VERSION ". Copyright (C) 1999-2005 Matt Chapman.\n");
129          fprintf(stderr, "See http://www.rdesktop.org/ for more information.\n\n");          fprintf(stderr, "See http://www.rdesktop.org/ for more information.\n\n");
130    
131          fprintf(stderr, "Usage: %s [options] server[:port]\n", program);          fprintf(stderr, "Usage: %s [options] server[:port]\n", program);
# Line 114  usage(char *program) Line 143  usage(char *program)
143          fprintf(stderr, "   -g: desktop geometry (WxH)\n");          fprintf(stderr, "   -g: desktop geometry (WxH)\n");
144          fprintf(stderr, "   -f: full-screen mode\n");          fprintf(stderr, "   -f: full-screen mode\n");
145          fprintf(stderr, "   -b: force bitmap updates\n");          fprintf(stderr, "   -b: force bitmap updates\n");
146    #ifdef HAVE_ICONV
147            fprintf(stderr, "   -L: local codepage\n");
148    #endif
149          fprintf(stderr, "   -B: use BackingStore of X-server (if available)\n");          fprintf(stderr, "   -B: use BackingStore of X-server (if available)\n");
150          fprintf(stderr, "   -e: disable encryption (French TS)\n");          fprintf(stderr, "   -e: disable encryption (French TS)\n");
151          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 158  usage(char *program)
158          fprintf(stderr, "   -N: enable numlock syncronization\n");          fprintf(stderr, "   -N: enable numlock syncronization\n");
159          fprintf(stderr, "   -X: embed into another window with a given id.\n");          fprintf(stderr, "   -X: embed into another window with a given id.\n");
160          fprintf(stderr, "   -a: connection colour depth\n");          fprintf(stderr, "   -a: connection colour depth\n");
161            fprintf(stderr, "   -z: enable rdp compression\n");
162          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");
163          fprintf(stderr, "   -P: use persistent bitmap caching\n");          fprintf(stderr, "   -P: use persistent bitmap caching\n");
164          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 166  usage(char *program)
166                  "         '-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");
167          fprintf(stderr, "             or      COM1=/dev/ttyS0,COM2=/dev/ttyS1\n");          fprintf(stderr, "             or      COM1=/dev/ttyS0,COM2=/dev/ttyS1\n");
168          fprintf(stderr,          fprintf(stderr,
169                  "         '-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");
170          fprintf(stderr, "             or   A=/mnt/floppy,D=/mnt/cdrom'\n");          fprintf(stderr, "             or   'floppy=/mnt/floppy,cdrom=/mnt/cdrom'\n");
171          fprintf(stderr, "         '-r clientname=<client name>': Set the client name displayed\n");          fprintf(stderr, "         '-r clientname=<client name>': Set the client name displayed\n");
172          fprintf(stderr, "             for redirected disks\n");          fprintf(stderr, "             for redirected disks\n");
173          fprintf(stderr,          fprintf(stderr,
# Line 150  usage(char *program) Line 183  usage(char *program)
183          fprintf(stderr, "   -5: use RDP version 5 (default)\n");          fprintf(stderr, "   -5: use RDP version 5 (default)\n");
184  }  }
185    
186  void  static void
187  print_disconnect_reason(uint16 reason)  print_disconnect_reason(uint16 reason)
188  {  {
189          char *text;          char *text;
# Line 250  print_disconnect_reason(uint16 reason) Line 283  print_disconnect_reason(uint16 reason)
283          fprintf(stderr, "disconnect: %s.\n", text);          fprintf(stderr, "disconnect: %s.\n", text);
284  }  }
285    
286    static void
287    rdesktop_reset_state(void)
288    {
289            rdp_reset_state();
290    }
291    
292  static BOOL  static BOOL
293  read_password(char *password, int size)  read_password(char *password, int size)
294  {  {
# Line 349  main(int argc, char *argv[]) Line 388  main(int argc, char *argv[])
388          uint32 flags, ext_disc_reason = 0;          uint32 flags, ext_disc_reason = 0;
389          char *p;          char *p;
390          int c;          int c;
391            char *locale = NULL;
392          int username_option = 0;          int username_option = 0;
393            int run_count = 0;      /* Session Directory support */
394            BOOL continue_connect = True;   /* Session Directory support */
395    
396    #ifdef HAVE_LOCALE_H
397            /* Set locale according to environment */
398            locale = setlocale(LC_ALL, "");
399            if (locale)
400            {
401                    locale = xstrdup(locale);
402            }
403    
404    #endif
405          flags = RDP_LOGON_NORMAL;          flags = RDP_LOGON_NORMAL;
406          prompt_password = False;          prompt_password = False;
407          domain[0] = password[0] = shell[0] = directory[0] = 0;          domain[0] = password[0] = shell[0] = directory[0] = 0;
         strcpy(keymapname, "en-us");  
408          g_embed_wnd = 0;          g_embed_wnd = 0;
409    
410          g_num_devices = 0;          g_num_devices = 0;
# Line 367  main(int argc, char *argv[]) Line 416  main(int argc, char *argv[])
416  #endif  #endif
417    
418          while ((c = getopt(argc, argv,          while ((c = getopt(argc, argv,
419                             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)
420          {          {
421                  switch (c)                  switch (c)
422                  {                  {
# Line 390  main(int argc, char *argv[]) Line 439  main(int argc, char *argv[])
439                                  username_option = 1;                                  username_option = 1;
440                                  break;                                  break;
441    
442                            case 'L':
443    #ifdef HAVE_ICONV
444                                    STRNCPY(g_codepage, optarg, sizeof(g_codepage));
445    #else
446                                    error("iconv support not available\n");
447    #endif
448                                    break;
449    
450                          case 'd':                          case 'd':
451                                  STRNCPY(domain, optarg, sizeof(domain));                                  STRNCPY(domain, optarg, sizeof(domain));
452                                  break;                                  break;
# Line 423  main(int argc, char *argv[]) Line 480  main(int argc, char *argv[])
480                                  break;                                  break;
481    
482                          case 'k':                          case 'k':
483                                  STRNCPY(keymapname, optarg, sizeof(keymapname));                                  STRNCPY(g_keymapname, optarg, sizeof(g_keymapname));
484                                  break;                                  break;
485    
486                          case 'g':                          case 'g':
# Line 442  main(int argc, char *argv[]) Line 499  main(int argc, char *argv[])
499                                  }                                  }
500    
501                                  if (*p == 'x')                                  if (*p == 'x')
502                                          g_height = strtol(p + 1, NULL, 10);                                          g_height = strtol(p + 1, &p, 10);
503    
504                                  if (g_height <= 0)                                  if (g_height <= 0)
505                                  {                                  {
# Line 451  main(int argc, char *argv[]) Line 508  main(int argc, char *argv[])
508                                  }                                  }
509    
510                                  if (*p == '%')                                  if (*p == '%')
511                                    {
512                                          g_width = -g_width;                                          g_width = -g_width;
513                                            p++;
514                                    }
515    
516                                    if (*p == '+' || *p == '-')
517                                    {
518                                            g_pos |= (*p == '-') ? 2 : 1;
519                                            g_xpos = strtol(p, &p, 10);
520    
521                                    }
522                                    if (*p == '+' || *p == '-')
523                                    {
524                                            g_pos |= (*p == '-') ? 4 : 1;
525                                            g_ypos = strtol(p, NULL, 10);
526                                    }
527    
528                                  break;                                  break;
529    
# Line 515  main(int argc, char *argv[]) Line 587  main(int argc, char *argv[])
587                                  break;                                  break;
588    
589                          case 'X':                          case 'X':
590                                  g_embed_wnd = strtol(optarg, NULL, 10);                                  g_embed_wnd = strtol(optarg, NULL, 0);
591                                  break;                                  break;
592    
593                          case 'a':                          case 'a':
# Line 528  main(int argc, char *argv[]) Line 600  main(int argc, char *argv[])
600                                  }                                  }
601                                  break;                                  break;
602    
603                          case 'x':                          case 'z':
604                                    DEBUG(("rdp compression enabled\n"));
605                                    flags |= (RDP_LOGON_COMPRESSION | RDP_LOGON_COMPRESSION2);
606                                    break;
607    
608                            case 'x':
609                                  if (strncmp("modem", optarg, 1) == 0)                                  if (strncmp("modem", optarg, 1) == 0)
610                                  {                                  {
611                                          g_rdp5_performanceflags =                                          g_rdp5_performanceflags =
# Line 572  main(int argc, char *argv[]) Line 648  main(int argc, char *argv[])
648  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
649                                                                  g_rdpsnd = True;                                                                  g_rdpsnd = True;
650  #else  #else
651                                                                  warning("Not compiled with sound support");                                                                  warning("Not compiled with sound support\n");
652  #endif  #endif
653    
654                                                          if (strncmp("off", optarg, 3) == 0)                                                          if (strncmp("off", optarg, 3) == 0)
655  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
656                                                                  g_rdpsnd = False;                                                                  g_rdpsnd = False;
657  #else  #else
658                                                                  warning("Not compiled with sound support");                                                                  warning("Not compiled with sound support\n");
659  #endif  #endif
660    
661                                                          optarg = p;                                                          optarg = p;
# Line 590  main(int argc, char *argv[]) Line 666  main(int argc, char *argv[])
666  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
667                                                  g_rdpsnd = True;                                                  g_rdpsnd = True;
668  #else  #else
669                                                  warning("Not compiled with sound support");                                                  warning("Not compiled with sound support\n");
670  #endif  #endif
671                                          }                                          }
672                                  }                                  }
# Line 663  main(int argc, char *argv[]) Line 739  main(int argc, char *argv[])
739                  STRNCPY(g_username, pw->pw_name, sizeof(g_username));                  STRNCPY(g_username, pw->pw_name, sizeof(g_username));
740          }          }
741    
742    #ifdef HAVE_ICONV
743            if (g_codepage[0] == 0)
744            {
745                    if (setlocale(LC_CTYPE, ""))
746                    {
747                            STRNCPY(g_codepage, nl_langinfo(CODESET), sizeof(g_codepage));
748                    }
749                    else
750                    {
751                            STRNCPY(g_codepage, DEFAULT_CODEPAGE, sizeof(g_codepage));
752                    }
753            }
754    #endif
755    
756          if (g_hostname[0] == 0)          if (g_hostname[0] == 0)
757          {          {
758                  if (gethostname(fullhostname, sizeof(fullhostname)) == -1)                  if (gethostname(fullhostname, sizeof(fullhostname)) == -1)
# Line 678  main(int argc, char *argv[]) Line 768  main(int argc, char *argv[])
768                  STRNCPY(g_hostname, fullhostname, sizeof(g_hostname));                  STRNCPY(g_hostname, fullhostname, sizeof(g_hostname));
769          }          }
770    
771            if (g_keymapname[0] == 0)
772            {
773                    if (locale && xkeymap_from_locale(locale))
774                    {
775                            fprintf(stderr, "Autoselected keyboard map %s\n", g_keymapname);
776                    }
777                    else
778                    {
779                            STRNCPY(g_keymapname, "en-us", sizeof(g_keymapname));
780                    }
781            }
782            if (locale)
783                    xfree(locale);
784    
785    
786          if (prompt_password && read_password(password, sizeof(password)))          if (prompt_password && read_password(password, sizeof(password)))
787                  flags |= RDP_LOGON_AUTO;                  flags |= RDP_LOGON_AUTO;
788    
# Line 701  main(int argc, char *argv[]) Line 806  main(int argc, char *argv[])
806  #endif  #endif
807          rdpdr_init();          rdpdr_init();
808    
809          if (!rdp_connect(server, flags, domain, password, shell, directory))          while (run_count < 2 && continue_connect)       /* add support for Session Directory; only reconnect once */
810                  return 1;          {
811                    if (run_count == 0)
812                    {
813                            if (!rdp_connect(server, flags, domain, password, shell, directory))
814                                    return 1;
815                    }
816                    else if (!rdp_reconnect
817                             (server, flags, domain, password, shell, directory, g_redirect_cookie))
818                            return 1;
819    
820          /* By setting encryption to False here, we have an encrypted login                  /* By setting encryption to False here, we have an encrypted login
821             packet but unencrypted transfer of other packets */                     packet but unencrypted transfer of other packets */
822          if (!packet_encryption)                  if (!packet_encryption)
823                  g_encryption = False;                          g_encryption = False;
824    
825    
826          DEBUG(("Connection successful.\n"));                  DEBUG(("Connection successful.\n"));
827          memset(password, 0, sizeof(password));                  memset(password, 0, sizeof(password));
828    
829          if (ui_create_window())                  if (run_count == 0)
830          {                          if (!ui_create_window())
831                  rdp_main_loop(&deactivated, &ext_disc_reason);                                  continue_connect = False;
832                  ui_destroy_window();  
833                    if (continue_connect)
834                            rdp_main_loop(&deactivated, &ext_disc_reason);
835    
836                    DEBUG(("Disconnecting...\n"));
837                    rdp_disconnect();
838    
839                    if ((g_redirect == True) && (run_count == 0))   /* Support for Session Directory */
840                    {
841                            /* reset state of major globals */
842                            rdesktop_reset_state();
843    
844                            STRNCPY(domain, g_redirect_domain, sizeof(domain));
845                            STRNCPY(g_username, g_redirect_username, sizeof(g_username));
846                            STRNCPY(password, g_redirect_password, sizeof(password));
847                            STRNCPY(server, g_redirect_server, sizeof(server));
848                            flags |= RDP_LOGON_AUTO;
849    
850                            g_redirect = False;
851                    }
852                    else
853                    {
854                            continue_connect = False;
855                            ui_destroy_window();
856                            break;
857                    }
858    
859                    run_count++;
860          }          }
861    
         DEBUG(("Disconnecting...\n"));  
         rdp_disconnect();  
862          cache_save_state();          cache_save_state();
863          ui_deinit();          ui_deinit();
864    
# Line 847  xmalloc(int size) Line 985  xmalloc(int size)
985          return mem;          return mem;
986  }  }
987    
988    /* strdup */
989    char *
990    xstrdup(const char *s)
991    {
992            char *mem = strdup(s);
993            if (mem == NULL)
994            {
995                    perror("strdup");
996                    exit(1);
997            }
998            return mem;
999    }
1000    
1001  /* realloc; exit if out of memory */  /* realloc; exit if out of memory */
1002  void *  void *
1003  xrealloc(void *oldmem, int size)  xrealloc(void *oldmem, int size)
1004  {  {
1005          void *mem = realloc(oldmem, size);          void *mem;
1006    
1007            if (size < 1)
1008                    size = 1;
1009            mem = realloc(oldmem, size);
1010          if (mem == NULL)          if (mem == NULL)
1011          {          {
1012                  error("xrealloc %d\n", size);                  error("xrealloc %d\n", size);

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

  ViewVC Help
Powered by ViewVC 1.1.26