/[rdesktop]/sourceforge.net/branches/seamlessrdp-branch/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

Annotation of /sourceforge.net/branches/seamlessrdp-branch/rdesktop/rdesktop.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 38 - (hide annotations)
Thu Apr 4 12:04:33 2002 UTC (22 years, 1 month ago) by matthewc
Original Path: sourceforge.net/trunk/rdesktop/rdesktop.c
File MIME type: text/plain
File size: 7136 byte(s)
Committing my keymap work - unlike the version in the unified patches,
this one uses external keymap files (which are my preference).

1 matty 10 /*
2     rdesktop: A Remote Desktop Protocol client.
3     Entrypoint and utility functions
4 matty 30 Copyright (C) Matthew Chapman 1999-2001
5 matty 10
6     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
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10    
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     GNU General Public License for more details.
15    
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19     */
20    
21 matty 24 #include <stdlib.h> /* malloc realloc free */
22 matty 30 #include <stdarg.h> /* va_list va_start va_end */
23 matty 24 #include <unistd.h> /* read close getuid getgid getpid getppid gethostname */
24     #include <fcntl.h> /* open */
25     #include <pwd.h> /* getpwuid */
26     #include <sys/stat.h> /* stat */
27     #include <sys/time.h> /* gettimeofday */
28     #include <sys/times.h> /* times */
29 matty 10 #include "rdesktop.h"
30    
31     char username[16];
32     char hostname[16];
33 matthewc 38 char keymapname[16];
34     int keylayout;
35 matty 30 int width;
36     int height;
37 matty 28 BOOL bitmap_compression = True;
38 matty 29 BOOL sendmotion = True;
39 matty 10 BOOL orders = True;
40     BOOL licence = True;
41 matty 30 BOOL encryption = True;
42 matty 28 BOOL desktop_save = True;
43     BOOL fullscreen = False;
44 matty 10
45     /* Display usage information */
46 matty 25 static void
47     usage(char *program)
48 matty 10 {
49 matty 30 printf("Usage: %s [options] server\n", program);
50     printf(" -u: user name\n");
51     printf(" -d: domain\n");
52     printf(" -s: shell\n");
53     printf(" -c: working directory\n");
54     printf(" -p: password (autologon)\n");
55     printf(" -n: client hostname\n");
56 matthewc 38 printf(" -k: keyboard layout\n");
57 matty 30 printf(" -g: desktop geometry (WxH)\n");
58     printf(" -f: full-screen mode\n");
59     printf(" -b: force bitmap updates\n");
60     printf(" -e: disable encryption (French TS)\n");
61     printf(" -m: do not send motion events\n");
62     printf(" -l: do not request licence\n\n");
63 matty 10 }
64    
65     /* Client program */
66 matty 25 int
67     main(int argc, char *argv[])
68 matty 10 {
69 matty 30 char fullhostname[64];
70 matty 21 char domain[16];
71     char password[16];
72     char shell[32];
73     char directory[32];
74 matty 10 char title[32];
75 matty 30 struct passwd *pw;
76     char *server, *p;
77     uint32 flags;
78 matty 10 int c;
79    
80 matty 30 printf("rdesktop: A Remote Desktop Protocol client.\n");
81     printf("Version " VERSION ". Copyright (C) 1999-2001 Matt Chapman.\n");
82     printf("See http://www.rdesktop.org/ for more information.\n\n");
83 matty 10
84 matty 21 flags = RDP_LOGON_NORMAL;
85     domain[0] = password[0] = shell[0] = directory[0] = 0;
86 matthewc 38 strcpy(keymapname, "us");
87 matty 21
88 matty 30 while ((c = getopt(argc, argv, "u:d:s:c:p:n:k:g:fbemlh?")) != -1)
89 matty 10 {
90     switch (c)
91     {
92     case 'u':
93 matty 30 STRNCPY(username, optarg, sizeof(username));
94 matty 10 break;
95    
96 matty 21 case 'd':
97 matty 30 STRNCPY(domain, optarg, sizeof(domain));
98 matty 21 break;
99    
100     case 's':
101 matty 30 STRNCPY(shell, optarg, sizeof(shell));
102 matty 21 break;
103    
104     case 'c':
105 matty 30 STRNCPY(directory, optarg, sizeof(directory));
106 matty 21 break;
107    
108 matty 30 case 'p':
109     STRNCPY(password, optarg, sizeof(password));
110     flags |= RDP_LOGON_AUTO;
111     break;
112    
113 matty 10 case 'n':
114 matty 30 STRNCPY(hostname, optarg, sizeof(hostname));
115 matty 10 break;
116    
117     case 'k':
118 matthewc 38 STRNCPY(keymapname, optarg, sizeof(keymapname));
119 matty 10 break;
120    
121 matty 30 case 'g':
122     width = strtol(optarg, &p, 10);
123     if (*p == 'x')
124     height = strtol(p+1, NULL, 10);
125    
126     if ((width == 0) || (height == 0))
127     {
128     error("invalid geometry\n");
129     return 1;
130     }
131 matty 10 break;
132    
133 matty 30 case 'f':
134     fullscreen = True;
135     break;
136    
137 matty 10 case 'b':
138     orders = False;
139     break;
140    
141 matty 30 case 'e':
142     encryption = False;
143 matty 10 break;
144    
145 matty 30 case 'm':
146     sendmotion = False;
147 matty 28 break;
148 matty 29
149 matty 30 case 'l':
150     licence = False;
151 matty 28 break;
152 matty 29
153 matty 28 case 'h':
154 matty 10 case '?':
155     default:
156     usage(argv[0]);
157     return 1;
158     }
159     }
160    
161     if (argc - optind < 1)
162     {
163     usage(argv[0]);
164     return 1;
165     }
166    
167     server = argv[optind];
168    
169     if (username[0] == 0)
170     {
171     pw = getpwuid(getuid());
172     if ((pw == NULL) || (pw->pw_name == NULL))
173     {
174 matty 30 error("could not determine username, use -u\n");
175 matty 10 return 1;
176     }
177    
178 matty 30 STRNCPY(username, pw->pw_name, sizeof(username));
179 matty 10 }
180    
181     if (hostname[0] == 0)
182     {
183 matty 30 if (gethostname(fullhostname, sizeof(fullhostname)) == -1)
184 matty 10 {
185 matty 30 error("could not determine local hostname, use -n\n");
186 matty 10 return 1;
187     }
188 matty 30
189     p = strchr(fullhostname, '.');
190     if (p != NULL)
191     *p = 0;
192    
193     STRNCPY(hostname, fullhostname, sizeof(hostname));
194 matty 10 }
195    
196 matty 30 if (!strcmp(password, "-"))
197     {
198     p = getpass("Password: ");
199     if (p == NULL)
200     {
201     error("failed to read password\n");
202     return 0;
203     }
204     STRNCPY(password, p, sizeof(password));
205     }
206    
207     if ((width == 0) || (height == 0))
208     {
209     width = 800;
210     height = 600;
211     }
212    
213 matty 12 strcpy(title, "rdesktop - ");
214 matty 30 strncat(title, server, sizeof(title) - sizeof("rdesktop - "));
215 matty 12
216 matty 10 if (ui_create_window(title))
217     {
218 matty 28 if (!rdp_connect(server, flags, domain, password, shell,
219     directory))
220     return 1;
221    
222 matty 30 printf("Connection successful.\n");
223 matty 10 rdp_main_loop();
224 matty 33 printf("Disconnecting...\n");
225 matty 10 ui_destroy_window();
226 matthewc 38 rdp_disconnect();
227 matty 10 }
228    
229     return 0;
230     }
231    
232     /* Generate a 32-byte random for the secure transport code. */
233 matty 25 void
234     generate_random(uint8 *random)
235 matty 10 {
236     struct stat st;
237 matty 22 struct tms tmsbuf;
238 matty 24 uint32 *r = (uint32 *) random;
239 matty 10 int fd;
240    
241     /* If we have a kernel random device, use it. */
242 matty 30 if (((fd = open("/dev/urandom", O_RDONLY)) != -1)
243     || ((fd = open("/dev/random", O_RDONLY)) != -1))
244 matty 10 {
245     read(fd, random, 32);
246     close(fd);
247     return;
248     }
249    
250     /* Otherwise use whatever entropy we can gather - ideas welcome. */
251     r[0] = (getpid()) | (getppid() << 16);
252     r[1] = (getuid()) | (getgid() << 16);
253 matty 24 r[2] = times(&tmsbuf); /* system uptime (clocks) */
254     gettimeofday((struct timeval *) &r[3], NULL); /* sec and usec */
255 matty 10 stat("/tmp", &st);
256     r[5] = st.st_atime;
257     r[6] = st.st_mtime;
258     r[7] = st.st_ctime;
259     }
260    
261     /* malloc; exit if out of memory */
262 matty 25 void *
263     xmalloc(int size)
264 matty 10 {
265     void *mem = malloc(size);
266     if (mem == NULL)
267     {
268 matty 30 error("xmalloc %d\n", size);
269 matty 10 exit(1);
270     }
271     return mem;
272     }
273    
274     /* realloc; exit if out of memory */
275 matty 25 void *
276     xrealloc(void *oldmem, int size)
277 matty 10 {
278     void *mem = realloc(oldmem, size);
279     if (mem == NULL)
280     {
281 matty 30 error("xrealloc %d\n", size);
282 matty 10 exit(1);
283     }
284     return mem;
285     }
286    
287     /* free */
288 matty 25 void
289     xfree(void *mem)
290 matty 10 {
291     free(mem);
292     }
293    
294 matty 30 /* report an error */
295 matty 25 void
296 matty 30 error(char *format, ...)
297     {
298     va_list ap;
299    
300     fprintf(stderr, "ERROR: ");
301    
302     va_start(ap, format);
303     vfprintf(stderr, format, ap);
304     va_end(ap);
305     }
306    
307     /* report an unimplemented protocol feature */
308     void
309     unimpl(char *format, ...)
310     {
311     va_list ap;
312    
313     fprintf(stderr, "NOT IMPLEMENTED: ");
314    
315     va_start(ap, format);
316     vfprintf(stderr, format, ap);
317     va_end(ap);
318     }
319    
320     /* produce a hex dump */
321     void
322 matty 25 hexdump(unsigned char *p, unsigned int len)
323 matty 10 {
324     unsigned char *line = p;
325     unsigned int thisline, offset = 0;
326     int i;
327    
328     while (offset < len)
329     {
330 matty 30 printf("%04x ", offset);
331 matty 10 thisline = len - offset;
332     if (thisline > 16)
333     thisline = 16;
334    
335     for (i = 0; i < thisline; i++)
336 matty 30 printf("%02x ", line[i]);
337 matty 10
338 matty 30 for (; i < 16; i++)
339     printf(" ");
340    
341 matty 10 for (i = 0; i < thisline; i++)
342 matty 30 printf("%c",
343 matty 24 (line[i] >= 0x20
344     && line[i] < 0x7f) ? line[i] : '.');
345 matty 10
346 matty 30 printf("\n");
347 matty 10 offset += thisline;
348     line += thisline;
349     }
350     }

  ViewVC Help
Powered by ViewVC 1.1.26