/[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

Contents of /sourceforge.net/trunk/rdesktop/rdesktop.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 33 - (show annotations)
Sat Sep 15 12:34:34 2001 UTC (22 years, 8 months ago) by matty
File MIME type: text/plain
File size: 7182 byte(s)
Add a ui_select to xwin.c to reduce latency.
Remove extraneous error messages - only report at lowest level.
Endianness and IRIX compile fixes.

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

  ViewVC Help
Powered by ViewVC 1.1.26