/[rdesktop]/sourceforge.net/branches/seamlessrdp-branch/rdesktop/rdesktop.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /sourceforge.net/branches/seamlessrdp-branch/rdesktop/rdesktop.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 333 by astrand, Thu Feb 20 12:14:13 2003 UTC revision 424 by forsberg, Thu Jun 19 07:29:53 2003 UTC
# Line 1  Line 1 
1  /*  /* -*- 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-2003
# Line 59  BOOL desktop_save = True; Line 59  BOOL desktop_save = True;
59  BOOL fullscreen = False;  BOOL fullscreen = False;
60  BOOL grab_keyboard = True;  BOOL grab_keyboard = True;
61  BOOL hide_decorations = False;  BOOL hide_decorations = False;
62    BOOL use_rdp5 = False;
63  extern BOOL owncolmap;  extern BOOL owncolmap;
64    
65  #ifdef RDP2VNC  #ifdef RDP2VNC
# Line 99  usage(char *program) Line 100  usage(char *program)
100          fprintf(stderr, "   -T: window title\n");          fprintf(stderr, "   -T: window title\n");
101          fprintf(stderr, "   -D: hide window manager decorations\n");          fprintf(stderr, "   -D: hide window manager decorations\n");
102          fprintf(stderr, "   -a: server bpp\n");          fprintf(stderr, "   -a: server bpp\n");
103            fprintf(stderr, "   -5: Use RDP5 (EXPERIMENTAL!)\n");
104  }  }
105    
106  static BOOL  static BOOL
# Line 147  main(int argc, char *argv[]) Line 149  main(int argc, char *argv[])
149          char password[16];          char password[16];
150          char shell[128];          char shell[128];
151          char directory[32];          char directory[32];
152          BOOL prompt_password;          BOOL prompt_password, rdp_retval = False;
153          struct passwd *pw;          struct passwd *pw;
154          uint32 flags;          uint32 flags;
155          char *p;          char *p;
# Line 165  main(int argc, char *argv[]) Line 167  main(int argc, char *argv[])
167  #define VNCOPT  #define VNCOPT
168  #endif  #endif
169    
170          while ((c = getopt(argc, argv, VNCOPT "u:d:s:S:c:p:n:k:g:a:fbemCKT:Dh?")) != -1)          while ((c = getopt(argc, argv, VNCOPT "u:d:s:S:c:p:n:k:g:a:fbemCKT:Dh?54")) != -1)
171          {          {
172                  switch (c)                  switch (c)
173                  {                  {
# Line 301  main(int argc, char *argv[]) Line 303  main(int argc, char *argv[])
303                                  }                                  }
304                                  break;                                  break;
305    
306                            case '5':
307                                    use_rdp5 = True;
308                                    break;
309                          case 'h':                          case 'h':
310                          case '?':                          case '?':
311                          default:                          default:
# Line 361  main(int argc, char *argv[]) Line 366  main(int argc, char *argv[])
366    
367  #ifdef RDP2VNC  #ifdef RDP2VNC
368          rdp2vnc_connect(server, flags, domain, password, shell, directory);          rdp2vnc_connect(server, flags, domain, password, shell, directory);
369            return 0;
370  #else  #else
371    
372          if (!ui_init())          if (!ui_init())
373                  return 1;                  return 1;
374    
375            ipc_init();             // Must be run after ui_init, we need X to be setup.
376    
377            if (use_rdp5)
378                    cliprdr_init(); // FIXME: Should perhaps be integrated into the channel management code?
379    
380          if (!rdp_connect(server, flags, domain, password, shell, directory))          if (!rdp_connect(server, flags, domain, password, shell, directory))
381                  return 1;                  return 1;
382    
# Line 374  main(int argc, char *argv[]) Line 385  main(int argc, char *argv[])
385    
386          if (ui_create_window())          if (ui_create_window())
387          {          {
388                  rdp_main_loop();                  rdp_retval = rdp_main_loop();
389                  ui_destroy_window();                  ui_destroy_window();
390          }          }
391    
# Line 382  main(int argc, char *argv[]) Line 393  main(int argc, char *argv[])
393          rdp_disconnect();          rdp_disconnect();
394          ui_deinit();          ui_deinit();
395    
396            if (True == rdp_retval)
397                    return 0;
398            else
399                    return 2;
400    
401  #endif  #endif
402    
         return 0;  
403  }  }
404    
405  #ifdef EGD_SOCKET  #ifdef EGD_SOCKET
# Line 544  unimpl(char *format, ...) Line 559  unimpl(char *format, ...)
559    
560  /* produce a hex dump */  /* produce a hex dump */
561  void  void
562  hexdump(unsigned char *p, unsigned int len)  hexdump(unsigned char *p, int len)
563  {  {
564          unsigned char *line = p;          unsigned char *line = p;
565          unsigned int thisline, offset = 0;          int i, thisline, offset = 0;
         int i;  
566    
567          while (offset < len)          while (offset < len)
568          {          {
# Line 576  hexdump(unsigned char *p, unsigned int l Line 590  hexdump(unsigned char *p, unsigned int l
590  int  int
591  load_licence(unsigned char **data)  load_licence(unsigned char **data)
592  {  {
593          char *path;          char *home, *path;
         char *home;  
594          struct stat st;          struct stat st;
595          int fd;          int fd, length;
596    
597          home = getenv("HOME");          home = getenv("HOME");
598          if (home == NULL)          if (home == NULL)
599                  return -1;                  return -1;
600    
601          path = xmalloc(strlen(home) + strlen(hostname) + 20);          path = (char *) xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence."));
602          sprintf(path, "%s/.rdesktop/licence.%s", home, hostname);          sprintf(path, "%s/.rdesktop/licence.%s", home, hostname);
603    
604          fd = open(path, O_RDONLY);          fd = open(path, O_RDONLY);
# Line 595  load_licence(unsigned char **data) Line 608  load_licence(unsigned char **data)
608          if (fstat(fd, &st))          if (fstat(fd, &st))
609                  return -1;                  return -1;
610    
611          *data = xmalloc(st.st_size);          *data = (uint8 *) xmalloc(st.st_size);
612          return read(fd, *data, st.st_size);          length = read(fd, *data, st.st_size);
613            close(fd);
614            xfree(path);
615            return length;
616  }  }
617    
618  void  void
619  save_licence(unsigned char *data, int length)  save_licence(unsigned char *data, int length)
620  {  {
621          char *fpath;            /* file path for licence */          char *home, *path, *tmppath;
622          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(s_ptr, len);  
   
         /* Skip three strings */  
         for (i = 0; i < 3; i++)  
         {  
                 in_uint32(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(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;  
         }  
623    
624          home = getenv("HOME");          home = getenv("HOME");
625          if (home == NULL)          if (home == NULL)
626                  return;                  return;
627    
628          /* 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);  
629    
630          sprintf(fpath, "%s/.rdesktop", fpath);          sprintf(path, "%s/.rdesktop", home);
631          if (mkdir(fpath, 0700) == -1 && errno != EEXIST)          if ((mkdir(path, 0700) == -1) && errno != EEXIST)
632          {          {
633                  perror("mkdir");                  perror(path);
634                  exit(1);                  return;
635          }          }
636    
637          /* set the real licence filename, and put a write lock on it. */          /* write licence to licence.hostname.new, then atomically rename to licence.hostname */
         fname = xmalloc(strlen(fpath) + strlen(hostname) + 10);  
         sprintf(fname, "%s/licence.%s", fpath, hostname);  
         fnfd = open(fname, O_RDONLY);  
         if (fnfd != -1)  
         {  
                 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;  
         }  
638    
639          /* close the file and rename it to fname */          sprintf(path, "%s/.rdesktop/licence.%s", home, hostname);
640          if (close(fnwrkfd) == -1)          tmppath = (char *) xmalloc(strlen(path) + sizeof(".new"));
641            strcpy(tmppath, path);
642            strcat(tmppath, ".new");
643    
644            fd = open(tmppath, O_WRONLY | O_CREAT | O_TRUNC, 0600);
645            if (fd == -1)
646          {          {
647                  perror("close");                  perror(tmppath);
648                  unlink(fnamewrk);                  return;
                 exit(1);  
649          }          }
650          if (rename(fnamewrk, fname) == -1)  
651            if (write(fd, data, length) != length)
652          {          {
653                  perror("rename");                  perror(tmppath);
654                  unlink(fnamewrk);                  unlink(tmppath);
                 exit(1);  
655          }          }
656          /* close the file lock on fname */          else if (rename(tmppath, path) == -1)
         if (fnfd != -1)  
657          {          {
658                  fnfl.l_type = F_UNLCK;                  perror(path);
659                  fnfl.l_whence = SEEK_SET;                  unlink(tmppath);
                 fnfl.l_start = 0;  
                 fnfl.l_len = 1;  
                 fcntl(fnfd, F_SETLK, &fnfl);  
                 close(fnfd);  
660          }          }
661    
662            close(fd);
663            xfree(tmppath);
664            xfree(path);
665  }  }

Legend:
Removed from v.333  
changed lines
  Added in v.424

  ViewVC Help
Powered by ViewVC 1.1.26