/[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 317 by astrand, Mon Feb 10 12:56:34 2003 UTC revision 328 by astrand, Tue Feb 18 13:03:51 2003 UTC
# Line 26  Line 26 
26  #include <sys/stat.h>           /* stat */  #include <sys/stat.h>           /* stat */
27  #include <sys/time.h>           /* gettimeofday */  #include <sys/time.h>           /* gettimeofday */
28  #include <sys/times.h>          /* times */  #include <sys/times.h>          /* times */
29    #include <errno.h>
30  #include "rdesktop.h"  #include "rdesktop.h"
31    
32  #ifdef EGD_SOCKET  #ifdef EGD_SOCKET
# Line 49  int width = 800;               /* If width or height Line 50  int width = 800;               /* If width or height
50  int height = 600;  int height = 600;
51  int tcp_port_rdp = TCP_PORT_RDP;  int tcp_port_rdp = TCP_PORT_RDP;
52  int server_bpp = 8;  int server_bpp = 8;
53    int win_button_size = 0;        /* If zero, disable single app mode */
54  BOOL bitmap_compression = True;  BOOL bitmap_compression = True;
55  BOOL sendmotion = True;  BOOL sendmotion = True;
56  BOOL orders = True;  BOOL orders = True;
# Line 145  main(int argc, char *argv[]) Line 147  main(int argc, char *argv[])
147          domain[0] = password[0] = shell[0] = directory[0] = 0;          domain[0] = password[0] = shell[0] = directory[0] = 0;
148          strcpy(keymapname, "en-us");          strcpy(keymapname, "en-us");
149    
150          while ((c = getopt(argc, argv, "u:d:s:c:p:n:k:g:a:fbemCKT:Dh?")) != -1)          while ((c = getopt(argc, argv, "u:d:s:S:c:p:n:k:g:a:fbemCKT:Dh?")) != -1)
151          {          {
152                  switch (c)                  switch (c)
153                  {                  {
# Line 162  main(int argc, char *argv[]) Line 164  main(int argc, char *argv[])
164                                  STRNCPY(shell, optarg, sizeof(shell));                                  STRNCPY(shell, optarg, sizeof(shell));
165                                  break;                                  break;
166    
167                            case 'S':
168                                    if (!strcmp(optarg, "standard"))
169                                    {
170                                            win_button_size = 18;
171                                            break;
172                                    }
173    
174                                    win_button_size = strtol(optarg, &p, 10);
175    
176                                    if (*p)
177                                    {
178                                            error("invalid button size\n");
179                                            return 1;
180                                    }
181    
182                                    break;
183    
184                          case 'c':                          case 'c':
185                                  STRNCPY(directory, optarg, sizeof(directory));                                  STRNCPY(directory, optarg, sizeof(directory));
186                                  break;                                  break;
# Line 242  main(int argc, char *argv[]) Line 261  main(int argc, char *argv[])
261    
262                          case 'a':                          case 'a':
263                                  server_bpp = strtol(optarg, NULL, 10);                                  server_bpp = strtol(optarg, NULL, 10);
264                                  if (server_bpp != 8 && server_bpp != 16 && server_bpp != 15 && server_bpp != 24)                                  if (server_bpp != 8 && server_bpp != 16 && server_bpp != 15
265                                        && server_bpp != 24)
266                                  {                                  {
267                                          error("invalid server bpp\n");                                          error("invalid server bpp\n");
268                                          return 1;                                          return 1;
# Line 513  hexdump(unsigned char *p, unsigned int l Line 533  hexdump(unsigned char *p, unsigned int l
533          }          }
534  }  }
535    
536    
537    int
538    load_licence(unsigned char **data)
539    {
540            char *path;
541            char *home;
542            struct stat st;
543            int fd;
544    
545            home = getenv("HOME");
546            if (home == NULL)
547                    return -1;
548    
549            path = xmalloc(strlen(home) + strlen(hostname) + 20);
550            sprintf(path, "%s/.rdesktop/licence.%s", home, hostname);
551    
552            fd = open(path, O_RDONLY);
553            if (fd == -1)
554                    return -1;
555    
556            if (fstat(fd, &st))
557                    return -1;
558    
559            *data = xmalloc(st.st_size);
560            return read(fd, *data, st.st_size);
561    }
562    
563    void
564    save_licence(unsigned char *data, int length)
565    {
566            char *fpath;            /* file path for licence */
567            char *fname, *fnamewrk; /* file name for licence .inkl path. */
568            char *home;
569            uint32 y;
570            struct flock fnfl;
571            int fnfd, fnwrkfd, i, wlen;
572            struct stream s, *s_ptr;
573            uint32 len;
574    
575            /* Construct a stream, so that we can use macros to extract the
576             * licence.
577             */
578            s_ptr = &s;
579            s_ptr->p = data;
580            /* Skip first two bytes */
581            in_uint16(s_ptr, len);
582    
583            /* Skip three strings */
584            for (i = 0; i < 3; i++)
585            {
586                    in_uint32(s_ptr, len);
587                    s_ptr->p += len;
588                    /* Make sure that we won't be past the end of data after
589                     * reading the next length value
590                     */
591                    if ((s_ptr->p) + 4 > data + length)
592                    {
593                            printf("Error in parsing licence key.\n");
594                            printf("Strings %d end value %x > supplied length (%x)\n", i,
595                                   (unsigned int) s_ptr->p, (unsigned int) data + length);
596                            return;
597                    }
598            }
599            in_uint32(s_ptr, len);
600            if (s_ptr->p + len > data + length)
601            {
602                    printf("Error in parsing licence key.\n");
603                    printf("End of licence %x > supplied length (%x)\n",
604                           (unsigned int) s_ptr->p + len, (unsigned int) data + length);
605                    return;
606            }
607    
608            home = getenv("HOME");
609            if (home == NULL)
610                    return;
611    
612            /* set and create the directory -- if it doesn't exist. */
613            fpath = xmalloc(strlen(home) + 11);
614            STRNCPY(fpath, home, strlen(home) + 1);
615    
616            sprintf(fpath, "%s/.rdesktop", fpath);
617            if (mkdir(fpath, 0700) == -1 && errno != EEXIST)
618            {
619                    perror("mkdir");
620                    exit(1);
621            }
622    
623            /* set the real licence filename, and put a write lock on it. */
624            fname = xmalloc(strlen(fpath) + strlen(hostname) + 10);
625            sprintf(fname, "%s/licence.%s", fpath, hostname);
626            fnfd = open(fname, O_RDONLY);
627            if (fnfd != -1)
628            {
629                    fnfl.l_type = F_WRLCK;
630                    fnfl.l_whence = SEEK_SET;
631                    fnfl.l_start = 0;
632                    fnfl.l_len = 1;
633                    fcntl(fnfd, F_SETLK, &fnfl);
634            }
635    
636            /* create a temporary licence file */
637            fnamewrk = xmalloc(strlen(fname) + 12);
638            for (y = 0;; y++)
639            {
640                    sprintf(fnamewrk, "%s.%lu", fname, (long unsigned int) y);
641                    fnwrkfd = open(fnamewrk, O_WRONLY | O_CREAT | O_EXCL, 0600);
642                    if (fnwrkfd == -1)
643                    {
644                            if (errno == EINTR || errno == EEXIST)
645                                    continue;
646                            perror("create");
647                            exit(1);
648                    }
649                    break;
650            }
651            /* write to the licence file */
652            for (y = 0; y < len;)
653            {
654                    do
655                    {
656                            wlen = write(fnwrkfd, s_ptr->p + y, len - y);
657                    }
658                    while (wlen == -1 && errno == EINTR);
659                    if (wlen < 1)
660                    {
661                            perror("write");
662                            unlink(fnamewrk);
663                            exit(1);
664                    }
665                    y += wlen;
666            }
667    
668            /* close the file and rename it to fname */
669            if (close(fnwrkfd) == -1)
670            {
671                    perror("close");
672                    unlink(fnamewrk);
673                    exit(1);
674            }
675            if (rename(fnamewrk, fname) == -1)
676            {
677                    perror("rename");
678                    unlink(fnamewrk);
679                    exit(1);
680            }
681            /* close the file lock on fname */
682            if (fnfd != -1)
683            {
684                    fnfl.l_type = F_UNLCK;
685                    fnfl.l_whence = SEEK_SET;
686                    fnfl.l_start = 0;
687                    fnfl.l_len = 1;
688                    fcntl(fnfd, F_SETLK, &fnfl);
689                    close(fnfd);
690            }
691    
692    }

Legend:
Removed from v.317  
changed lines
  Added in v.328

  ViewVC Help
Powered by ViewVC 1.1.26