/[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 730 by jsorg71, Tue Jun 29 16:22:41 2004 UTC
# Line 43  Line 43 
43    
44  char g_title[64] = "";  char g_title[64] = "";
45  char g_username[64];  char g_username[64];
46  char hostname[16];  char g_hostname[16];
47  char keymapname[16];  char keymapname[16];
48  int keylayout = 0x409;          /* Defaults to US keyboard layout */  int g_keylayout = 0x409;        /* Defaults to US keyboard layout */
49    
50  int g_width = 800;              /* width is special: If 0, the  int g_width = 800;              /* width is special: If 0, the
51                                     geometry will be fetched from                                     geometry will be fetched from
# Line 53  int g_width = 800;             /* width is special: Line 53  int g_width = 800;             /* width is special:
53                                     absolute value specifies the                                     absolute value specifies the
54                                     percent of the whole screen. */                                     percent of the whole screen. */
55  int g_height = 600;  int g_height = 600;
56  int tcp_port_rdp = TCP_PORT_RDP;  extern int g_tcp_port_rdp;
57  int g_server_bpp = 8;  int g_server_bpp = 8;
58  int g_win_button_size = 0;      /* If zero, disable single app mode */  int g_win_button_size = 0;      /* If zero, disable single app mode */
59  BOOL g_bitmap_compression = True;  BOOL g_bitmap_compression = True;
60  BOOL g_sendmotion = True;  BOOL g_sendmotion = True;
61  BOOL g_orders = True;  BOOL g_bitmap_cache = True;
62    BOOL g_bitmap_cache_persist_enable = False;
63    BOOL g_bitmap_cache_precache = True;
64  BOOL g_encryption = True;  BOOL g_encryption = True;
65  BOOL packet_encryption = True;  BOOL packet_encryption = True;
66  BOOL g_desktop_save = True;  BOOL g_desktop_save = True;
# Line 68  BOOL g_hide_decorations = False; Line 70  BOOL g_hide_decorations = False;
70  BOOL g_use_rdp5 = True;  BOOL g_use_rdp5 = True;
71  BOOL g_console_session = False;  BOOL g_console_session = False;
72  BOOL g_numlock_sync = False;  BOOL g_numlock_sync = False;
73  extern BOOL g_owncolmap;  BOOL g_owncolmap = False;
74    BOOL g_ownbackstore = True;     /* We can't rely on external BackingStore */
75    uint32 g_embed_wnd;
76    uint32 g_rdp5_performanceflags =
77            RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS;
78    
79  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
80  BOOL g_rdpsnd = False;  BOOL g_rdpsnd = False;
# Line 76  BOOL g_rdpsnd = False; Line 82  BOOL g_rdpsnd = False;
82    
83  extern RDPDR_DEVICE g_rdpdr_device[];  extern RDPDR_DEVICE g_rdpdr_device[];
84  extern uint32 g_num_devices;  extern uint32 g_num_devices;
85    extern char *g_rdpdr_clientname;
86    
87  #ifdef RDP2VNC  #ifdef RDP2VNC
88  extern int rfb_port;  extern int rfb_port;
# Line 107  usage(char *program) Line 114  usage(char *program)
114          fprintf(stderr, "   -g: desktop geometry (WxH)\n");          fprintf(stderr, "   -g: desktop geometry (WxH)\n");
115          fprintf(stderr, "   -f: full-screen mode\n");          fprintf(stderr, "   -f: full-screen mode\n");
116          fprintf(stderr, "   -b: force bitmap updates\n");          fprintf(stderr, "   -b: force bitmap updates\n");
117            fprintf(stderr, "   -B: use BackingStore of X-server (if available)\n");
118          fprintf(stderr, "   -e: disable encryption (French TS)\n");          fprintf(stderr, "   -e: disable encryption (French TS)\n");
119          fprintf(stderr, "   -E: disable encryption from client to server\n");          fprintf(stderr, "   -E: disable encryption from client to server\n");
120          fprintf(stderr, "   -m: do not send motion events\n");          fprintf(stderr, "   -m: do not send motion events\n");
# Line 116  usage(char *program) Line 124  usage(char *program)
124          fprintf(stderr, "   -S: caption button size (single application mode)\n");          fprintf(stderr, "   -S: caption button size (single application mode)\n");
125          fprintf(stderr, "   -T: window title\n");          fprintf(stderr, "   -T: window title\n");
126          fprintf(stderr, "   -N: enable numlock syncronization\n");          fprintf(stderr, "   -N: enable numlock syncronization\n");
127            fprintf(stderr, "   -X: embed into another window with a given id.\n");
128          fprintf(stderr, "   -a: connection colour depth\n");          fprintf(stderr, "   -a: connection colour depth\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");          fprintf(stderr, "   -r: enable specified device redirection (this flag can be repeated)\n");
132          fprintf(stderr,          fprintf(stderr,
133                  "         '-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");
# Line 124  usage(char *program) Line 135  usage(char *program)
135          fprintf(stderr,          fprintf(stderr,
136                  "         '-r disk:A=/mnt/floppy': enable redirection of /mnt/floppy to A:\n");                  "         '-r disk:A=/mnt/floppy': enable redirection of /mnt/floppy to A:\n");
137          fprintf(stderr, "             or   A=/mnt/floppy,D=/mnt/cdrom'\n");          fprintf(stderr, "             or   A=/mnt/floppy,D=/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,          fprintf(stderr,
141                  "         '-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");
142          fprintf(stderr, "             or      LPT1=/dev/lp0,LPT2=/dev/lp1\n");          fprintf(stderr, "             or      LPT1=/dev/lp0,LPT2=/dev/lp1\n");
143          fprintf(stderr, "         '-r printer:mydeskjet': enable printer redirection\n");          fprintf(stderr, "         '-r printer:mydeskjet': enable printer redirection\n");
144          fprintf(stderr,          fprintf(stderr,
145                  "             or       mydeskjet=\"HP LaserJet IIIP\" to enter server driver as well\n");                  "             or      mydeskjet=\"HP LaserJet IIIP\" to enter server driver as well\n");
146          fprintf(stderr, "         '-r sound': enable sound redirection\n");          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");          fprintf(stderr, "   -0: attach to console\n");
149          fprintf(stderr, "   -4: use RDP version 4\n");          fprintf(stderr, "   -4: use RDP version 4\n");
150          fprintf(stderr, "   -5: use RDP version 5 (default)\n");          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
254  read_password(char *password, int size)  read_password(char *password, int size)
255  {  {
# Line 193  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 205  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 213  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 230  main(int argc, char *argv[]) Line 344  main(int argc, char *argv[])
344          char password[64];          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    
# Line 242  main(int argc, char *argv[]) Line 356  main(int argc, char *argv[])
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;          g_num_devices = 0;
362    
# Line 251  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:c:p:n:k:g:fbeEmCDKS:T:Na:r:045h?")) != -1)          while ((c = getopt(argc, argv,
370                            VNCOPT "u:d:s:c:p:n:k:g:fbBeEmCDKS:T:NX:a:x:Pr:045h?")) != -1)
371          {          {
372                  switch (c)                  switch (c)
373                  {                  {
# Line 303  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 344  main(int argc, char *argv[]) Line 460  main(int argc, char *argv[])
460                                  break;                                  break;
461    
462                          case 'b':                          case 'b':
463                                  g_orders = False;                                  g_bitmap_cache = False;
464                                    break;
465    
466                            case 'B':
467                                    g_ownbackstore = False;
468                                  break;                                  break;
469    
470                          case 'e':                          case 'e':
# Line 394  main(int argc, char *argv[]) Line 514  main(int argc, char *argv[])
514                                  g_numlock_sync = True;                                  g_numlock_sync = True;
515                                  break;                                  break;
516    
517                            case 'X':
518                                    g_embed_wnd = strtol(optarg, NULL, 10);
519                                    break;
520    
521                          case 'a':                          case 'a':
522                                  g_server_bpp = strtol(optarg, NULL, 10);                                  g_server_bpp = strtol(optarg, NULL, 10);
523                                  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 528  main(int argc, char *argv[])
528                                  }                                  }
529                                  break;                                  break;
530    
531                            case 'x':
532    
533                                    if (strncmp("modem", optarg, 1) == 0)
534                                    {
535                                            g_rdp5_performanceflags =
536                                                    RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG |
537                                                    RDP5_NO_MENUANIMATIONS | RDP5_NO_THEMING;
538                                    }
539                                    else if (strncmp("broadband", optarg, 1) == 0)
540                                    {
541                                            g_rdp5_performanceflags = RDP5_NO_WALLPAPER;
542                                    }
543                                    else if (strncmp("lan", optarg, 1) == 0)
544                                    {
545                                            g_rdp5_performanceflags = RDP5_DISABLE_NOTHING;
546                                    }
547                                    else
548                                    {
549                                            g_rdp5_performanceflags = strtol(optarg, NULL, 16);
550                                    }
551                                    break;
552    
553                            case 'P':
554                                    g_bitmap_cache_persist_enable = True;
555                                    break;
556    
557                          case 'r':                          case 'r':
558    
559                                  if (strncmp("sound", optarg, 5) == 0)                                  if (strncmp("sound", optarg, 5) == 0)
560                                  {                                  {
561                                            optarg += 5;
562    
563                                            if (*optarg == ':')
564                                            {
565                                                    *optarg++;
566                                                    while ((p = next_arg(optarg, ',')))
567                                                    {
568                                                            if (strncmp("remote", optarg, 6) == 0)
569                                                                    flags |= RDP_LOGON_LEAVE_AUDIO;
570    
571                                                            if (strncmp("local", optarg, 5) == 0)
572    #ifdef WITH_RDPSND
573                                                                    g_rdpsnd = True;
574    #else
575                                                                    warning("Not compiled with sound support");
576    #endif
577    
578                                                            if (strncmp("off", optarg, 3) == 0)
579    #ifdef WITH_RDPSND
580                                                                    g_rdpsnd = False;
581    #else
582                                                                    warning("Not compiled with sound support");
583    #endif
584    
585                                                            optarg = p;
586                                                    }
587                                            }
588                                            else
589                                            {
590  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
591                                          g_rdpsnd = True;                                                  g_rdpsnd = True;
592  #else  #else
593                                          warning("Not compiled with sound support");                                                  warning("Not compiled with sound support");
594  #endif  #endif
595                                            }
596                                  }                                  }
597                                  else if (strncmp("disk", optarg, 4) == 0)                                  else if (strncmp("disk", optarg, 4) == 0)
598                                  {                                  {
# Line 431  main(int argc, char *argv[]) Line 611  main(int argc, char *argv[])
611                                  {                                  {
612                                          printer_enum_devices(&g_num_devices, optarg + 7);                                          printer_enum_devices(&g_num_devices, optarg + 7);
613                                  }                                  }
614                                    else if (strncmp("clientname", optarg, 7) == 0)
615                                    {
616                                            g_rdpdr_clientname = xmalloc(strlen(optarg + 11) + 1);
617                                            strcpy(g_rdpdr_clientname, optarg + 11);
618                                    }
619                                  else                                  else
620                                  {                                  {
621                                          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 642  main(int argc, char *argv[])
642                  }                  }
643          }          }
644    
645          if (argc - optind < 1)          if (argc - optind != 1)
646          {          {
647                  usage(argv[0]);                  usage(argv[0]);
648                  return 1;                  return 1;
# Line 478  main(int argc, char *argv[]) Line 663  main(int argc, char *argv[])
663                  STRNCPY(g_username, pw->pw_name, sizeof(g_username));                  STRNCPY(g_username, pw->pw_name, sizeof(g_username));
664          }          }
665    
666          if (hostname[0] == 0)          if (g_hostname[0] == 0)
667          {          {
668                  if (gethostname(fullhostname, sizeof(fullhostname)) == -1)                  if (gethostname(fullhostname, sizeof(fullhostname)) == -1)
669                  {                  {
# Line 490  main(int argc, char *argv[]) Line 675  main(int argc, char *argv[])
675                  if (p != NULL)                  if (p != NULL)
676                          *p = 0;                          *p = 0;
677    
678                  STRNCPY(hostname, fullhostname, sizeof(hostname));                  STRNCPY(g_hostname, fullhostname, sizeof(g_hostname));
679          }          }
680    
681          if (prompt_password && read_password(password, sizeof(password)))          if (prompt_password && read_password(password, sizeof(password)))
# Line 530  main(int argc, char *argv[]) Line 715  main(int argc, char *argv[])
715    
716          if (ui_create_window())          if (ui_create_window())
717          {          {
718                  rdp_retval = rdp_main_loop();                  rdp_main_loop(&deactivated, &ext_disc_reason);
719                  ui_destroy_window();                  ui_destroy_window();
720          }          }
721    
722          DEBUG(("Disconnecting...\n"));          DEBUG(("Disconnecting...\n"));
723          rdp_disconnect();          rdp_disconnect();
724            cache_save_state();
725          ui_deinit();          ui_deinit();
726    
727          if (True == rdp_retval)          if (ext_disc_reason >= 2)
728                    print_disconnect_reason(ext_disc_reason);
729    
730            if (deactivated)
731            {
732                    /* clean disconnect */
733                  return 0;                  return 0;
734            }
735          else          else
736                  return 2;          {
737                    if (ext_disc_reason == exDiscReasonAPIInitiatedDisconnect
738                        || ext_disc_reason == exDiscReasonAPIInitiatedLogoff)
739                    {
740                            /* not so clean disconnect, but nothing to worry about */
741                            return 0;
742                    }
743                    else
744                    {
745                            /* return error */
746                            return 2;
747                    }
748            }
749    
750  #endif  #endif
751    
# Line 732  hexdump(unsigned char *p, unsigned int l Line 936  hexdump(unsigned char *p, unsigned int l
936  }  }
937    
938  /*  /*
939    input: src is the string we look in for needle    input: src is the string we look in for needle.
940             Needle may be escaped by a backslash, in
941             that case we ignore that particular needle.
942    return value: returns next src pointer, for    return value: returns next src pointer, for
943          succesive executions, like in a while loop          succesive executions, like in a while loop
944          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 1020  toupper_str(char *p)
1020  #define LTOA_BUFSIZE (sizeof(long) * 8 + 1)  #define LTOA_BUFSIZE (sizeof(long) * 8 + 1)
1021    
1022  char *  char *
1023  ltoa(long N, int base)  l_to_a(long N, int base)
1024  {  {
1025          static char ret[LTOA_BUFSIZE];          static char ret[LTOA_BUFSIZE];
1026    
1027          register int i = 2;          char *head = ret, buf[LTOA_BUFSIZE], *tail = buf + sizeof(buf);
         long uarg;  
         char *tail, *head = ret, buf[LTOA_BUFSIZE];  
1028    
1029          if (36 < base || 2 > base)          register int divrem;
                 base = 10;  
1030    
1031          tail = &buf[LTOA_BUFSIZE - 1];          if (base < 36 || 2 > base)
1032          *tail-- = '\0';                  base = 10;
1033    
1034          if (10 == base && N < 0L)          if (N < 0)
1035          {          {
1036                  *head++ = '-';                  *head++ = '-';
1037                  uarg = -N;                  N = -N;
1038          }          }
         else  
                 uarg = N;  
1039    
1040          if (uarg)          tail = buf + sizeof(buf);
1041          {          *--tail = 0;
                 for (i = 1; uarg; ++i)  
                 {  
                         register ldiv_t r;  
1042    
1043                          r = ldiv(uarg, base);          do
1044                          *tail-- = (char) (r.rem + ((9L < r.rem) ? ('A' - 10L) : '0'));          {
1045                          uarg = r.quot;                  divrem = N % base;
1046                  }                  *--tail = (divrem <= 9) ? divrem + '0' : divrem + 'a' - 10;
1047                    N /= base;
1048          }          }
1049          else          while (N);
                 *tail-- = '0';  
1050    
1051          memcpy(head, ++tail, i);          strcpy(head, tail);
1052          return ret;          return ret;
1053  }  }
1054    
# Line 866  load_licence(unsigned char **data) Line 1064  load_licence(unsigned char **data)
1064          if (home == NULL)          if (home == NULL)
1065                  return -1;                  return -1;
1066    
1067          path = (char *) xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence."));          path = (char *) xmalloc(strlen(home) + strlen(g_hostname) + sizeof("/.rdesktop/licence."));
1068          sprintf(path, "%s/.rdesktop/licence.%s", home, hostname);          sprintf(path, "%s/.rdesktop/licence.%s", home, g_hostname);
1069    
1070          fd = open(path, O_RDONLY);          fd = open(path, O_RDONLY);
1071          if (fd == -1)          if (fd == -1)
# Line 893  save_licence(unsigned char *data, int le Line 1091  save_licence(unsigned char *data, int le
1091          if (home == NULL)          if (home == NULL)
1092                  return;                  return;
1093    
1094          path = (char *) xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence."));          path = (char *) xmalloc(strlen(home) + strlen(g_hostname) + sizeof("/.rdesktop/licence."));
1095    
1096          sprintf(path, "%s/.rdesktop", home);          sprintf(path, "%s/.rdesktop", home);
1097          if ((mkdir(path, 0700) == -1) && errno != EEXIST)          if ((mkdir(path, 0700) == -1) && errno != EEXIST)
# Line 904  save_licence(unsigned char *data, int le Line 1102  save_licence(unsigned char *data, int le
1102    
1103          /* write licence to licence.hostname.new, then atomically rename to licence.hostname */          /* write licence to licence.hostname.new, then atomically rename to licence.hostname */
1104    
1105          sprintf(path, "%s/.rdesktop/licence.%s", home, hostname);          sprintf(path, "%s/.rdesktop/licence.%s", home, g_hostname);
1106          tmppath = (char *) xmalloc(strlen(path) + sizeof(".new"));          tmppath = (char *) xmalloc(strlen(path) + sizeof(".new"));
1107          strcpy(tmppath, path);          strcpy(tmppath, path);
1108          strcat(tmppath, ".new");          strcat(tmppath, ".new");
# Line 931  save_licence(unsigned char *data, int le Line 1129  save_licence(unsigned char *data, int le
1129          xfree(tmppath);          xfree(tmppath);
1130          xfree(path);          xfree(path);
1131  }  }
1132    
1133    /* Create the bitmap cache directory */
1134    BOOL
1135    rd_pstcache_mkdir(void)
1136    {
1137            char *home;
1138            char bmpcache_dir[256];
1139    
1140            home = getenv("HOME");
1141    
1142            if (home == NULL)
1143                    return False;
1144    
1145            sprintf(bmpcache_dir, "%s/%s", home, ".rdesktop");
1146    
1147            if ((mkdir(bmpcache_dir, S_IRWXU) == -1) && errno != EEXIST)
1148            {
1149                    perror(bmpcache_dir);
1150                    return False;
1151            }
1152    
1153            sprintf(bmpcache_dir, "%s/%s", home, ".rdesktop/cache");
1154    
1155            if ((mkdir(bmpcache_dir, S_IRWXU) == -1) && errno != EEXIST)
1156            {
1157                    perror(bmpcache_dir);
1158                    return False;
1159            }
1160    
1161            return True;
1162    }
1163    
1164    /* open a file in the .rdesktop directory */
1165    int
1166    rd_open_file(char *filename)
1167    {
1168            char *home;
1169            char fn[256];
1170       int fd;
1171    
1172            home = getenv("HOME");
1173            if (home == NULL)
1174                    return -1;
1175            sprintf(fn, "%s/.rdesktop/%s", home, filename);
1176            fd = open(fn, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
1177            if (fd == -1)
1178                    perror(fn);
1179            return fd;
1180    }
1181    
1182    /* close file */
1183    void
1184    rd_close_file(int fd)
1185    {
1186      close(fd);
1187    }
1188    
1189    /* read from file*/
1190    int
1191    rd_read_file(int fd, void *ptr, int len)
1192    {
1193      return read(fd, ptr, len);
1194    }
1195    
1196    /* write to file */
1197    int
1198    rd_write_file(int fd, void* ptr, int len)
1199    {
1200      return write(fd, ptr, len);
1201    }
1202    
1203    /* move file pointer */
1204    int
1205    rd_lseek_file(int fd, int offset)
1206    {
1207      return lseek(fd, offset, SEEK_SET);
1208    }
1209    
1210    /* do a write lock on a file */
1211    BOOL
1212    rd_lock_file(int fd, int start, int len)
1213    {
1214            struct flock lock;
1215    
1216            lock.l_type = F_WRLCK;
1217            lock.l_whence = SEEK_SET;
1218            lock.l_start = start;
1219            lock.l_len = len;
1220            if (fcntl(fd, F_SETLK, &lock) == -1)
1221                    return False;
1222            return True;
1223    }

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

  ViewVC Help
Powered by ViewVC 1.1.26