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

Legend:
Removed from v.318  
changed lines
  Added in v.329

  ViewVC Help
Powered by ViewVC 1.1.26