/[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 17 by matty, Thu Sep 28 15:54:11 2000 UTC revision 25 by matty, Sat Jan 6 03:47:04 2001 UTC
# Line 18  Line 18 
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */  */
20    
21  #include <stdlib.h>     /* malloc realloc free */  #include <stdlib.h>             /* malloc realloc free */
22  #include <unistd.h>     /* read close getuid getgid getpid getppid gethostname */  #include <unistd.h>             /* read close getuid getgid getpid getppid gethostname */
23  #include <fcntl.h>      /* open */  #include <fcntl.h>              /* open */
24  #include <pwd.h>        /* getpwuid */  #include <pwd.h>                /* getpwuid */
25  #include <sys/stat.h>   /* stat */  #include <sys/stat.h>           /* stat */
26  #include <sys/time.h>   /* gettimeofday */  #include <sys/time.h>           /* gettimeofday */
27  #include <sys/times.h>  /* times */  #include <sys/times.h>          /* times */
28  #include "rdesktop.h"  #include "rdesktop.h"
29    
30  char username[16];  char username[16];
# Line 32  char hostname[16]; Line 32  char hostname[16];
32  int width = 800;  int width = 800;
33  int height = 600;  int height = 600;
34  int keylayout = 0x409;  int keylayout = 0x409;
35  BOOL motion = False;  BOOL motion = True;
36  BOOL orders = True;  BOOL orders = True;
37  BOOL licence = True;  BOOL licence = True;
38    
39  /* Display usage information */  /* Display usage information */
40  static void usage(char *program)  static void
41    usage(char *program)
42  {  {
43          STATUS("Usage: %s [options] server\n", program);          STATUS("Usage: %s [options] server\n", program);
44          STATUS("   -u: user name\n");          STATUS("   -u: user name\n");
45            STATUS("   -d: domain\n");
46            STATUS("   -s: shell\n");
47            STATUS("   -c: working directory\n");
48            STATUS("   -p: password (autologon)\n");
49          STATUS("   -n: client hostname\n");          STATUS("   -n: client hostname\n");
50          STATUS("   -w: desktop width\n");          STATUS("   -w: desktop width\n");
51          STATUS("   -h: desktop height\n");          STATUS("   -h: desktop height\n");
52          STATUS("   -k: keyboard layout (hex)\n");          STATUS("   -k: keyboard layout (hex)\n");
         STATUS("   -m: send motion events\n");  
53          STATUS("   -b: force bitmap updates\n");          STATUS("   -b: force bitmap updates\n");
54            STATUS("   -m: do not send motion events\n");
55          STATUS("   -l: do not request licence\n\n");          STATUS("   -l: do not request licence\n\n");
56  }  }
57    
58  /* Client program */  /* Client program */
59  int main(int argc, char *argv[])  int
60    main(int argc, char *argv[])
61  {  {
62          struct passwd *pw;          struct passwd *pw;
63          char *server;          char *server;
64            uint32 flags;
65            char domain[16];
66            char password[16];
67            char shell[32];
68            char directory[32];
69          char title[32];          char title[32];
70          int c;          int c;
71    
72          STATUS("rdesktop: A Remote Desktop Protocol client.\n");          STATUS("rdesktop: A Remote Desktop Protocol client.\n");
73          STATUS("Version "VERSION". Copyright (C) 1999-2000 Matt Chapman.\n");          STATUS("Version " VERSION
74                   ". Copyright (C) 1999-2000 Matt Chapman.\n");
75          STATUS("See http://www.rdesktop.org/ for more information.\n\n");          STATUS("See http://www.rdesktop.org/ for more information.\n\n");
76    
77          while ((c = getopt(argc, argv, "u:n:w:h:k:mbl?")) != -1)          flags = RDP_LOGON_NORMAL;
78            domain[0] = password[0] = shell[0] = directory[0] = 0;
79    
80            while ((c = getopt(argc, argv, "u:d:s:c:p:n:w:h:k:bml?")) != -1)
81          {          {
82                  switch (c)                  switch (c)
83                  {                  {
# Line 70  int main(int argc, char *argv[]) Line 85  int main(int argc, char *argv[])
85                                  strncpy(username, optarg, sizeof(username));                                  strncpy(username, optarg, sizeof(username));
86                                  break;                                  break;
87    
88                            case 'd':
89                                    strncpy(domain, optarg, sizeof(domain));
90                                    break;
91    
92                            case 'p':
93                                    flags |= RDP_LOGON_AUTO;
94                                    strncpy(password, optarg, sizeof(password));
95                                    break;
96    
97                            case 's':
98                                    strncpy(shell, optarg, sizeof(shell));
99                                    break;
100    
101                            case 'c':
102                                    strncpy(directory, optarg, sizeof(directory));
103                                    break;
104    
105                          case 'n':                          case 'n':
106                                  strncpy(hostname, optarg, sizeof(hostname));                                  strncpy(hostname, optarg, sizeof(hostname));
107                                  break;                                  break;
# Line 87  int main(int argc, char *argv[]) Line 119  int main(int argc, char *argv[])
119                                  break;                                  break;
120    
121                          case 'm':                          case 'm':
122                                  motion = True;                                  motion = False;
123                                  break;                                  break;
124    
125                          case 'b':                          case 'b':
# Line 134  int main(int argc, char *argv[]) Line 166  int main(int argc, char *argv[])
166                  }                  }
167          }          }
168    
169          if (!rdp_connect(server))          if (!rdp_connect(server, flags, domain, password, shell, directory))
170                  return 1;                  return 1;
171    
172          STATUS("Connection successful.\n");          STATUS("Connection successful.\n");
# Line 153  int main(int argc, char *argv[]) Line 185  int main(int argc, char *argv[])
185  }  }
186    
187  /* Generate a 32-byte random for the secure transport code. */  /* Generate a 32-byte random for the secure transport code. */
188  void generate_random(uint8 *random)  void
189    generate_random(uint8 *random)
190  {  {
191          struct stat st;          struct stat st;
192          uint32 *r = (uint32 *)random;          struct tms tmsbuf;
193            uint32 *r = (uint32 *) random;
194          int fd;          int fd;
195    
196          /* If we have a kernel random device, use it. */          /* If we have a kernel random device, use it. */
# Line 170  void generate_random(uint8 *random) Line 204  void generate_random(uint8 *random)
204          /* Otherwise use whatever entropy we can gather - ideas welcome. */          /* Otherwise use whatever entropy we can gather - ideas welcome. */
205          r[0] = (getpid()) | (getppid() << 16);          r[0] = (getpid()) | (getppid() << 16);
206          r[1] = (getuid()) | (getgid() << 16);          r[1] = (getuid()) | (getgid() << 16);
207          r[2] = times(NULL); /* system uptime (clocks) */          r[2] = times(&tmsbuf);  /* system uptime (clocks) */
208          gettimeofday((struct timeval *)&r[3], NULL); /* sec and usec */          gettimeofday((struct timeval *) &r[3], NULL);   /* sec and usec */
209          stat("/tmp", &st);          stat("/tmp", &st);
210          r[5] = st.st_atime;          r[5] = st.st_atime;
211          r[6] = st.st_mtime;          r[6] = st.st_mtime;
# Line 179  void generate_random(uint8 *random) Line 213  void generate_random(uint8 *random)
213  }  }
214    
215  /* malloc; exit if out of memory */  /* malloc; exit if out of memory */
216  void *xmalloc(int size)  void *
217    xmalloc(int size)
218  {  {
219          void *mem = malloc(size);          void *mem = malloc(size);
220          if (mem == NULL)          if (mem == NULL)
# Line 191  void *xmalloc(int size) Line 226  void *xmalloc(int size)
226  }  }
227    
228  /* realloc; exit if out of memory */  /* realloc; exit if out of memory */
229  void *xrealloc(void *oldmem, int size)  void *
230    xrealloc(void *oldmem, int size)
231  {  {
232          void *mem = realloc(oldmem, size);          void *mem = realloc(oldmem, size);
233          if (mem == NULL)          if (mem == NULL)
# Line 203  void *xrealloc(void *oldmem, int size) Line 239  void *xrealloc(void *oldmem, int size)
239  }  }
240    
241  /* free */  /* free */
242  void xfree(void *mem)  void
243    xfree(void *mem)
244  {  {
245          free(mem);          free(mem);
246  }  }
247    
248  /* Produce a hex dump */  /* Produce a hex dump */
249  void hexdump(unsigned char *p, unsigned int len)  void
250    hexdump(unsigned char *p, unsigned int len)
251  {  {
252          unsigned char *line = p;          unsigned char *line = p;
253          unsigned int thisline, offset = 0;          unsigned int thisline, offset = 0;
# Line 223  void hexdump(unsigned char *p, unsigned Line 261  void hexdump(unsigned char *p, unsigned
261                          thisline = 16;                          thisline = 16;
262    
263                  for (i = 0; i < thisline; i++)                  for (i = 0; i < thisline; i++)
264                          STATUS("%02x ", line[i])                          STATUS("%02x ", line[i]) for (; i < 16; i++)
265                                    STATUS("   ");
                 for (; i < 16; i++)  
                         STATUS("   ");  
266    
267                  for (i = 0; i < thisline; i++)                  for (i = 0; i < thisline; i++)
268                          STATUS("%c", (line[i] >= 0x20 && line[i] < 0x7f) ? line[i] : '.');                          STATUS("%c",
269                                   (line[i] >= 0x20
270                                    && line[i] < 0x7f) ? line[i] : '.');
271    
272                  STATUS("\n");                  STATUS("\n");
273                  offset += thisline;                  offset += thisline;

Legend:
Removed from v.17  
changed lines
  Added in v.25

  ViewVC Help
Powered by ViewVC 1.1.26