/[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 474 by matthewc, Tue Sep 30 09:11:08 2003 UTC revision 848 by jsorg71, Sun Mar 13 03:29:19 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 26  Line 26 
26  #include <sys/stat.h>           /* stat */  #include <sys/stat.h>           /* stat */
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 */
30  #include <errno.h>  #include <errno.h>
31  #include "rdesktop.h"  #include "rdesktop.h"
32    
# Line 34  Line 35 
35  #include <sys/un.h>             /* sockaddr_un */  #include <sys/un.h>             /* sockaddr_un */
36  #endif  #endif
37    
 #ifdef WITH_OPENSSL  
38  #include <openssl/md5.h>  #include <openssl/md5.h>
 #else  
 #include "crypto/md5.h"  
 #endif  
39    
40  char g_title[32] = "";  char g_title[64] = "";
41  char g_username[16];  char g_username[64];
42  char hostname[16];  char g_hostname[16];
43  char keymapname[16];  char keymapname[16];
44  int keylayout = 0x409;          /* Defaults to US keyboard layout */  int g_keylayout = 0x409;        /* Defaults to US keyboard layout */
45  int g_width = 800;              /* If width or height are reset to zero, the geometry will  
46                                     be fetched from _NET_WORKAREA */  int g_width = 800;              /* width is special: If 0, the
47                                       geometry will be fetched from
48                                       _NET_WORKAREA. If negative,
49                                       absolute value specifies the
50                                       percent of the whole screen. */
51  int g_height = 600;  int g_height = 600;
52  int tcp_port_rdp = TCP_PORT_RDP;  int g_xpos = 0;
53    int g_ypos = 0;
54    extern int g_tcp_port_rdp;
55  int g_server_bpp = 8;  int g_server_bpp = 8;
56  int g_win_button_size = 0;      /* If zero, disable single app mode */  int g_win_button_size = 0;      /* If zero, disable single app mode */
57  BOOL g_bitmap_compression = True;  BOOL g_bitmap_compression = True;
58  BOOL g_sendmotion = True;  BOOL g_sendmotion = True;
59  BOOL g_orders = True;  BOOL g_bitmap_cache = True;
60    BOOL g_bitmap_cache_persist_enable = False;
61    BOOL g_bitmap_cache_precache = True;
62  BOOL g_encryption = True;  BOOL g_encryption = True;
63  BOOL packet_encryption = True;  BOOL packet_encryption = True;
64  BOOL g_desktop_save = True;  BOOL g_desktop_save = True;     /* desktop save order */
65    BOOL g_polygon_ellipse_orders = True;   /* polygon / ellipse orders */
66  BOOL g_fullscreen = False;  BOOL g_fullscreen = False;
67  BOOL g_grab_keyboard = True;  BOOL g_grab_keyboard = True;
68  BOOL g_hide_decorations = False;  BOOL g_hide_decorations = False;
69  BOOL g_use_rdp5 = True;  BOOL g_use_rdp5 = True;
70  extern BOOL g_owncolmap;  BOOL g_console_session = False;
71    BOOL g_numlock_sync = False;
72    BOOL g_owncolmap = False;
73    BOOL g_ownbackstore = True;     /* We can't rely on external BackingStore */
74    uint32 g_embed_wnd;
75    uint32 g_rdp5_performanceflags =
76            RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS;
77    
78    #ifdef WITH_RDPSND
79    BOOL g_rdpsnd = False;
80    #endif
81    
82    extern RDPDR_DEVICE g_rdpdr_device[];
83    extern uint32 g_num_devices;
84    extern char *g_rdpdr_clientname;
85    
86  #ifdef RDP2VNC  #ifdef RDP2VNC
87  extern int rfb_port;  extern int rfb_port;
# Line 75  static void Line 95  static void
95  usage(char *program)  usage(char *program)
96  {  {
97          fprintf(stderr, "rdesktop: A Remote Desktop Protocol client.\n");          fprintf(stderr, "rdesktop: A Remote Desktop Protocol client.\n");
98          fprintf(stderr, "Version " VERSION ". Copyright (C) 1999-2003 Matt Chapman.\n");          fprintf(stderr, "Version " VERSION ". Copyright (C) 1999-2005 Matt Chapman.\n");
99          fprintf(stderr, "See http://www.rdesktop.org/ for more information.\n\n");          fprintf(stderr, "See http://www.rdesktop.org/ for more information.\n\n");
100    
101          fprintf(stderr, "Usage: %s [options] server[:port]\n", program);          fprintf(stderr, "Usage: %s [options] server[:port]\n", program);
# Line 86  usage(char *program) Line 106  usage(char *program)
106          fprintf(stderr, "   -u: user name\n");          fprintf(stderr, "   -u: user name\n");
107          fprintf(stderr, "   -d: domain\n");          fprintf(stderr, "   -d: domain\n");
108          fprintf(stderr, "   -s: shell\n");          fprintf(stderr, "   -s: shell\n");
         fprintf(stderr, "   -S: caption button size (single application mode)\n");  
109          fprintf(stderr, "   -c: working directory\n");          fprintf(stderr, "   -c: working directory\n");
110          fprintf(stderr, "   -p: password (- to prompt)\n");          fprintf(stderr, "   -p: password (- to prompt)\n");
111          fprintf(stderr, "   -n: client hostname\n");          fprintf(stderr, "   -n: client hostname\n");
112          fprintf(stderr, "   -k: keyboard layout on terminal server (us,sv,gr,etc.)\n");          fprintf(stderr, "   -k: keyboard layout on server (en-us, de, sv, etc.)\n");
113          fprintf(stderr, "   -g: desktop geometry (WxH)\n");          fprintf(stderr, "   -g: desktop geometry (WxH)\n");
114          fprintf(stderr, "   -f: full-screen mode\n");          fprintf(stderr, "   -f: full-screen mode\n");
115          fprintf(stderr, "   -b: force bitmap updates\n");          fprintf(stderr, "   -b: force bitmap updates\n");
116            fprintf(stderr, "   -B: use BackingStore of X-server (if available)\n");
117          fprintf(stderr, "   -e: disable encryption (French TS)\n");          fprintf(stderr, "   -e: disable encryption (French TS)\n");
118          fprintf(stderr, "   -E: disable encryption from client to server\n");          fprintf(stderr, "   -E: disable encryption from client to server\n");
119          fprintf(stderr, "   -m: do not send motion events\n");          fprintf(stderr, "   -m: do not send motion events\n");
120          fprintf(stderr, "   -C: use private colour map\n");          fprintf(stderr, "   -C: use private colour map\n");
121            fprintf(stderr, "   -D: hide window manager decorations\n");
122          fprintf(stderr, "   -K: keep window manager key bindings\n");          fprintf(stderr, "   -K: keep window manager key bindings\n");
123            fprintf(stderr, "   -S: caption button size (single application mode)\n");
124          fprintf(stderr, "   -T: window title\n");          fprintf(stderr, "   -T: window title\n");
125          fprintf(stderr, "   -D: hide window manager decorations\n");          fprintf(stderr, "   -N: enable numlock syncronization\n");
126          fprintf(stderr, "   -a: server bpp\n");          fprintf(stderr, "   -X: embed into another window with a given id.\n");
127          fprintf(stderr, "   -4: Use RDP version 4\n");          fprintf(stderr, "   -a: connection colour depth\n");
128          fprintf(stderr, "   -5: Use RDP version 5 (default)\n");          fprintf(stderr, "   -z: enable rdp compression\n");
129            fprintf(stderr, "   -x: RDP5 experience (m[odem 28.8], b[roadband], l[an] or hex nr.)\n");
130            fprintf(stderr, "   -P: use persistent bitmap caching\n");
131            fprintf(stderr, "   -r: enable specified device redirection (this flag can be repeated)\n");
132            fprintf(stderr,
133                    "         '-r comport:COM1=/dev/ttyS0': enable serial redirection of /dev/ttyS0 to COM1\n");
134            fprintf(stderr, "             or      COM1=/dev/ttyS0,COM2=/dev/ttyS1\n");
135            fprintf(stderr,
136                    "         '-r disk:floppy=/mnt/floppy': enable redirection of /mnt/floppy to 'floppy' share\n");
137            fprintf(stderr, "             or   'floppy=/mnt/floppy,cdrom=/mnt/cdrom'\n");
138            fprintf(stderr, "         '-r clientname=<client name>': Set the client name displayed\n");
139            fprintf(stderr, "             for redirected disks\n");
140            fprintf(stderr,
141                    "         '-r lptport:LPT1=/dev/lp0': enable parallel redirection of /dev/lp0 to LPT1\n");
142            fprintf(stderr, "             or      LPT1=/dev/lp0,LPT2=/dev/lp1\n");
143            fprintf(stderr, "         '-r printer:mydeskjet': enable printer redirection\n");
144            fprintf(stderr,
145                    "             or      mydeskjet=\"HP LaserJet IIIP\" to enter server driver as well\n");
146            fprintf(stderr, "         '-r sound:[local|off|remote]': enable sound redirection\n");
147            fprintf(stderr, "                     remote would leave sound on server\n");
148            fprintf(stderr, "   -0: attach to console\n");
149            fprintf(stderr, "   -4: use RDP version 4\n");
150            fprintf(stderr, "   -5: use RDP version 5 (default)\n");
151    }
152    
153    void
154    print_disconnect_reason(uint16 reason)
155    {
156            char *text;
157    
158            switch (reason)
159            {
160                    case exDiscReasonNoInfo:
161                            text = "No information available";
162                            break;
163    
164                    case exDiscReasonAPIInitiatedDisconnect:
165                            text = "Server initiated disconnect";
166                            break;
167    
168                    case exDiscReasonAPIInitiatedLogoff:
169                            text = "Server initiated logoff";
170                            break;
171    
172                    case exDiscReasonServerIdleTimeout:
173                            text = "Server idle timeout reached";
174                            break;
175    
176                    case exDiscReasonServerLogonTimeout:
177                            text = "Server logon timeout reached";
178                            break;
179    
180                    case exDiscReasonReplacedByOtherConnection:
181                            text = "The session was replaced";
182                            break;
183    
184                    case exDiscReasonOutOfMemory:
185                            text = "The server is out of memory";
186                            break;
187    
188                    case exDiscReasonServerDeniedConnection:
189                            text = "The server denied the connection";
190                            break;
191    
192                    case exDiscReasonServerDeniedConnectionFips:
193                            text = "The server denied the connection for security reason";
194                            break;
195    
196                    case exDiscReasonLicenseInternal:
197                            text = "Internal licensing error";
198                            break;
199    
200                    case exDiscReasonLicenseNoLicenseServer:
201                            text = "No license server available";
202                            break;
203    
204                    case exDiscReasonLicenseNoLicense:
205                            text = "No valid license available";
206                            break;
207    
208                    case exDiscReasonLicenseErrClientMsg:
209                            text = "Invalid licensing message";
210                            break;
211    
212                    case exDiscReasonLicenseHwidDoesntMatchLicense:
213                            text = "Hardware id doesn't match software license";
214                            break;
215    
216                    case exDiscReasonLicenseErrClientLicense:
217                            text = "Client license error";
218                            break;
219    
220                    case exDiscReasonLicenseCantFinishProtocol:
221                            text = "Network error during licensing protocol";
222                            break;
223    
224                    case exDiscReasonLicenseClientEndedProtocol:
225                            text = "Licensing protocol was not completed";
226                            break;
227    
228                    case exDiscReasonLicenseErrClientEncryption:
229                            text = "Incorrect client license enryption";
230                            break;
231    
232                    case exDiscReasonLicenseCantUpgradeLicense:
233                            text = "Can't upgrade license";
234                            break;
235    
236                    case exDiscReasonLicenseNoRemoteConnections:
237                            text = "The server is not licensed to accept remote connections";
238                            break;
239    
240                    default:
241                            if (reason > 0x1000 && reason < 0x7fff)
242                            {
243                                    text = "Internal protocol error";
244                            }
245                            else
246                            {
247                                    text = "Unknown reason";
248                            }
249            }
250            fprintf(stderr, "disconnect: %s.\n", text);
251  }  }
252    
253  static BOOL  static BOOL
# Line 163  parse_server_and_port(char *server) Line 307  parse_server_and_port(char *server)
307                  if (*server == '[' && p != NULL)                  if (*server == '[' && p != NULL)
308                  {                  {
309                          if (*(p + 1) == ':' && *(p + 2) != '\0')                          if (*(p + 1) == ':' && *(p + 2) != '\0')
310                                  tcp_port_rdp = strtol(p + 2, NULL, 10);                                  g_tcp_port_rdp = strtol(p + 2, NULL, 10);
311                          /* remove the port number and brackets from the address */                          /* remove the port number and brackets from the address */
312                          *p = '\0';                          *p = '\0';
313                          strncpy(server, server + 1, strlen(server));                          strncpy(server, server + 1, strlen(server));
# Line 175  parse_server_and_port(char *server) Line 319  parse_server_and_port(char *server)
319                  p = strchr(server, ':');                  p = strchr(server, ':');
320                  if (p != NULL)                  if (p != NULL)
321                  {                  {
322                          tcp_port_rdp = strtol(p + 1, NULL, 10);                          g_tcp_port_rdp = strtol(p + 1, NULL, 10);
323                          *p = 0;                          *p = 0;
324                  }                  }
325          }          }
# Line 183  parse_server_and_port(char *server) Line 327  parse_server_and_port(char *server)
327          p = strchr(server, ':');          p = strchr(server, ':');
328          if (p != NULL)          if (p != NULL)
329          {          {
330                  tcp_port_rdp = strtol(p + 1, NULL, 10);                  g_tcp_port_rdp = strtol(p + 1, NULL, 10);
331                  *p = 0;                  *p = 0;
332          }          }
333  #endif /* IPv6 */  #endif /* IPv6 */
# Line 197  main(int argc, char *argv[]) Line 341  main(int argc, char *argv[])
341          char server[64];          char server[64];
342          char fullhostname[64];          char fullhostname[64];
343          char domain[16];          char domain[16];
344          char password[16];          char password[64];
345          char shell[128];          char shell[128];
346          char directory[32];          char directory[32];
347          BOOL prompt_password, rdp_retval = False;          BOOL prompt_password, deactivated;
348          struct passwd *pw;          struct passwd *pw;
349          uint32 flags;          uint32 flags, ext_disc_reason = 0;
350          char *p;          char *p;
351          int c;          int c;
352    
353          int username_option = 0;          int username_option = 0;
354    
355          flags = RDP_LOGON_NORMAL;          flags = RDP_LOGON_NORMAL;
356          prompt_password = False;          prompt_password = False;
357          domain[0] = password[0] = shell[0] = directory[0] = 0;          domain[0] = password[0] = shell[0] = directory[0] = 0;
358          strcpy(keymapname, "en-us");          strcpy(keymapname, "en-us");
359            g_embed_wnd = 0;
360    
361            g_num_devices = 0;
362    
363  #ifdef RDP2VNC  #ifdef RDP2VNC
364  #define VNCOPT "V:Q:"  #define VNCOPT "V:Q:"
# Line 218  main(int argc, char *argv[]) Line 366  main(int argc, char *argv[])
366  #define VNCOPT  #define VNCOPT
367  #endif  #endif
368    
369          while ((c = getopt(argc, argv, VNCOPT "u:d:s:S:c:p:n:k:g:a:fbeEmCKT:Dh?54")) != -1)          while ((c = getopt(argc, argv,
370                               VNCOPT "u:d:s:c:p:n:k:g:fbBeEmzCDKS:T:NX:a:x:Pr:045h?")) != -1)
371          {          {
372                  switch (c)                  switch (c)
373                  {                  {
# Line 249  main(int argc, char *argv[]) Line 398  main(int argc, char *argv[])
398                                  STRNCPY(shell, optarg, sizeof(shell));                                  STRNCPY(shell, optarg, sizeof(shell));
399                                  break;                                  break;
400    
                         case 'S':  
                                 if (!strcmp(optarg, "standard"))  
                                 {  
                                         g_win_button_size = 18;  
                                         break;  
                                 }  
   
                                 g_win_button_size = strtol(optarg, &p, 10);  
   
                                 if (*p)  
                                 {  
                                         error("invalid button size\n");  
                                         return 1;  
                                 }  
   
                                 break;  
   
401                          case 'c':                          case 'c':
402                                  STRNCPY(directory, optarg, sizeof(directory));                                  STRNCPY(directory, optarg, sizeof(directory));
403                                  break;                                  break;
# Line 287  main(int argc, char *argv[]) Line 419  main(int argc, char *argv[])
419                                  break;                                  break;
420    
421                          case 'n':                          case 'n':
422                                  STRNCPY(hostname, optarg, sizeof(hostname));                                  STRNCPY(g_hostname, optarg, sizeof(g_hostname));
423                                  break;                                  break;
424    
425                          case 'k':                          case 'k':
# Line 295  main(int argc, char *argv[]) Line 427  main(int argc, char *argv[])
427                                  break;                                  break;
428    
429                          case 'g':                          case 'g':
430                                    g_fullscreen = False;
431                                  if (!strcmp(optarg, "workarea"))                                  if (!strcmp(optarg, "workarea"))
432                                  {                                  {
433                                          g_width = g_height = 0;                                          g_width = g_height = 0;
# Line 302  main(int argc, char *argv[]) Line 435  main(int argc, char *argv[])
435                                  }                                  }
436    
437                                  g_width = strtol(optarg, &p, 10);                                  g_width = strtol(optarg, &p, 10);
438                                    if (g_width <= 0)
439                                    {
440                                            error("invalid geometry\n");
441                                            return 1;
442                                    }
443    
444                                  if (*p == 'x')                                  if (*p == 'x')
445                                          g_height = strtol(p + 1, NULL, 10);                                          g_height = strtol(p + 1, &p, 10);
446    
447                                  if ((g_width == 0) || (g_height == 0))                                  if (g_height <= 0)
448                                  {                                  {
449                                          error("invalid geometry\n");                                          error("invalid geometry\n");
450                                          return 1;                                          return 1;
451                                  }                                  }
452    
453                                    if (*p == '%')
454                                    {
455                                            g_width = -g_width;
456                                            p++;
457                                    }
458    
459                                    if (*p == '+' || *p == '-')
460                                            g_xpos = strtol(p, &p, 10);
461    
462                                    if (*p == '+' || *p == '-')
463                                            g_ypos = strtol(p, NULL, 10);
464    
465                                  break;                                  break;
466    
467                          case 'f':                          case 'f':
# Line 317  main(int argc, char *argv[]) Line 469  main(int argc, char *argv[])
469                                  break;                                  break;
470    
471                          case 'b':                          case 'b':
472                                  g_orders = False;                                  g_bitmap_cache = False;
473                                    break;
474    
475                            case 'B':
476                                    g_ownbackstore = False;
477                                  break;                                  break;
478    
479                          case 'e':                          case 'e':
# Line 334  main(int argc, char *argv[]) Line 490  main(int argc, char *argv[])
490                                  g_owncolmap = True;                                  g_owncolmap = True;
491                                  break;                                  break;
492    
493                            case 'D':
494                                    g_hide_decorations = True;
495                                    break;
496    
497                          case 'K':                          case 'K':
498                                  g_grab_keyboard = False;                                  g_grab_keyboard = False;
499                                  break;                                  break;
500    
501                            case 'S':
502                                    if (!strcmp(optarg, "standard"))
503                                    {
504                                            g_win_button_size = 18;
505                                            break;
506                                    }
507    
508                                    g_win_button_size = strtol(optarg, &p, 10);
509    
510                                    if (*p)
511                                    {
512                                            error("invalid button size\n");
513                                            return 1;
514                                    }
515    
516                                    break;
517    
518                          case 'T':                          case 'T':
519                                  STRNCPY(g_title, optarg, sizeof(g_title));                                  STRNCPY(g_title, optarg, sizeof(g_title));
520                                  break;                                  break;
521    
522                          case 'D':                          case 'N':
523                                  g_hide_decorations = True;                                  g_numlock_sync = True;
524                                    break;
525    
526                            case 'X':
527                                    g_embed_wnd = strtol(optarg, NULL, 10);
528                                  break;                                  break;
529    
530                          case 'a':                          case 'a':
# Line 356  main(int argc, char *argv[]) Line 537  main(int argc, char *argv[])
537                                  }                                  }
538                                  break;                                  break;
539    
540                            case 'z':
541                                    DEBUG(("rdp compression enabled\n"));
542                                    flags |= RDP_COMPRESSION;
543                                    break;
544    
545                            case 'x':
546                                    if (strncmp("modem", optarg, 1) == 0)
547                                    {
548                                            g_rdp5_performanceflags =
549                                                    RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG |
550                                                    RDP5_NO_MENUANIMATIONS | RDP5_NO_THEMING;
551                                    }
552                                    else if (strncmp("broadband", optarg, 1) == 0)
553                                    {
554                                            g_rdp5_performanceflags = RDP5_NO_WALLPAPER;
555                                    }
556                                    else if (strncmp("lan", optarg, 1) == 0)
557                                    {
558                                            g_rdp5_performanceflags = RDP5_DISABLE_NOTHING;
559                                    }
560                                    else
561                                    {
562                                            g_rdp5_performanceflags = strtol(optarg, NULL, 16);
563                                    }
564                                    break;
565    
566                            case 'P':
567                                    g_bitmap_cache_persist_enable = True;
568                                    break;
569    
570                            case 'r':
571    
572                                    if (strncmp("sound", optarg, 5) == 0)
573                                    {
574                                            optarg += 5;
575    
576                                            if (*optarg == ':')
577                                            {
578                                                    *optarg++;
579                                                    while ((p = next_arg(optarg, ',')))
580                                                    {
581                                                            if (strncmp("remote", optarg, 6) == 0)
582                                                                    flags |= RDP_LOGON_LEAVE_AUDIO;
583    
584                                                            if (strncmp("local", optarg, 5) == 0)
585    #ifdef WITH_RDPSND
586                                                                    g_rdpsnd = True;
587    #else
588                                                                    warning("Not compiled with sound support\n");
589    #endif
590    
591                                                            if (strncmp("off", optarg, 3) == 0)
592    #ifdef WITH_RDPSND
593                                                                    g_rdpsnd = False;
594    #else
595                                                                    warning("Not compiled with sound support\n");
596    #endif
597    
598                                                            optarg = p;
599                                                    }
600                                            }
601                                            else
602                                            {
603    #ifdef WITH_RDPSND
604                                                    g_rdpsnd = True;
605    #else
606                                                    warning("Not compiled with sound support\n");
607    #endif
608                                            }
609                                    }
610                                    else if (strncmp("disk", optarg, 4) == 0)
611                                    {
612                                            /* -r disk:h:=/mnt/floppy */
613                                            disk_enum_devices(&g_num_devices, optarg + 4);
614                                    }
615                                    else if (strncmp("comport", optarg, 7) == 0)
616                                    {
617                                            serial_enum_devices(&g_num_devices, optarg + 7);
618                                    }
619                                    else if (strncmp("lptport", optarg, 7) == 0)
620                                    {
621                                            parallel_enum_devices(&g_num_devices, optarg + 7);
622                                    }
623                                    else if (strncmp("printer", optarg, 7) == 0)
624                                    {
625                                            printer_enum_devices(&g_num_devices, optarg + 7);
626                                    }
627                                    else if (strncmp("clientname", optarg, 7) == 0)
628                                    {
629                                            g_rdpdr_clientname = xmalloc(strlen(optarg + 11) + 1);
630                                            strcpy(g_rdpdr_clientname, optarg + 11);
631                                    }
632                                    else
633                                    {
634                                            warning("Unknown -r argument\n\n\tPossible arguments are: comport, disk, lptport, printer, sound\n");
635                                    }
636                                    break;
637    
638                            case '0':
639                                    g_console_session = True;
640                                    break;
641    
642                          case '4':                          case '4':
643                                  g_use_rdp5 = False;                                  g_use_rdp5 = False;
644                                  break;                                  break;
# Line 372  main(int argc, char *argv[]) Line 655  main(int argc, char *argv[])
655                  }                  }
656          }          }
657    
658          if (argc - optind < 1)          if (argc - optind != 1)
659          {          {
660                  usage(argv[0]);                  usage(argv[0]);
661                  return 1;                  return 1;
# Line 393  main(int argc, char *argv[]) Line 676  main(int argc, char *argv[])
676                  STRNCPY(g_username, pw->pw_name, sizeof(g_username));                  STRNCPY(g_username, pw->pw_name, sizeof(g_username));
677          }          }
678    
679          if (hostname[0] == 0)          if (g_hostname[0] == 0)
680          {          {
681                  if (gethostname(fullhostname, sizeof(fullhostname)) == -1)                  if (gethostname(fullhostname, sizeof(fullhostname)) == -1)
682                  {                  {
# Line 405  main(int argc, char *argv[]) Line 688  main(int argc, char *argv[])
688                  if (p != NULL)                  if (p != NULL)
689                          *p = 0;                          *p = 0;
690    
691                  STRNCPY(hostname, fullhostname, sizeof(hostname));                  STRNCPY(g_hostname, fullhostname, sizeof(g_hostname));
692            }
693    
694            if ((flags & RDP_COMPRESSION) && (g_server_bpp > 8))
695            {
696                    warning("rdp compression not supported for bpp > 8, compression disabled\n");
697                    flags ^= RDP_COMPRESSION;
698          }          }
699    
700          if (prompt_password && read_password(password, sizeof(password)))          if (prompt_password && read_password(password, sizeof(password)))
# Line 426  main(int argc, char *argv[]) Line 715  main(int argc, char *argv[])
715                  return 1;                  return 1;
716    
717  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
718          rdpsnd_init();          if (g_rdpsnd)
719                    rdpsnd_init();
720  #endif  #endif
721          /* rdpdr_init(); */          rdpdr_init();
722    
723          if (!rdp_connect(server, flags, domain, password, shell, directory))          if (!rdp_connect(server, flags, domain, password, shell, directory))
724                  return 1;                  return 1;
# Line 444  main(int argc, char *argv[]) Line 734  main(int argc, char *argv[])
734    
735          if (ui_create_window())          if (ui_create_window())
736          {          {
737                  rdp_retval = rdp_main_loop();                  rdp_main_loop(&deactivated, &ext_disc_reason);
738                  ui_destroy_window();                  ui_destroy_window();
739          }          }
740    
741          DEBUG(("Disconnecting...\n"));          DEBUG(("Disconnecting...\n"));
742          rdp_disconnect();          rdp_disconnect();
743            cache_save_state();
744          ui_deinit();          ui_deinit();
745    
746          if (True == rdp_retval)          if (ext_disc_reason >= 2)
747                    print_disconnect_reason(ext_disc_reason);
748    
749            if (deactivated)
750            {
751                    /* clean disconnect */
752                  return 0;                  return 0;
753            }
754          else          else
755                  return 2;          {
756                    if (ext_disc_reason == exDiscReasonAPIInitiatedDisconnect
757                        || ext_disc_reason == exDiscReasonAPIInitiatedLogoff)
758                    {
759                            /* not so clean disconnect, but nothing to worry about */
760                            return 0;
761                    }
762                    else
763                    {
764                            /* return error */
765                            return 2;
766                    }
767            }
768    
769  #endif  #endif
770    
# Line 561  xmalloc(int size) Line 870  xmalloc(int size)
870  void *  void *
871  xrealloc(void *oldmem, int size)  xrealloc(void *oldmem, int size)
872  {  {
873          void *mem = realloc(oldmem, size);          void *mem;
874    
875            if (size < 1)
876                    size = 1;
877            mem = realloc(oldmem, size);
878          if (mem == NULL)          if (mem == NULL)
879          {          {
880                  error("xrealloc %d\n", size);                  error("xrealloc %d\n", size);
# Line 618  unimpl(char *format, ...) Line 931  unimpl(char *format, ...)
931    
932  /* produce a hex dump */  /* produce a hex dump */
933  void  void
934  hexdump(unsigned char *p, int len)  hexdump(unsigned char *p, unsigned int len)
935  {  {
936          unsigned char *line = p;          unsigned char *line = p;
937          int i, thisline, offset = 0;          int i, thisline, offset = 0;
# Line 645  hexdump(unsigned char *p, int len) Line 958  hexdump(unsigned char *p, int len)
958          }          }
959  }  }
960    
961    /*
962      input: src is the string we look in for needle.
963             Needle may be escaped by a backslash, in
964             that case we ignore that particular needle.
965      return value: returns next src pointer, for
966            succesive executions, like in a while loop
967            if retval is 0, then there are no more args.
968      pitfalls:
969            src is modified. 0x00 chars are inserted to
970            terminate strings.
971            return val, points on the next val chr after ins
972            0x00
973    
974            example usage:
975            while( (pos = next_arg( optarg, ',')) ){
976                    printf("%s\n",optarg);
977                    optarg=pos;
978            }
979    
980    */
981    char *
982    next_arg(char *src, char needle)
983    {
984            char *nextval;
985            char *p;
986            char *mvp = 0;
987    
988            /* EOS */
989            if (*src == (char) 0x00)
990                    return 0;
991    
992            p = src;
993            /*  skip escaped needles */
994            while ((nextval = strchr(p, needle)))
995            {
996                    mvp = nextval - 1;
997                    /* found backslashed needle */
998                    if (*mvp == '\\' && (mvp > src))
999                    {
1000                            /* move string one to the left */
1001                            while (*(mvp + 1) != (char) 0x00)
1002                            {
1003                                    *mvp = *(mvp + 1);
1004                                    *mvp++;
1005                            }
1006                            *mvp = (char) 0x00;
1007                            p = nextval;
1008                    }
1009                    else
1010                    {
1011                            p = nextval + 1;
1012                            break;
1013                    }
1014    
1015            }
1016    
1017            /* more args available */
1018            if (nextval)
1019            {
1020                    *nextval = (char) 0x00;
1021                    return ++nextval;
1022            }
1023    
1024            /* no more args after this, jump to EOS */
1025            nextval = src + strlen(src);
1026            return nextval;
1027    }
1028    
1029    
1030    void
1031    toupper_str(char *p)
1032    {
1033            while (*p)
1034            {
1035                    if ((*p >= 'a') && (*p <= 'z'))
1036                            *p = toupper((int) *p);
1037                    p++;
1038            }
1039    }
1040    
1041    
1042    /* not all clibs got ltoa */
1043    #define LTOA_BUFSIZE (sizeof(long) * 8 + 1)
1044    
1045    char *
1046    l_to_a(long N, int base)
1047    {
1048            static char ret[LTOA_BUFSIZE];
1049    
1050            char *head = ret, buf[LTOA_BUFSIZE], *tail = buf + sizeof(buf);
1051    
1052            register int divrem;
1053    
1054            if (base < 36 || 2 > base)
1055                    base = 10;
1056    
1057            if (N < 0)
1058            {
1059                    *head++ = '-';
1060                    N = -N;
1061            }
1062    
1063            tail = buf + sizeof(buf);
1064            *--tail = 0;
1065    
1066            do
1067            {
1068                    divrem = N % base;
1069                    *--tail = (divrem <= 9) ? divrem + '0' : divrem + 'a' - 10;
1070                    N /= base;
1071            }
1072            while (N);
1073    
1074            strcpy(head, tail);
1075            return ret;
1076    }
1077    
1078    
1079  int  int
1080  load_licence(unsigned char **data)  load_licence(unsigned char **data)
# Line 657  load_licence(unsigned char **data) Line 1087  load_licence(unsigned char **data)
1087          if (home == NULL)          if (home == NULL)
1088                  return -1;                  return -1;
1089    
1090          path = (char *) xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence."));          path = (char *) xmalloc(strlen(home) + strlen(g_hostname) + sizeof("/.rdesktop/licence."));
1091          sprintf(path, "%s/.rdesktop/licence.%s", home, hostname);          sprintf(path, "%s/.rdesktop/licence.%s", home, g_hostname);
1092    
1093          fd = open(path, O_RDONLY);          fd = open(path, O_RDONLY);
1094          if (fd == -1)          if (fd == -1)
# Line 684  save_licence(unsigned char *data, int le Line 1114  save_licence(unsigned char *data, int le
1114          if (home == NULL)          if (home == NULL)
1115                  return;                  return;
1116    
1117          path = (char *) xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence."));          path = (char *) xmalloc(strlen(home) + strlen(g_hostname) + sizeof("/.rdesktop/licence."));
1118    
1119          sprintf(path, "%s/.rdesktop", home);          sprintf(path, "%s/.rdesktop", home);
1120          if ((mkdir(path, 0700) == -1) && errno != EEXIST)          if ((mkdir(path, 0700) == -1) && errno != EEXIST)
# Line 695  save_licence(unsigned char *data, int le Line 1125  save_licence(unsigned char *data, int le
1125    
1126          /* write licence to licence.hostname.new, then atomically rename to licence.hostname */          /* write licence to licence.hostname.new, then atomically rename to licence.hostname */
1127    
1128          sprintf(path, "%s/.rdesktop/licence.%s", home, hostname);          sprintf(path, "%s/.rdesktop/licence.%s", home, g_hostname);
1129          tmppath = (char *) xmalloc(strlen(path) + sizeof(".new"));          tmppath = (char *) xmalloc(strlen(path) + sizeof(".new"));
1130          strcpy(tmppath, path);          strcpy(tmppath, path);
1131          strcat(tmppath, ".new");          strcat(tmppath, ".new");
# Line 722  save_licence(unsigned char *data, int le Line 1152  save_licence(unsigned char *data, int le
1152          xfree(tmppath);          xfree(tmppath);
1153          xfree(path);          xfree(path);
1154  }  }
1155    
1156    /* Create the bitmap cache directory */
1157    BOOL
1158    rd_pstcache_mkdir(void)
1159    {
1160            char *home;
1161            char bmpcache_dir[256];
1162    
1163            home = getenv("HOME");
1164    
1165            if (home == NULL)
1166                    return False;
1167    
1168            sprintf(bmpcache_dir, "%s/%s", home, ".rdesktop");
1169    
1170            if ((mkdir(bmpcache_dir, S_IRWXU) == -1) && errno != EEXIST)
1171            {
1172                    perror(bmpcache_dir);
1173                    return False;
1174            }
1175    
1176            sprintf(bmpcache_dir, "%s/%s", home, ".rdesktop/cache");
1177    
1178            if ((mkdir(bmpcache_dir, S_IRWXU) == -1) && errno != EEXIST)
1179            {
1180                    perror(bmpcache_dir);
1181                    return False;
1182            }
1183    
1184            return True;
1185    }
1186    
1187    /* open a file in the .rdesktop directory */
1188    int
1189    rd_open_file(char *filename)
1190    {
1191            char *home;
1192            char fn[256];
1193            int fd;
1194    
1195            home = getenv("HOME");
1196            if (home == NULL)
1197                    return -1;
1198            sprintf(fn, "%s/.rdesktop/%s", home, filename);
1199            fd = open(fn, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
1200            if (fd == -1)
1201                    perror(fn);
1202            return fd;
1203    }
1204    
1205    /* close file */
1206    void
1207    rd_close_file(int fd)
1208    {
1209            close(fd);
1210    }
1211    
1212    /* read from file*/
1213    int
1214    rd_read_file(int fd, void *ptr, int len)
1215    {
1216            return read(fd, ptr, len);
1217    }
1218    
1219    /* write to file */
1220    int
1221    rd_write_file(int fd, void *ptr, int len)
1222    {
1223            return write(fd, ptr, len);
1224    }
1225    
1226    /* move file pointer */
1227    int
1228    rd_lseek_file(int fd, int offset)
1229    {
1230            return lseek(fd, offset, SEEK_SET);
1231    }
1232    
1233    /* do a write lock on a file */
1234    BOOL
1235    rd_lock_file(int fd, int start, int len)
1236    {
1237            struct flock lock;
1238    
1239            lock.l_type = F_WRLCK;
1240            lock.l_whence = SEEK_SET;
1241            lock.l_start = start;
1242            lock.l_len = len;
1243            if (fcntl(fd, F_SETLK, &lock) == -1)
1244                    return False;
1245            return True;
1246    }

Legend:
Removed from v.474  
changed lines
  Added in v.848

  ViewVC Help
Powered by ViewVC 1.1.26