/[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 365 by matthewc, Wed Apr 16 08:19:15 2003 UTC revision 427 by forsberg, Thu Jun 19 11:51:18 2003 UTC
# Line 55  BOOL bitmap_compression = True; Line 55  BOOL bitmap_compression = True;
55  BOOL sendmotion = True;  BOOL sendmotion = True;
56  BOOL orders = True;  BOOL orders = True;
57  BOOL encryption = True;  BOOL encryption = True;
58    BOOL packet_encryption = True;
59  BOOL desktop_save = True;  BOOL desktop_save = True;
60  BOOL fullscreen = False;  BOOL fullscreen = False;
61  BOOL grab_keyboard = True;  BOOL grab_keyboard = True;
# Line 94  usage(char *program) Line 95  usage(char *program)
95          fprintf(stderr, "   -f: full-screen mode\n");          fprintf(stderr, "   -f: full-screen mode\n");
96          fprintf(stderr, "   -b: force bitmap updates\n");          fprintf(stderr, "   -b: force bitmap updates\n");
97          fprintf(stderr, "   -e: disable encryption (French TS)\n");          fprintf(stderr, "   -e: disable encryption (French TS)\n");
98            fprintf(stderr, "   -E: disable encryption of everything but the logon packet\n");
99          fprintf(stderr, "   -m: do not send motion events\n");          fprintf(stderr, "   -m: do not send motion events\n");
100          fprintf(stderr, "   -C: use private colour map\n");          fprintf(stderr, "   -C: use private colour map\n");
101          fprintf(stderr, "   -K: keep window manager key bindings\n");          fprintf(stderr, "   -K: keep window manager key bindings\n");
# Line 149  main(int argc, char *argv[]) Line 151  main(int argc, char *argv[])
151          char password[16];          char password[16];
152          char shell[128];          char shell[128];
153          char directory[32];          char directory[32];
154          BOOL prompt_password;          BOOL prompt_password, rdp_retval = False;
155          struct passwd *pw;          struct passwd *pw;
156          uint32 flags;          uint32 flags;
157          char *p;          char *p;
# Line 167  main(int argc, char *argv[]) Line 169  main(int argc, char *argv[])
169  #define VNCOPT  #define VNCOPT
170  #endif  #endif
171    
172          while ((c = getopt(argc, argv, VNCOPT "u:d:s:S:c:p:n:k:g:a:fbemCKT:Dh?54")) != -1)          while ((c = getopt(argc, argv, VNCOPT "u:d:s:S:c:p:n:k:g:a:fbeEmCKT:Dh?54")) != -1)
173          {          {
174                  switch (c)                  switch (c)
175                  {                  {
# Line 272  main(int argc, char *argv[]) Line 274  main(int argc, char *argv[])
274                          case 'e':                          case 'e':
275                                  encryption = False;                                  encryption = False;
276                                  break;                                  break;
277                            case 'E':
278                                    packet_encryption = False;
279                                    break;
280                          case 'm':                          case 'm':
281                                  sendmotion = False;                                  sendmotion = False;
282                                  break;                                  break;
# Line 366  main(int argc, char *argv[]) Line 370  main(int argc, char *argv[])
370    
371  #ifdef RDP2VNC  #ifdef RDP2VNC
372          rdp2vnc_connect(server, flags, domain, password, shell, directory);          rdp2vnc_connect(server, flags, domain, password, shell, directory);
373            return 0;
374  #else  #else
375    
376          if (!ui_init())          if (!ui_init())
377                  return 1;                  return 1;
378    
379            ipc_init();             // Must be run after ui_init, we need X to be setup.
380    
381            if (use_rdp5)
382                    cliprdr_init(); // FIXME: Should perhaps be integrated into the channel management code?
383    
384          if (!rdp_connect(server, flags, domain, password, shell, directory))          if (!rdp_connect(server, flags, domain, password, shell, directory))
385                  return 1;                  return 1;
386    
387            /* By setting encryption to False here, we have an encrypted login
388               packet but unencrypted transfer of other packets */
389            if (!packet_encryption)
390                    encryption = False;
391    
392    
393          DEBUG(("Connection successful.\n"));          DEBUG(("Connection successful.\n"));
394          memset(password, 0, sizeof(password));          memset(password, 0, sizeof(password));
395    
396          if (ui_create_window())          if (ui_create_window())
397          {          {
398                  rdp_main_loop();                  rdp_retval = rdp_main_loop();
399                  ui_destroy_window();                  ui_destroy_window();
400          }          }
401    
# Line 387  main(int argc, char *argv[]) Line 403  main(int argc, char *argv[])
403          rdp_disconnect();          rdp_disconnect();
404          ui_deinit();          ui_deinit();
405    
406            if (True == rdp_retval)
407                    return 0;
408            else
409                    return 2;
410    
411  #endif  #endif
412    
         return 0;  
413  }  }
414    
415  #ifdef EGD_SOCKET  #ifdef EGD_SOCKET
# Line 549  unimpl(char *format, ...) Line 569  unimpl(char *format, ...)
569    
570  /* produce a hex dump */  /* produce a hex dump */
571  void  void
572  hexdump(unsigned char *p, unsigned int len)  hexdump(unsigned char *p, int len)
573  {  {
574          unsigned char *line = p;          unsigned char *line = p;
575          unsigned int thisline, offset = 0;          int i, thisline, offset = 0;
         int i;  
576    
577          while (offset < len)          while (offset < len)
578          {          {
# Line 581  hexdump(unsigned char *p, unsigned int l Line 600  hexdump(unsigned char *p, unsigned int l
600  int  int
601  load_licence(unsigned char **data)  load_licence(unsigned char **data)
602  {  {
603          char *path;          char *home, *path;
         char *home;  
604          struct stat st;          struct stat st;
605          int fd;          int fd, length;
606    
607          home = getenv("HOME");          home = getenv("HOME");
608          if (home == NULL)          if (home == NULL)
609                  return -1;                  return -1;
610    
611          path = xmalloc(strlen(home) + strlen(hostname) + 20);          path = (char *) xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence."));
612          sprintf(path, "%s/.rdesktop/licence.%s", home, hostname);          sprintf(path, "%s/.rdesktop/licence.%s", home, hostname);
613    
614          fd = open(path, O_RDONLY);          fd = open(path, O_RDONLY);
# Line 600  load_licence(unsigned char **data) Line 618  load_licence(unsigned char **data)
618          if (fstat(fd, &st))          if (fstat(fd, &st))
619                  return -1;                  return -1;
620    
621          *data = xmalloc(st.st_size);          *data = (uint8 *) xmalloc(st.st_size);
622          return read(fd, *data, st.st_size);          length = read(fd, *data, st.st_size);
623            close(fd);
624            xfree(path);
625            return length;
626  }  }
627    
628  void  void
629  save_licence(unsigned char *data, int length)  save_licence(unsigned char *data, int length)
630  {  {
631          char *fpath;            /* file path for licence */          char *home, *path, *tmppath;
632          char *fname, *fnamewrk; /* file name for licence .inkl path. */          int fd;
         char *home;  
         uint32 y;  
         struct flock fnfl;  
         int fnfd, fnwrkfd, i, wlen;  
         struct stream s, *s_ptr;  
         uint32 len;  
   
         /* Construct a stream, so that we can use macros to extract the  
          * licence.  
          */  
         s_ptr = &s;  
         s_ptr->p = data;  
         /* Skip first two bytes */  
         in_uint16_le(s_ptr, len);  
   
         /* Skip three strings */  
         for (i = 0; i < 3; i++)  
         {  
                 in_uint32_le(s_ptr, len);  
                 s_ptr->p += len;  
                 /* Make sure that we won't be past the end of data after  
                  * reading the next length value  
                  */  
                 if ((s_ptr->p) + 4 > data + length)  
                 {  
                         printf("Error in parsing licence key.\n");  
                         printf("Strings %d end value %x > supplied length (%x)\n", i,  
                                (unsigned int) s_ptr->p, (unsigned int) data + length);  
                         return;  
                 }  
         }  
         in_uint32_le(s_ptr, len);  
         if (s_ptr->p + len > data + length)  
         {  
                 printf("Error in parsing licence key.\n");  
                 printf("End of licence %x > supplied length (%x)\n",  
                        (unsigned int) s_ptr->p + len, (unsigned int) data + length);  
                 return;  
         }  
633    
634          home = getenv("HOME");          home = getenv("HOME");
635          if (home == NULL)          if (home == NULL)
636                  return;                  return;
637    
638          /* set and create the directory -- if it doesn't exist. */          path = (char *) xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence."));
         fpath = xmalloc(strlen(home) + 11);  
         STRNCPY(fpath, home, strlen(home) + 1);  
639    
640          sprintf(fpath, "%s/.rdesktop", fpath);          sprintf(path, "%s/.rdesktop", home);
641          if (mkdir(fpath, 0700) == -1 && errno != EEXIST)          if ((mkdir(path, 0700) == -1) && errno != EEXIST)
642          {          {
643                  perror("mkdir");                  perror(path);
644                  exit(1);                  return;
645          }          }
646    
647          /* set the real licence filename, and put a write lock on it. */          /* write licence to licence.hostname.new, then atomically rename to licence.hostname */
648          fname = xmalloc(strlen(fpath) + strlen(hostname) + 10);  
649          sprintf(fname, "%s/licence.%s", fpath, hostname);          sprintf(path, "%s/.rdesktop/licence.%s", home, hostname);
650          fnfd = open(fname, O_RDONLY);          tmppath = (char *) xmalloc(strlen(path) + sizeof(".new"));
651          if (fnfd != -1)          strcpy(tmppath, path);
652          {          strcat(tmppath, ".new");
                 fnfl.l_type = F_WRLCK;  
                 fnfl.l_whence = SEEK_SET;  
                 fnfl.l_start = 0;  
                 fnfl.l_len = 1;  
                 fcntl(fnfd, F_SETLK, &fnfl);  
         }  
   
         /* create a temporary licence file */  
         fnamewrk = xmalloc(strlen(fname) + 12);  
         for (y = 0;; y++)  
         {  
                 sprintf(fnamewrk, "%s.%lu", fname, (long unsigned int) y);  
                 fnwrkfd = open(fnamewrk, O_WRONLY | O_CREAT | O_EXCL, 0600);  
                 if (fnwrkfd == -1)  
                 {  
                         if (errno == EINTR || errno == EEXIST)  
                                 continue;  
                         perror("create");  
                         exit(1);  
                 }  
                 break;  
         }  
         /* write to the licence file */  
         for (y = 0; y < len;)  
         {  
                 do  
                 {  
                         wlen = write(fnwrkfd, s_ptr->p + y, len - y);  
                 }  
                 while (wlen == -1 && errno == EINTR);  
                 if (wlen < 1)  
                 {  
                         perror("write");  
                         unlink(fnamewrk);  
                         exit(1);  
                 }  
                 y += wlen;  
         }  
653    
654          /* close the file and rename it to fname */          fd = open(tmppath, O_WRONLY | O_CREAT | O_TRUNC, 0600);
655          if (close(fnwrkfd) == -1)          if (fd == -1)
656          {          {
657                  perror("close");                  perror(tmppath);
658                  unlink(fnamewrk);                  return;
                 exit(1);  
659          }          }
660          if (rename(fnamewrk, fname) == -1)  
661            if (write(fd, data, length) != length)
662          {          {
663                  perror("rename");                  perror(tmppath);
664                  unlink(fnamewrk);                  unlink(tmppath);
                 exit(1);  
665          }          }
666          /* close the file lock on fname */          else if (rename(tmppath, path) == -1)
         if (fnfd != -1)  
667          {          {
668                  fnfl.l_type = F_UNLCK;                  perror(path);
669                  fnfl.l_whence = SEEK_SET;                  unlink(tmppath);
                 fnfl.l_start = 0;  
                 fnfl.l_len = 1;  
                 fcntl(fnfd, F_SETLK, &fnfl);  
                 close(fnfd);  
670          }          }
671    
672            close(fd);
673            xfree(tmppath);
674            xfree(path);
675  }  }

Legend:
Removed from v.365  
changed lines
  Added in v.427

  ViewVC Help
Powered by ViewVC 1.1.26