/[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 582 by n-ki, Fri Jan 23 14:37:51 2004 UTC revision 747 by astrand, Mon Aug 9 13:50:41 2004 UTC
# Line 35  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[64] = "";  char g_title[64] = "";
41  char g_username[64];  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    
46  int g_width = 800;              /* width is special: If 0, the  int g_width = 800;              /* width is special: If 0, the
47                                     geometry will be fetched from                                     geometry will be fetched from
# Line 53  int g_width = 800;             /* width is special: Line 49  int g_width = 800;             /* width is special:
49                                     absolute value specifies the                                     absolute value specifies the
50                                     percent of the whole screen. */                                     percent of the whole screen. */
51  int g_height = 600;  int g_height = 600;
52  int tcp_port_rdp = TCP_PORT_RDP;  extern int g_tcp_port_rdp;
53  int g_server_bpp = 8;  int g_server_bpp = 8;
54  int g_win_button_size = 0;      /* If zero, disable single app mode */  int g_win_button_size = 0;      /* If zero, disable single app mode */
55  BOOL g_bitmap_compression = True;  BOOL g_bitmap_compression = True;
56  BOOL g_sendmotion = True;  BOOL g_sendmotion = True;
57  BOOL g_orders = True;  BOOL g_bitmap_cache = True;
58    BOOL g_bitmap_cache_persist_enable = False;
59    BOOL g_bitmap_cache_precache = True;
60  BOOL g_encryption = True;  BOOL g_encryption = True;
61  BOOL packet_encryption = True;  BOOL packet_encryption = True;
62  BOOL g_desktop_save = True;  BOOL g_desktop_save = True;
# Line 68  BOOL g_hide_decorations = False; Line 66  BOOL g_hide_decorations = False;
66  BOOL g_use_rdp5 = True;  BOOL g_use_rdp5 = True;
67  BOOL g_console_session = False;  BOOL g_console_session = False;
68  BOOL g_numlock_sync = False;  BOOL g_numlock_sync = False;
69  extern BOOL g_owncolmap;  BOOL g_owncolmap = False;
70    BOOL g_ownbackstore = True;     /* We can't rely on external BackingStore */
71    uint32 g_embed_wnd;
72    uint32 g_rdp5_performanceflags =
73            RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS;
74    
75  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
76  BOOL g_rdpsnd = False;  BOOL g_rdpsnd = False;
# Line 76  BOOL g_rdpsnd = False; Line 78  BOOL g_rdpsnd = False;
78    
79  extern RDPDR_DEVICE g_rdpdr_device[];  extern RDPDR_DEVICE g_rdpdr_device[];
80  extern uint32 g_num_devices;  extern uint32 g_num_devices;
81    extern char *g_rdpdr_clientname;
82    
83  #ifdef RDP2VNC  #ifdef RDP2VNC
84  extern int rfb_port;  extern int rfb_port;
# Line 107  usage(char *program) Line 110  usage(char *program)
110          fprintf(stderr, "   -g: desktop geometry (WxH)\n");          fprintf(stderr, "   -g: desktop geometry (WxH)\n");
111          fprintf(stderr, "   -f: full-screen mode\n");          fprintf(stderr, "   -f: full-screen mode\n");
112          fprintf(stderr, "   -b: force bitmap updates\n");          fprintf(stderr, "   -b: force bitmap updates\n");
113            fprintf(stderr, "   -B: use BackingStore of X-server (if available)\n");
114          fprintf(stderr, "   -e: disable encryption (French TS)\n");          fprintf(stderr, "   -e: disable encryption (French TS)\n");
115          fprintf(stderr, "   -E: disable encryption from client to server\n");          fprintf(stderr, "   -E: disable encryption from client to server\n");
116          fprintf(stderr, "   -m: do not send motion events\n");          fprintf(stderr, "   -m: do not send motion events\n");
# Line 116  usage(char *program) Line 120  usage(char *program)
120          fprintf(stderr, "   -S: caption button size (single application mode)\n");          fprintf(stderr, "   -S: caption button size (single application mode)\n");
121          fprintf(stderr, "   -T: window title\n");          fprintf(stderr, "   -T: window title\n");
122          fprintf(stderr, "   -N: enable numlock syncronization\n");          fprintf(stderr, "   -N: enable numlock syncronization\n");
123            fprintf(stderr, "   -X: embed into another window with a given id.\n");
124          fprintf(stderr, "   -a: connection colour depth\n");          fprintf(stderr, "   -a: connection colour depth\n");
125            fprintf(stderr, "   -x: RDP5 experience (m[odem 28.8], b[roadband], l[an] or hex nr.)\n");
126            fprintf(stderr, "   -P: use persistent bitmap caching\n");
127          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");
128          fprintf(stderr,          fprintf(stderr,
129                  "         '-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");
130          fprintf(stderr, "             or      COM1=/dev/ttyS0,COM2=/dev/ttyS1\n");          fprintf(stderr, "             or      COM1=/dev/ttyS0,COM2=/dev/ttyS1\n");
131          fprintf(stderr,          fprintf(stderr,
132                  "         '-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");
133          fprintf(stderr, "             or   A=/mnt/floppy,D=/mnt/cdrom'\n");          fprintf(stderr, "             or   'floppy=/mnt/floppy,cdrom=/mnt/cdrom'\n");
134            fprintf(stderr, "         '-r clientname=<client name>': Set the client name displayed\n");
135            fprintf(stderr, "             for redirected disks\n");
136          fprintf(stderr,          fprintf(stderr,
137                  "         '-r lptport:LPT1=/dev/lp0': enable parallel redirection of /dev/lp0 to LPT1\n");                  "         '-r lptport:LPT1=/dev/lp0': enable parallel redirection of /dev/lp0 to LPT1\n");
138          fprintf(stderr, "             or      LPT1=/dev/lp0,LPT2=/dev/lp1\n");          fprintf(stderr, "             or      LPT1=/dev/lp0,LPT2=/dev/lp1\n");
139          fprintf(stderr, "         '-r printer:mydeskjet': enable printer redirection\n");          fprintf(stderr, "         '-r printer:mydeskjet': enable printer redirection\n");
140          fprintf(stderr,          fprintf(stderr,
141                  "             or       mydeskjet=\"HP LaserJet IIIP\" to enter server driver as well\n");                  "             or      mydeskjet=\"HP LaserJet IIIP\" to enter server driver as well\n");
142          fprintf(stderr, "         '-r sound': enable sound redirection\n");          fprintf(stderr, "         '-r sound:[local|off|remote]': enable sound redirection\n");
143            fprintf(stderr, "                     remote would leave sound on server\n");
144          fprintf(stderr, "   -0: attach to console\n");          fprintf(stderr, "   -0: attach to console\n");
145          fprintf(stderr, "   -4: use RDP version 4\n");          fprintf(stderr, "   -4: use RDP version 4\n");
146          fprintf(stderr, "   -5: use RDP version 5 (default)\n");          fprintf(stderr, "   -5: use RDP version 5 (default)\n");
147  }  }
148    
149    void
150    print_disconnect_reason(uint16 reason)
151    {
152            char *text;
153    
154            switch (reason)
155            {
156                    case exDiscReasonNoInfo:
157                            text = "No information available";
158                            break;
159    
160                    case exDiscReasonAPIInitiatedDisconnect:
161                            text = "Server initiated disconnect";
162                            break;
163    
164                    case exDiscReasonAPIInitiatedLogoff:
165                            text = "Server initiated logoff";
166                            break;
167    
168                    case exDiscReasonServerIdleTimeout:
169                            text = "Server idle timeout reached";
170                            break;
171    
172                    case exDiscReasonServerLogonTimeout:
173                            text = "Server logon timeout reached";
174                            break;
175    
176                    case exDiscReasonReplacedByOtherConnection:
177                            text = "The session was replaced";
178                            break;
179    
180                    case exDiscReasonOutOfMemory:
181                            text = "The server is out of memory";
182                            break;
183    
184                    case exDiscReasonServerDeniedConnection:
185                            text = "The server denied the connection";
186                            break;
187    
188                    case exDiscReasonServerDeniedConnectionFips:
189                            text = "The server denied the connection for security reason";
190                            break;
191    
192                    case exDiscReasonLicenseInternal:
193                            text = "Internal licensing error";
194                            break;
195    
196                    case exDiscReasonLicenseNoLicenseServer:
197                            text = "No license server available";
198                            break;
199    
200                    case exDiscReasonLicenseNoLicense:
201                            text = "No valid license available";
202                            break;
203    
204                    case exDiscReasonLicenseErrClientMsg:
205                            text = "Invalid licensing message";
206                            break;
207    
208                    case exDiscReasonLicenseHwidDoesntMatchLicense:
209                            text = "Hardware id doesn't match software license";
210                            break;
211    
212                    case exDiscReasonLicenseErrClientLicense:
213                            text = "Client license error";
214                            break;
215    
216                    case exDiscReasonLicenseCantFinishProtocol:
217                            text = "Network error during licensing protocol";
218                            break;
219    
220                    case exDiscReasonLicenseClientEndedProtocol:
221                            text = "Licensing protocol was not completed";
222                            break;
223    
224                    case exDiscReasonLicenseErrClientEncryption:
225                            text = "Incorrect client license enryption";
226                            break;
227    
228                    case exDiscReasonLicenseCantUpgradeLicense:
229                            text = "Can't upgrade license";
230                            break;
231    
232                    case exDiscReasonLicenseNoRemoteConnections:
233                            text = "The server is not licensed to accept remote connections";
234                            break;
235    
236                    default:
237                            if (reason > 0x1000 && reason < 0x7fff)
238                            {
239                                    text = "Internal protocol error";
240                            }
241                            else
242                            {
243                                    text = "Unknown reason";
244                            }
245            }
246            fprintf(stderr, "disconnect: %s.\n", text);
247    }
248    
249  static BOOL  static BOOL
250  read_password(char *password, int size)  read_password(char *password, int size)
251  {  {
# Line 193  parse_server_and_port(char *server) Line 303  parse_server_and_port(char *server)
303                  if (*server == '[' && p != NULL)                  if (*server == '[' && p != NULL)
304                  {                  {
305                          if (*(p + 1) == ':' && *(p + 2) != '\0')                          if (*(p + 1) == ':' && *(p + 2) != '\0')
306                                  tcp_port_rdp = strtol(p + 2, NULL, 10);                                  g_tcp_port_rdp = strtol(p + 2, NULL, 10);
307                          /* remove the port number and brackets from the address */                          /* remove the port number and brackets from the address */
308                          *p = '\0';                          *p = '\0';
309                          strncpy(server, server + 1, strlen(server));                          strncpy(server, server + 1, strlen(server));
# Line 205  parse_server_and_port(char *server) Line 315  parse_server_and_port(char *server)
315                  p = strchr(server, ':');                  p = strchr(server, ':');
316                  if (p != NULL)                  if (p != NULL)
317                  {                  {
318                          tcp_port_rdp = strtol(p + 1, NULL, 10);                          g_tcp_port_rdp = strtol(p + 1, NULL, 10);
319                          *p = 0;                          *p = 0;
320                  }                  }
321          }          }
# Line 213  parse_server_and_port(char *server) Line 323  parse_server_and_port(char *server)
323          p = strchr(server, ':');          p = strchr(server, ':');
324          if (p != NULL)          if (p != NULL)
325          {          {
326                  tcp_port_rdp = strtol(p + 1, NULL, 10);                  g_tcp_port_rdp = strtol(p + 1, NULL, 10);
327                  *p = 0;                  *p = 0;
328          }          }
329  #endif /* IPv6 */  #endif /* IPv6 */
# Line 230  main(int argc, char *argv[]) Line 340  main(int argc, char *argv[])
340          char password[64];          char password[64];
341          char shell[128];          char shell[128];
342          char directory[32];          char directory[32];
343          BOOL prompt_password, rdp_retval = False;          BOOL prompt_password, deactivated;
344          struct passwd *pw;          struct passwd *pw;
345          uint32 flags;          uint32 flags, ext_disc_reason = 0;
346          char *p;          char *p;
347          int c;          int c;
348    
# Line 242  main(int argc, char *argv[]) Line 352  main(int argc, char *argv[])
352          prompt_password = False;          prompt_password = False;
353          domain[0] = password[0] = shell[0] = directory[0] = 0;          domain[0] = password[0] = shell[0] = directory[0] = 0;
354          strcpy(keymapname, "en-us");          strcpy(keymapname, "en-us");
355            g_embed_wnd = 0;
356    
357          g_num_devices = 0;          g_num_devices = 0;
358    
# Line 251  main(int argc, char *argv[]) Line 362  main(int argc, char *argv[])
362  #define VNCOPT  #define VNCOPT
363  #endif  #endif
364    
365          while ((c = getopt(argc, argv, VNCOPT "u:d:s:c:p:n:k:g:fbeEmCDKS:T:Na:r:045h?")) != -1)          while ((c = getopt(argc, argv,
366                               VNCOPT "u:d:s:c:p:n:k:g:fbBeEmCDKS:T:NX:a:x:Pr:045h?")) != -1)
367          {          {
368                  switch (c)                  switch (c)
369                  {                  {
# Line 303  main(int argc, char *argv[]) Line 415  main(int argc, char *argv[])
415                                  break;                                  break;
416    
417                          case 'n':                          case 'n':
418                                  STRNCPY(hostname, optarg, sizeof(hostname));                                  STRNCPY(g_hostname, optarg, sizeof(g_hostname));
419                                  break;                                  break;
420    
421                          case 'k':                          case 'k':
# Line 344  main(int argc, char *argv[]) Line 456  main(int argc, char *argv[])
456                                  break;                                  break;
457    
458                          case 'b':                          case 'b':
459                                  g_orders = False;                                  g_bitmap_cache = False;
460                                    break;
461    
462                            case 'B':
463                                    g_ownbackstore = False;
464                                  break;                                  break;
465    
466                          case 'e':                          case 'e':
# Line 394  main(int argc, char *argv[]) Line 510  main(int argc, char *argv[])
510                                  g_numlock_sync = True;                                  g_numlock_sync = True;
511                                  break;                                  break;
512    
513                            case 'X':
514                                    g_embed_wnd = strtol(optarg, NULL, 10);
515                                    break;
516    
517                          case 'a':                          case 'a':
518                                  g_server_bpp = strtol(optarg, NULL, 10);                                  g_server_bpp = strtol(optarg, NULL, 10);
519                                  if (g_server_bpp != 8 && g_server_bpp != 16 && g_server_bpp != 15                                  if (g_server_bpp != 8 && g_server_bpp != 16 && g_server_bpp != 15
# Line 404  main(int argc, char *argv[]) Line 524  main(int argc, char *argv[])
524                                  }                                  }
525                                  break;                                  break;
526    
527                            case 'x':
528    
529                                    if (strncmp("modem", optarg, 1) == 0)
530                                    {
531                                            g_rdp5_performanceflags =
532                                                    RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG |
533                                                    RDP5_NO_MENUANIMATIONS | RDP5_NO_THEMING;
534                                    }
535                                    else if (strncmp("broadband", optarg, 1) == 0)
536                                    {
537                                            g_rdp5_performanceflags = RDP5_NO_WALLPAPER;
538                                    }
539                                    else if (strncmp("lan", optarg, 1) == 0)
540                                    {
541                                            g_rdp5_performanceflags = RDP5_DISABLE_NOTHING;
542                                    }
543                                    else
544                                    {
545                                            g_rdp5_performanceflags = strtol(optarg, NULL, 16);
546                                    }
547                                    break;
548    
549                            case 'P':
550                                    g_bitmap_cache_persist_enable = True;
551                                    break;
552    
553                          case 'r':                          case 'r':
554    
555                                  if (strncmp("sound", optarg, 5) == 0)                                  if (strncmp("sound", optarg, 5) == 0)
556                                  {                                  {
557                                            optarg += 5;
558    
559                                            if (*optarg == ':')
560                                            {
561                                                    *optarg++;
562                                                    while ((p = next_arg(optarg, ',')))
563                                                    {
564                                                            if (strncmp("remote", optarg, 6) == 0)
565                                                                    flags |= RDP_LOGON_LEAVE_AUDIO;
566    
567                                                            if (strncmp("local", optarg, 5) == 0)
568    #ifdef WITH_RDPSND
569                                                                    g_rdpsnd = True;
570    #else
571                                                                    warning("Not compiled with sound support\n");
572    #endif
573    
574                                                            if (strncmp("off", optarg, 3) == 0)
575    #ifdef WITH_RDPSND
576                                                                    g_rdpsnd = False;
577    #else
578                                                                    warning("Not compiled with sound support\n");
579    #endif
580    
581                                                            optarg = p;
582                                                    }
583                                            }
584                                            else
585                                            {
586  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
587                                          g_rdpsnd = True;                                                  g_rdpsnd = True;
588  #else  #else
589                                          warning("Not compiled with sound support");                                                  warning("Not compiled with sound support\n");
590  #endif  #endif
591                                            }
592                                  }                                  }
593                                  else if (strncmp("disk", optarg, 4) == 0)                                  else if (strncmp("disk", optarg, 4) == 0)
594                                  {                                  {
# Line 431  main(int argc, char *argv[]) Line 607  main(int argc, char *argv[])
607                                  {                                  {
608                                          printer_enum_devices(&g_num_devices, optarg + 7);                                          printer_enum_devices(&g_num_devices, optarg + 7);
609                                  }                                  }
610                                    else if (strncmp("clientname", optarg, 7) == 0)
611                                    {
612                                            g_rdpdr_clientname = xmalloc(strlen(optarg + 11) + 1);
613                                            strcpy(g_rdpdr_clientname, optarg + 11);
614                                    }
615                                  else                                  else
616                                  {                                  {
617                                          warning("Unknown -r argument\n\n\tPossible arguments are: comport, disk, lptport, printer, sound\n");                                          warning("Unknown -r argument\n\n\tPossible arguments are: comport, disk, lptport, printer, sound\n");
# Line 457  main(int argc, char *argv[]) Line 638  main(int argc, char *argv[])
638                  }                  }
639          }          }
640    
641          if (argc - optind < 1)          if (argc - optind != 1)
642          {          {
643                  usage(argv[0]);                  usage(argv[0]);
644                  return 1;                  return 1;
# Line 478  main(int argc, char *argv[]) Line 659  main(int argc, char *argv[])
659                  STRNCPY(g_username, pw->pw_name, sizeof(g_username));                  STRNCPY(g_username, pw->pw_name, sizeof(g_username));
660          }          }
661    
662          if (hostname[0] == 0)          if (g_hostname[0] == 0)
663          {          {
664                  if (gethostname(fullhostname, sizeof(fullhostname)) == -1)                  if (gethostname(fullhostname, sizeof(fullhostname)) == -1)
665                  {                  {
# Line 490  main(int argc, char *argv[]) Line 671  main(int argc, char *argv[])
671                  if (p != NULL)                  if (p != NULL)
672                          *p = 0;                          *p = 0;
673    
674                  STRNCPY(hostname, fullhostname, sizeof(hostname));                  STRNCPY(g_hostname, fullhostname, sizeof(g_hostname));
675          }          }
676    
677          if (prompt_password && read_password(password, sizeof(password)))          if (prompt_password && read_password(password, sizeof(password)))
# Line 530  main(int argc, char *argv[]) Line 711  main(int argc, char *argv[])
711    
712          if (ui_create_window())          if (ui_create_window())
713          {          {
714                  rdp_retval = rdp_main_loop();                  rdp_main_loop(&deactivated, &ext_disc_reason);
715                  ui_destroy_window();                  ui_destroy_window();
716          }          }
717    
718          DEBUG(("Disconnecting...\n"));          DEBUG(("Disconnecting...\n"));
719          rdp_disconnect();          rdp_disconnect();
720            cache_save_state();
721          ui_deinit();          ui_deinit();
722    
723          if (True == rdp_retval)          if (ext_disc_reason >= 2)
724                    print_disconnect_reason(ext_disc_reason);
725    
726            if (deactivated)
727            {
728                    /* clean disconnect */
729                  return 0;                  return 0;
730            }
731          else          else
732                  return 2;          {
733                    if (ext_disc_reason == exDiscReasonAPIInitiatedDisconnect
734                        || ext_disc_reason == exDiscReasonAPIInitiatedLogoff)
735                    {
736                            /* not so clean disconnect, but nothing to worry about */
737                            return 0;
738                    }
739                    else
740                    {
741                            /* return error */
742                            return 2;
743                    }
744            }
745    
746  #endif  #endif
747    
# Line 732  hexdump(unsigned char *p, unsigned int l Line 932  hexdump(unsigned char *p, unsigned int l
932  }  }
933    
934  /*  /*
935    input: src is the string we look in for needle    input: src is the string we look in for needle.
936             Needle may be escaped by a backslash, in
937             that case we ignore that particular needle.
938    return value: returns next src pointer, for    return value: returns next src pointer, for
939          succesive executions, like in a while loop          succesive executions, like in a while loop
940          if retval is 0, then there are no more args.          if retval is 0, then there are no more args.
# Line 814  toupper_str(char *p) Line 1016  toupper_str(char *p)
1016  #define LTOA_BUFSIZE (sizeof(long) * 8 + 1)  #define LTOA_BUFSIZE (sizeof(long) * 8 + 1)
1017    
1018  char *  char *
1019  ltoa(long N, int base)  l_to_a(long N, int base)
1020  {  {
1021          static char ret[LTOA_BUFSIZE];          static char ret[LTOA_BUFSIZE];
1022    
1023          register int i = 2;          char *head = ret, buf[LTOA_BUFSIZE], *tail = buf + sizeof(buf);
         long uarg;  
         char *tail, *head = ret, buf[LTOA_BUFSIZE];  
1024    
1025          if (36 < base || 2 > base)          register int divrem;
                 base = 10;  
1026    
1027          tail = &buf[LTOA_BUFSIZE - 1];          if (base < 36 || 2 > base)
1028          *tail-- = '\0';                  base = 10;
1029    
1030          if (10 == base && N < 0L)          if (N < 0)
1031          {          {
1032                  *head++ = '-';                  *head++ = '-';
1033                  uarg = -N;                  N = -N;
1034          }          }
         else  
                 uarg = N;  
1035    
1036          if (uarg)          tail = buf + sizeof(buf);
1037          {          *--tail = 0;
                 for (i = 1; uarg; ++i)  
                 {  
                         register ldiv_t r;  
1038    
1039                          r = ldiv(uarg, base);          do
1040                          *tail-- = (char) (r.rem + ((9L < r.rem) ? ('A' - 10L) : '0'));          {
1041                          uarg = r.quot;                  divrem = N % base;
1042                  }                  *--tail = (divrem <= 9) ? divrem + '0' : divrem + 'a' - 10;
1043                    N /= base;
1044          }          }
1045          else          while (N);
                 *tail-- = '0';  
1046    
1047          memcpy(head, ++tail, i);          strcpy(head, tail);
1048          return ret;          return ret;
1049  }  }
1050    
# Line 866  load_licence(unsigned char **data) Line 1060  load_licence(unsigned char **data)
1060          if (home == NULL)          if (home == NULL)
1061                  return -1;                  return -1;
1062    
1063          path = (char *) xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence."));          path = (char *) xmalloc(strlen(home) + strlen(g_hostname) + sizeof("/.rdesktop/licence."));
1064          sprintf(path, "%s/.rdesktop/licence.%s", home, hostname);          sprintf(path, "%s/.rdesktop/licence.%s", home, g_hostname);
1065    
1066          fd = open(path, O_RDONLY);          fd = open(path, O_RDONLY);
1067          if (fd == -1)          if (fd == -1)
# Line 893  save_licence(unsigned char *data, int le Line 1087  save_licence(unsigned char *data, int le
1087          if (home == NULL)          if (home == NULL)
1088                  return;                  return;
1089    
1090          path = (char *) xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence."));          path = (char *) xmalloc(strlen(home) + strlen(g_hostname) + sizeof("/.rdesktop/licence."));
1091    
1092          sprintf(path, "%s/.rdesktop", home);          sprintf(path, "%s/.rdesktop", home);
1093          if ((mkdir(path, 0700) == -1) && errno != EEXIST)          if ((mkdir(path, 0700) == -1) && errno != EEXIST)
# Line 904  save_licence(unsigned char *data, int le Line 1098  save_licence(unsigned char *data, int le
1098    
1099          /* write licence to licence.hostname.new, then atomically rename to licence.hostname */          /* write licence to licence.hostname.new, then atomically rename to licence.hostname */
1100    
1101          sprintf(path, "%s/.rdesktop/licence.%s", home, hostname);          sprintf(path, "%s/.rdesktop/licence.%s", home, g_hostname);
1102          tmppath = (char *) xmalloc(strlen(path) + sizeof(".new"));          tmppath = (char *) xmalloc(strlen(path) + sizeof(".new"));
1103          strcpy(tmppath, path);          strcpy(tmppath, path);
1104          strcat(tmppath, ".new");          strcat(tmppath, ".new");
# Line 931  save_licence(unsigned char *data, int le Line 1125  save_licence(unsigned char *data, int le
1125          xfree(tmppath);          xfree(tmppath);
1126          xfree(path);          xfree(path);
1127  }  }
1128    
1129    /* Create the bitmap cache directory */
1130    BOOL
1131    rd_pstcache_mkdir(void)
1132    {
1133            char *home;
1134            char bmpcache_dir[256];
1135    
1136            home = getenv("HOME");
1137    
1138            if (home == NULL)
1139                    return False;
1140    
1141            sprintf(bmpcache_dir, "%s/%s", home, ".rdesktop");
1142    
1143            if ((mkdir(bmpcache_dir, S_IRWXU) == -1) && errno != EEXIST)
1144            {
1145                    perror(bmpcache_dir);
1146                    return False;
1147            }
1148    
1149            sprintf(bmpcache_dir, "%s/%s", home, ".rdesktop/cache");
1150    
1151            if ((mkdir(bmpcache_dir, S_IRWXU) == -1) && errno != EEXIST)
1152            {
1153                    perror(bmpcache_dir);
1154                    return False;
1155            }
1156    
1157            return True;
1158    }
1159    
1160    /* open a file in the .rdesktop directory */
1161    int
1162    rd_open_file(char *filename)
1163    {
1164            char *home;
1165            char fn[256];
1166            int fd;
1167    
1168            home = getenv("HOME");
1169            if (home == NULL)
1170                    return -1;
1171            sprintf(fn, "%s/.rdesktop/%s", home, filename);
1172            fd = open(fn, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
1173            if (fd == -1)
1174                    perror(fn);
1175            return fd;
1176    }
1177    
1178    /* close file */
1179    void
1180    rd_close_file(int fd)
1181    {
1182            close(fd);
1183    }
1184    
1185    /* read from file*/
1186    int
1187    rd_read_file(int fd, void *ptr, int len)
1188    {
1189            return read(fd, ptr, len);
1190    }
1191    
1192    /* write to file */
1193    int
1194    rd_write_file(int fd, void *ptr, int len)
1195    {
1196            return write(fd, ptr, len);
1197    }
1198    
1199    /* move file pointer */
1200    int
1201    rd_lseek_file(int fd, int offset)
1202    {
1203            return lseek(fd, offset, SEEK_SET);
1204    }
1205    
1206    /* do a write lock on a file */
1207    BOOL
1208    rd_lock_file(int fd, int start, int len)
1209    {
1210            struct flock lock;
1211    
1212            lock.l_type = F_WRLCK;
1213            lock.l_whence = SEEK_SET;
1214            lock.l_start = start;
1215            lock.l_len = len;
1216            if (fcntl(fd, F_SETLK, &lock) == -1)
1217                    return False;
1218            return True;
1219    }

Legend:
Removed from v.582  
changed lines
  Added in v.747

  ViewVC Help
Powered by ViewVC 1.1.26