/[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 328 by astrand, Tue Feb 18 13:03:51 2003 UTC revision 376 by jsorg71, Mon May 19 21:36:33 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
66    extern int rfb_port;
67    extern int defer_time;
68    void
69    rdp2vnc_connect(char *server, uint32 flags, char *domain, char *password,
70                    char *shell, char *directory);
71    #endif
72  /* Display usage information */  /* Display usage information */
73  static void  static void
74  usage(char *program)  usage(char *program)
# Line 70  usage(char *program) Line 78  usage(char *program)
78          fprintf(stderr, "See http://www.rdesktop.org/ for more information.\n\n");          fprintf(stderr, "See http://www.rdesktop.org/ for more information.\n\n");
79    
80          fprintf(stderr, "Usage: %s [options] server[:port]\n", program);          fprintf(stderr, "Usage: %s [options] server[:port]\n", program);
81    #ifdef RDP2VNC
82            fprintf(stderr, "   -V: vnc port\n");
83            fprintf(stderr, "   -E: defer time (ms)\n");
84    #endif
85          fprintf(stderr, "   -u: user name\n");          fprintf(stderr, "   -u: user name\n");
86          fprintf(stderr, "   -d: domain\n");          fprintf(stderr, "   -d: domain\n");
87          fprintf(stderr, "   -s: shell\n");          fprintf(stderr, "   -s: shell\n");
88            fprintf(stderr, "   -S: caption button size (single application mode)\n");
89          fprintf(stderr, "   -c: working directory\n");          fprintf(stderr, "   -c: working directory\n");
90          fprintf(stderr, "   -p: password (- to prompt)\n");          fprintf(stderr, "   -p: password (- to prompt)\n");
91          fprintf(stderr, "   -n: client hostname\n");          fprintf(stderr, "   -n: client hostname\n");
# Line 87  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 161  main(int argc, char *argv[])
161          domain[0] = password[0] = shell[0] = directory[0] = 0;          domain[0] = password[0] = shell[0] = directory[0] = 0;
162          strcpy(keymapname, "en-us");          strcpy(keymapname, "en-us");
163    
164          while ((c = getopt(argc, argv, "u:d:s:S:c:p:n:k:g:a:fbemCKT:Dh?")) != -1)  #ifdef RDP2VNC
165    #define VNCOPT "V:E:"
166    #else
167    #define VNCOPT
168    #endif
169    
170            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                  {                  {
174    #ifdef RDP2VNC
175                            case 'V':
176                                    rfb_port = strtol(optarg, NULL, 10);
177                                    if (rfb_port < 100)
178                                            rfb_port += 5900;
179                                    break;
180    
181                            case 'E':
182                                    defer_time = strtol(optarg, NULL, 10);
183                                    if (defer_time < 0)
184                                            defer_time = 0;
185                                    break;
186    #endif
187    
188                          case 'u':                          case 'u':
189                                  STRNCPY(username, optarg, sizeof(username));                                  STRNCPY(username, optarg, sizeof(username));
190                                  username_option = 1;                                  username_option = 1;
# Line 269  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 327  main(int argc, char *argv[]) Line 364  main(int argc, char *argv[])
364                  strncat(title, server, sizeof(title) - sizeof("rdesktop - "));                  strncat(title, server, sizeof(title) - sizeof("rdesktop - "));
365          }          }
366    
367    #ifdef RDP2VNC
368            rdp2vnc_connect(server, flags, domain, password, shell, directory);
369    #else
370    
371          if (!ui_init())          if (!ui_init())
372                  return 1;                  return 1;
373    
# Line 345  main(int argc, char *argv[]) Line 386  main(int argc, char *argv[])
386          DEBUG(("Disconnecting...\n"));          DEBUG(("Disconnecting...\n"));
387          rdp_disconnect();          rdp_disconnect();
388          ui_deinit();          ui_deinit();
389    
390    #endif
391    
392          return 0;          return 0;
393  }  }
394    
# Line 505  unimpl(char *format, ...) Line 549  unimpl(char *format, ...)
549    
550  /* produce a hex dump */  /* produce a hex dump */
551  void  void
552  hexdump(unsigned char *p, unsigned int len)  hexdump(unsigned char *p, int len)
553  {  {
554          unsigned char *line = p;          unsigned char *line = p;
555          unsigned int thisline, offset = 0;          int i, thisline, offset = 0;
         int i;  
556    
557          while (offset < len)          while (offset < len)
558          {          {
# Line 537  hexdump(unsigned char *p, unsigned int l Line 580  hexdump(unsigned char *p, unsigned int l
580  int  int
581  load_licence(unsigned char **data)  load_licence(unsigned char **data)
582  {  {
583          char *path;          char *home, *path;
         char *home;  
584          struct stat st;          struct stat st;
585          int fd;          int fd, length;
586    
587          home = getenv("HOME");          home = getenv("HOME");
588          if (home == NULL)          if (home == NULL)
589                  return -1;                  return -1;
590    
591          path = xmalloc(strlen(home) + strlen(hostname) + 20);          path = (char*)xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence."));
592          sprintf(path, "%s/.rdesktop/licence.%s", home, hostname);          sprintf(path, "%s/.rdesktop/licence.%s", home, hostname);
593    
594          fd = open(path, O_RDONLY);          fd = open(path, O_RDONLY);
# Line 556  load_licence(unsigned char **data) Line 598  load_licence(unsigned char **data)
598          if (fstat(fd, &st))          if (fstat(fd, &st))
599                  return -1;                  return -1;
600    
601          *data = xmalloc(st.st_size);          *data = (uint8*)xmalloc(st.st_size);
602          return read(fd, *data, st.st_size);          length = read(fd, *data, st.st_size);
603            close(fd);
604            xfree(path);
605            return length;
606  }  }
607    
608  void  void
609  save_licence(unsigned char *data, int length)  save_licence(unsigned char *data, int length)
610  {  {
611          char *fpath;            /* file path for licence */          char *home, *path, *tmppath;
612          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;  
         }  
613    
614          home = getenv("HOME");          home = getenv("HOME");
615          if (home == NULL)          if (home == NULL)
616                  return;                  return;
617    
618          /* 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);  
619    
620          sprintf(fpath, "%s/.rdesktop", fpath);          sprintf(path, "%s/.rdesktop", home);
621          if (mkdir(fpath, 0700) == -1 && errno != EEXIST)          if ((mkdir(path, 0700) == -1) && errno != EEXIST)
622          {          {
623                  perror("mkdir");                  perror(path);
624                  exit(1);                  return;
625          }          }
626    
627          /* 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;  
         }  
628    
629          /* close the file and rename it to fname */          sprintf(path, "%s/.rdesktop/licence.%s", home, hostname);
630          if (close(fnwrkfd) == -1)          tmppath = (char*)xmalloc(strlen(path) + sizeof(".new"));
631            strcpy(tmppath, path);
632            strcat(tmppath, ".new");
633    
634            fd = open(tmppath, O_WRONLY|O_CREAT|O_TRUNC, 0600);
635            if (fd == -1)
636          {          {
637                  perror("close");                  perror(tmppath);
638                  unlink(fnamewrk);                  return;
                 exit(1);  
639          }          }
640          if (rename(fnamewrk, fname) == -1)  
641            if (write(fd, data, length) != length)
642          {          {
643                  perror("rename");                  perror(tmppath);
644                  unlink(fnamewrk);                  unlink(tmppath);
                 exit(1);  
645          }          }
646          /* close the file lock on fname */          else if (rename(tmppath, path) == -1)
         if (fnfd != -1)  
647          {          {
648                  fnfl.l_type = F_UNLCK;                  perror(path);
649                  fnfl.l_whence = SEEK_SET;                  unlink(tmppath);
                 fnfl.l_start = 0;  
                 fnfl.l_len = 1;  
                 fcntl(fnfd, F_SETLK, &fnfl);  
                 close(fnfd);  
650          }          }
651    
652            close(fd);
653            xfree(tmppath);
654            xfree(path);
655  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.26