/[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 29 by matty, Fri Sep 14 03:38:39 2001 UTC revision 30 by matty, Fri Sep 14 13:51:38 2001 UTC
# Line 1  Line 1 
1  /*  /*
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-2000     Copyright (C) Matthew Chapman 1999-2001
5        
6     This program is free software; you can redistribute it and/or modify     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by     it under the terms of the GNU General Public License as published by
# Line 19  Line 19 
19  */  */
20    
21  #include <stdlib.h>             /* malloc realloc free */  #include <stdlib.h>             /* malloc realloc free */
22    #include <stdarg.h>             /* va_list va_start va_end */
23  #include <unistd.h>             /* read close getuid getgid getpid getppid gethostname */  #include <unistd.h>             /* read close getuid getgid getpid getppid gethostname */
24  #include <fcntl.h>              /* open */  #include <fcntl.h>              /* open */
25  #include <pwd.h>                /* getpwuid */  #include <pwd.h>                /* getpwuid */
# Line 29  Line 30 
30    
31  char username[16];  char username[16];
32  char hostname[16];  char hostname[16];
33  int width = 800;  int width;
34  int height = 600;  int height;
35  int keylayout = 0x409;  int keylayout = 0x409;
36  BOOL bitmap_compression = True;  BOOL bitmap_compression = True;
37  BOOL sendmotion = True;  BOOL sendmotion = True;
38  BOOL orders = True;  BOOL orders = True;
39  BOOL licence = True;  BOOL licence = True;
40  BOOL use_encryption = True;  BOOL encryption = True;
41  BOOL desktop_save = True;  BOOL desktop_save = True;
42  BOOL fullscreen = False;  BOOL fullscreen = False;
43    
# Line 44  BOOL fullscreen = False; Line 45  BOOL fullscreen = False;
45  static void  static void
46  usage(char *program)  usage(char *program)
47  {  {
48          STATUS("Usage: %s [options] server\n", program);          printf("Usage: %s [options] server\n", program);
49          STATUS("   -u: user name\n");          printf("   -u: user name\n");
50          STATUS("   -d: domain\n");          printf("   -d: domain\n");
51          STATUS("   -s: shell\n");          printf("   -s: shell\n");
52          STATUS("   -c: working directory\n");          printf("   -c: working directory\n");
53          STATUS("   -p: password (autologon)\n");          printf("   -p: password (autologon)\n");
54          STATUS("   -n: client hostname\n");          printf("   -n: client hostname\n");
55          STATUS("   -w: desktop width\n");          printf("   -k: keyboard layout (hex)\n");
56          STATUS("   -h: desktop height\n");          printf("   -g: desktop geometry (WxH)\n");
57          STATUS("   -k: keyboard layout (hex)\n");          printf("   -f: full-screen mode\n");
58          STATUS("   -b: force bitmap updates\n");          printf("   -b: force bitmap updates\n");
59          STATUS("   -m: do not send motion events\n");          printf("   -e: disable encryption (French TS)\n");
60          STATUS("   -l: do not request licence\n\n");          printf("   -m: do not send motion events\n");
61            printf("   -l: do not request licence\n\n");
62  }  }
63    
64  /* Client program */  /* Client program */
65  int  int
66  main(int argc, char *argv[])  main(int argc, char *argv[])
67  {  {
68          struct passwd *pw;          char fullhostname[64];
         char *server;  
         uint32 flags;  
69          char domain[16];          char domain[16];
70          char password[16];          char password[16];
71          char shell[32];          char shell[32];
72          char directory[32];          char directory[32];
73          char title[32];          char title[32];
74            struct passwd *pw;
75            char *server, *p;
76            uint32 flags;
77          int c;          int c;
78    
79          STATUS("rdesktop: A Remote Desktop Protocol client.\n");          printf("rdesktop: A Remote Desktop Protocol client.\n");
80          STATUS("Version " VERSION          printf("Version " VERSION ". Copyright (C) 1999-2001 Matt Chapman.\n");
81                 ". Copyright (C) 1999-2000 Matt Chapman.\n");          printf("See http://www.rdesktop.org/ for more information.\n\n");
         STATUS("See http://www.rdesktop.org/ for more information.\n\n");  
82    
83          flags = RDP_LOGON_NORMAL;          flags = RDP_LOGON_NORMAL;
84          domain[0] = password[0] = shell[0] = directory[0] = 0;          domain[0] = password[0] = shell[0] = directory[0] = 0;
85    
86          while ((c = getopt(argc, argv, "u:d:s:c:p:n:g:k:mbleKFVh?")) != -1)          while ((c = getopt(argc, argv, "u:d:s:c:p:n:k:g:fbemlh?")) != -1)
87          {          {
88                  switch (c)                  switch (c)
89                  {                  {
90                          case 'u':                          case 'u':
91                                  strncpy(username, optarg, sizeof(username));                                  STRNCPY(username, optarg, sizeof(username));
92                                  break;                                  break;
93    
94                          case 'd':                          case 'd':
95                                  strncpy(domain, optarg, sizeof(domain));                                  STRNCPY(domain, optarg, sizeof(domain));
                                 break;  
   
                         case 'p':  
                                 flags |= RDP_LOGON_AUTO;  
                                 strncpy(password, optarg, sizeof(password));  
96                                  break;                                  break;
97    
98                          case 's':                          case 's':
99                                  strncpy(shell, optarg, sizeof(shell));                                  STRNCPY(shell, optarg, sizeof(shell));
100                                  break;                                  break;
101    
102                          case 'c':                          case 'c':
103                                  strncpy(directory, optarg, sizeof(directory));                                  STRNCPY(directory, optarg, sizeof(directory));
104                                  break;                                  break;
105    
106                          case 'n':                          case 'p':
107                                  strncpy(hostname, optarg, sizeof(hostname));                                  STRNCPY(password, optarg, sizeof(password));
108                                    flags |= RDP_LOGON_AUTO;
109                                  break;                                  break;
110                          case 'g':  
111                                  {                          case 'n':
112                                          char *tgem = 0;                                  STRNCPY(hostname, optarg, sizeof(hostname));
                                         width = strtol(optarg, NULL, 10);  
                                         tgem = strchr(optarg, 'x');  
                                         if ((tgem == 0) || (strlen(tgem) < 2))  
                                         {  
                                                 ERROR  
                                                         ("-g: invalid parameter. Syntax example: -g 1024x768\n");  
                                                 exit(1);  
                                         }  
                                         height = strtol(tgem + 1, NULL, 10);  
                                 }  
113                                  break;                                  break;
114    
115                          case 'k':                          case 'k':
116                                  keylayout = strtol(optarg, NULL, 16);                                  keylayout = strtol(optarg, NULL, 16);
                                 /* keylayout = find_keyb_code(optarg); */  
117                                  if (keylayout == 0)                                  if (keylayout == 0)
118                                          return 0;                                  {
119                                            error("invalid keyboard layout\n");
120                                            return 1;
121                                    }
122                                  break;                                  break;
123    
124                          case 'm':                          case 'g':
125                                  sendmotion = False;                                  width = strtol(optarg, &p, 10);
126                                    if (*p == 'x')
127                                            height = strtol(p+1, NULL, 10);
128    
129                                    if ((width == 0) || (height == 0))
130                                    {
131                                            error("invalid geometry\n");
132                                            return 1;
133                                    }
134                                    break;
135    
136                            case 'f':
137                                    fullscreen = True;
138                                  break;                                  break;
139    
140                          case 'b':                          case 'b':
141                                  orders = False;                                  orders = False;
142                                  break;                                  break;
143    
144                          case 'l':                          case 'e':
145                                  licence = False;                                  encryption = False;
146                                  break;                                  break;
147    
148                          case 'e':                          case 'm':
149                                  use_encryption = False;                                  sendmotion = False;
150                                  break;                                  break;
151    
152                          case 'F':                          case 'l':
153                                  fullscreen = True;                                  licence = False;
154                                  break;                                  break;
155    
156                          case 'h':                          case 'h':
# Line 172  main(int argc, char *argv[]) Line 174  main(int argc, char *argv[])
174                  pw = getpwuid(getuid());                  pw = getpwuid(getuid());
175                  if ((pw == NULL) || (pw->pw_name == NULL))                  if ((pw == NULL) || (pw->pw_name == NULL))
176                  {                  {
177                          STATUS("Could not determine user name.\n");                          error("could not determine username, use -u\n");
178                          return 1;                          return 1;
179                  }                  }
180    
181                  strncpy(username, pw->pw_name, sizeof(username));                  STRNCPY(username, pw->pw_name, sizeof(username));
182          }          }
183    
184          if (hostname[0] == 0)          if (hostname[0] == 0)
185          {          {
186                  if (gethostname(hostname, sizeof(hostname)) == -1)                  if (gethostname(fullhostname, sizeof(fullhostname)) == -1)
187                  {                  {
188                          STATUS("Could not determine host name.\n");                          error("could not determine local hostname, use -n\n");
189                          return 1;                          return 1;
190                  }                  }
191    
192                    p = strchr(fullhostname, '.');
193                    if (p != NULL)
194                            *p = 0;
195    
196                    STRNCPY(hostname, fullhostname, sizeof(hostname));
197            }
198    
199            if (!strcmp(password, "-"))
200            {
201                    p = getpass("Password: ");
202                    if (p == NULL)
203                    {
204                            error("failed to read password\n");
205                            return 0;
206                    }
207                    STRNCPY(password, p, sizeof(password));
208            }
209    
210            if ((width == 0) || (height == 0))
211            {
212                    width = 800;
213                    height = 600;
214          }          }
215    
216          strcpy(title, "rdesktop - ");          strcpy(title, "rdesktop - ");
217          strncat(title, server, sizeof(title));          strncat(title, server, sizeof(title) - sizeof("rdesktop - "));
218    
219          if (ui_create_window(title))          if (ui_create_window(title))
220          {          {
# Line 197  main(int argc, char *argv[]) Line 222  main(int argc, char *argv[])
222                                   directory))                                   directory))
223                          return 1;                          return 1;
224    
225                  STATUS("Connection successful.\n");                  printf("Connection successful.\n");
226                  rdp_main_loop();                  rdp_main_loop();
227                  ui_destroy_window();                  ui_destroy_window();
228          }          }
# Line 216  generate_random(uint8 *random) Line 241  generate_random(uint8 *random)
241          int fd;          int fd;
242    
243          /* If we have a kernel random device, use it. */          /* If we have a kernel random device, use it. */
244          if ((fd = open("/dev/urandom", O_RDONLY)) != -1)          if (((fd = open("/dev/urandom", O_RDONLY)) != -1)
245                || ((fd = open("/dev/random", O_RDONLY)) != -1))
246          {          {
247                  read(fd, random, 32);                  read(fd, random, 32);
248                  close(fd);                  close(fd);
# Line 241  xmalloc(int size) Line 267  xmalloc(int size)
267          void *mem = malloc(size);          void *mem = malloc(size);
268          if (mem == NULL)          if (mem == NULL)
269          {          {
270                  ERROR("xmalloc %d\n", size);                  error("xmalloc %d\n", size);
271                  exit(1);                  exit(1);
272          }          }
273          return mem;          return mem;
# Line 254  xrealloc(void *oldmem, int size) Line 280  xrealloc(void *oldmem, int size)
280          void *mem = realloc(oldmem, size);          void *mem = realloc(oldmem, size);
281          if (mem == NULL)          if (mem == NULL)
282          {          {
283                  ERROR("xrealloc %d\n", size);                  error("xrealloc %d\n", size);
284                  exit(1);                  exit(1);
285          }          }
286          return mem;          return mem;
# Line 267  xfree(void *mem) Line 293  xfree(void *mem)
293          free(mem);          free(mem);
294  }  }
295    
296  /* Produce a hex dump */  /* report an error */
297    void
298    error(char *format, ...)
299    {
300            va_list ap;
301    
302            fprintf(stderr, "ERROR: ");
303    
304            va_start(ap, format);
305            vfprintf(stderr, format, ap);
306            va_end(ap);
307    }
308    
309    /* report an unimplemented protocol feature */
310    void
311    unimpl(char *format, ...)
312    {
313            va_list ap;
314    
315            fprintf(stderr, "NOT IMPLEMENTED: ");
316    
317            va_start(ap, format);
318            vfprintf(stderr, format, ap);
319            va_end(ap);
320    }
321    
322    /* produce a hex dump */
323  void  void
324  hexdump(unsigned char *p, unsigned int len)  hexdump(unsigned char *p, unsigned int len)
325  {  {
# Line 277  hexdump(unsigned char *p, unsigned int l Line 329  hexdump(unsigned char *p, unsigned int l
329    
330          while (offset < len)          while (offset < len)
331          {          {
332                  STATUS("%04x ", offset);                  printf("%04x ", offset);
333                  thisline = len - offset;                  thisline = len - offset;
334                  if (thisline > 16)                  if (thisline > 16)
335                          thisline = 16;                          thisline = 16;
336    
337                  for (i = 0; i < thisline; i++)                  for (i = 0; i < thisline; i++)
338                          STATUS("%02x ", line[i]) for (; i < 16; i++)                          printf("%02x ", line[i]);
339                                  STATUS("   ");  
340                    for (; i < 16; i++)
341                                    printf("   ");
342    
343                  for (i = 0; i < thisline; i++)                  for (i = 0; i < thisline; i++)
344                          STATUS("%c",                          printf("%c",
345                                 (line[i] >= 0x20                                 (line[i] >= 0x20
346                                  && line[i] < 0x7f) ? line[i] : '.');                                  && line[i] < 0x7f) ? line[i] : '.');
347    
348                  STATUS("\n");                  printf("\n");
349                  offset += thisline;                  offset += thisline;
350                  line += thisline;                  line += thisline;
351          }          }

Legend:
Removed from v.29  
changed lines
  Added in v.30

  ViewVC Help
Powered by ViewVC 1.1.26