/[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 350 by forsberg, Thu Mar 27 13:18:13 2003 UTC revision 416 by forsberg, Fri Jun 6 11:11:20 2003 UTC
# Line 371  main(int argc, char *argv[]) Line 371  main(int argc, char *argv[])
371          if (!ui_init())          if (!ui_init())
372                  return 1;                  return 1;
373    
374            ipc_init();             // Must be run after ui_init, we need X to be setup.
375    
376            if (use_rdp5)
377                    cliprdr_init(); // FIXME: Should perhaps be integrated into the channel management code?
378    
379          if (!rdp_connect(server, flags, domain, password, shell, directory))          if (!rdp_connect(server, flags, domain, password, shell, directory))
380                  return 1;                  return 1;
381    
# Line 549  unimpl(char *format, ...) Line 554  unimpl(char *format, ...)
554    
555  /* produce a hex dump */  /* produce a hex dump */
556  void  void
557  hexdump(unsigned char *p, unsigned int len)  hexdump(unsigned char *p, int len)
558  {  {
559          unsigned char *line = p;          unsigned char *line = p;
560          unsigned int thisline, offset = 0;          int i, thisline, offset = 0;
         int i;  
561    
562          while (offset < len)          while (offset < len)
563          {          {
# Line 581  hexdump(unsigned char *p, unsigned int l Line 585  hexdump(unsigned char *p, unsigned int l
585  int  int
586  load_licence(unsigned char **data)  load_licence(unsigned char **data)
587  {  {
588          char *path;          char *home, *path;
         char *home;  
589          struct stat st;          struct stat st;
590          int fd;          int fd, length;
591    
592          home = getenv("HOME");          home = getenv("HOME");
593          if (home == NULL)          if (home == NULL)
594                  return -1;                  return -1;
595    
596          path = xmalloc(strlen(home) + strlen(hostname) + 20);          path = (char *) xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence."));
597          sprintf(path, "%s/.rdesktop/licence.%s", home, hostname);          sprintf(path, "%s/.rdesktop/licence.%s", home, hostname);
598    
599          fd = open(path, O_RDONLY);          fd = open(path, O_RDONLY);
# Line 600  load_licence(unsigned char **data) Line 603  load_licence(unsigned char **data)
603          if (fstat(fd, &st))          if (fstat(fd, &st))
604                  return -1;                  return -1;
605    
606          *data = xmalloc(st.st_size);          *data = (uint8 *) xmalloc(st.st_size);
607          return read(fd, *data, st.st_size);          length = read(fd, *data, st.st_size);
608            close(fd);
609            xfree(path);
610            return length;
611  }  }
612    
613  void  void
614  save_licence(unsigned char *data, int length)  save_licence(unsigned char *data, int length)
615  {  {
616          char *fpath;            /* file path for licence */          char *home, *path, *tmppath;
617          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;  
         }  
618    
619          home = getenv("HOME");          home = getenv("HOME");
620          if (home == NULL)          if (home == NULL)
621                  return;                  return;
622    
623          /* 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);  
624    
625          sprintf(fpath, "%s/.rdesktop", fpath);          sprintf(path, "%s/.rdesktop", home);
626          if (mkdir(fpath, 0700) == -1 && errno != EEXIST)          if ((mkdir(path, 0700) == -1) && errno != EEXIST)
627          {          {
628                  perror("mkdir");                  perror(path);
629                  exit(1);                  return;
630          }          }
631    
632          /* 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);  
         }  
633    
634          /* create a temporary licence file */          sprintf(path, "%s/.rdesktop/licence.%s", home, hostname);
635          fnamewrk = xmalloc(strlen(fname) + 12);          tmppath = (char *) xmalloc(strlen(path) + sizeof(".new"));
636          for (y = 0;; y++)          strcpy(tmppath, path);
637          {          strcat(tmppath, ".new");
                 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 */          fd = open(tmppath, O_WRONLY | O_CREAT | O_TRUNC, 0600);
640          if (close(fnwrkfd) == -1)          if (fd == -1)
641          {          {
642                  perror("close");                  perror(tmppath);
643                  unlink(fnamewrk);                  return;
                 exit(1);  
644          }          }
645          if (rename(fnamewrk, fname) == -1)  
646            if (write(fd, data, length) != length)
647          {          {
648                  perror("rename");                  perror(tmppath);
649                  unlink(fnamewrk);                  unlink(tmppath);
                 exit(1);  
650          }          }
651          /* close the file lock on fname */          else if (rename(tmppath, path) == -1)
         if (fnfd != -1)  
652          {          {
653                  fnfl.l_type = F_UNLCK;                  perror(path);
654                  fnfl.l_whence = SEEK_SET;                  unlink(tmppath);
                 fnfl.l_start = 0;  
                 fnfl.l_len = 1;  
                 fcntl(fnfd, F_SETLK, &fnfl);  
                 close(fnfd);  
655          }          }
656    
657            close(fd);
658            xfree(tmppath);
659            xfree(path);
660  }  }

Legend:
Removed from v.350  
changed lines
  Added in v.416

  ViewVC Help
Powered by ViewVC 1.1.26