40 |
#include "crypto/md5.h" |
#include "crypto/md5.h" |
41 |
#endif |
#endif |
42 |
|
|
43 |
char title[32] = ""; |
char g_title[64] = ""; |
44 |
char username[16]; |
char g_username[64]; |
45 |
char hostname[16]; |
char hostname[16]; |
46 |
char keymapname[16]; |
char keymapname[16]; |
47 |
int keylayout = 0x409; /* Defaults to US keyboard layout */ |
int keylayout = 0x409; /* Defaults to US keyboard layout */ |
48 |
int width = 800; /* If width or height are reset to zero, the geometry will |
|
49 |
be fetched from _NET_WORKAREA */ |
int g_width = 800; /* width is special: If 0, the |
50 |
int height = 600; |
geometry will be fetched from |
51 |
|
_NET_WORKAREA. If negative, |
52 |
|
absolute value specifies the |
53 |
|
percent of the whole screen. */ |
54 |
|
int g_height = 600; |
55 |
int tcp_port_rdp = TCP_PORT_RDP; |
int tcp_port_rdp = TCP_PORT_RDP; |
56 |
int server_bpp = 8; |
int g_server_bpp = 8; |
57 |
int win_button_size = 0; /* If zero, disable single app mode */ |
int g_win_button_size = 0; /* If zero, disable single app mode */ |
58 |
BOOL bitmap_compression = True; |
BOOL g_bitmap_compression = True; |
59 |
BOOL sendmotion = True; |
BOOL g_sendmotion = True; |
60 |
BOOL orders = True; |
BOOL g_orders = True; |
61 |
BOOL encryption = True; |
BOOL g_encryption = True; |
62 |
BOOL desktop_save = True; |
BOOL packet_encryption = True; |
63 |
BOOL fullscreen = False; |
BOOL g_desktop_save = True; |
64 |
BOOL grab_keyboard = True; |
BOOL g_fullscreen = False; |
65 |
BOOL hide_decorations = False; |
BOOL g_grab_keyboard = True; |
66 |
BOOL use_rdp5 = False; |
BOOL g_hide_decorations = False; |
67 |
extern BOOL owncolmap; |
BOOL g_use_rdp5 = True; |
68 |
|
BOOL g_console_session = False; |
69 |
|
extern BOOL g_owncolmap; |
70 |
|
|
71 |
|
#ifdef WITH_RDPSND |
72 |
|
BOOL g_rdpsnd = True; |
73 |
|
#endif |
74 |
|
|
75 |
#ifdef RDP2VNC |
#ifdef RDP2VNC |
76 |
extern int rfb_port; |
extern int rfb_port; |
90 |
fprintf(stderr, "Usage: %s [options] server[:port]\n", program); |
fprintf(stderr, "Usage: %s [options] server[:port]\n", program); |
91 |
#ifdef RDP2VNC |
#ifdef RDP2VNC |
92 |
fprintf(stderr, " -V: vnc port\n"); |
fprintf(stderr, " -V: vnc port\n"); |
93 |
fprintf(stderr, " -E: defer time (ms)\n"); |
fprintf(stderr, " -Q: defer time (ms)\n"); |
94 |
#endif |
#endif |
95 |
fprintf(stderr, " -u: user name\n"); |
fprintf(stderr, " -u: user name\n"); |
96 |
fprintf(stderr, " -d: domain\n"); |
fprintf(stderr, " -d: domain\n"); |
104 |
fprintf(stderr, " -f: full-screen mode\n"); |
fprintf(stderr, " -f: full-screen mode\n"); |
105 |
fprintf(stderr, " -b: force bitmap updates\n"); |
fprintf(stderr, " -b: force bitmap updates\n"); |
106 |
fprintf(stderr, " -e: disable encryption (French TS)\n"); |
fprintf(stderr, " -e: disable encryption (French TS)\n"); |
107 |
|
fprintf(stderr, " -E: disable encryption from client to server\n"); |
108 |
fprintf(stderr, " -m: do not send motion events\n"); |
fprintf(stderr, " -m: do not send motion events\n"); |
109 |
fprintf(stderr, " -C: use private colour map\n"); |
fprintf(stderr, " -C: use private colour map\n"); |
110 |
fprintf(stderr, " -K: keep window manager key bindings\n"); |
fprintf(stderr, " -K: keep window manager key bindings\n"); |
111 |
fprintf(stderr, " -T: window title\n"); |
fprintf(stderr, " -T: window title\n"); |
112 |
fprintf(stderr, " -D: hide window manager decorations\n"); |
fprintf(stderr, " -D: hide window manager decorations\n"); |
113 |
|
#ifdef WITH_RDPSND |
114 |
|
fprintf(stderr, " -A: disable audio-redirection\n"); |
115 |
|
#endif |
116 |
fprintf(stderr, " -a: server bpp\n"); |
fprintf(stderr, " -a: server bpp\n"); |
117 |
fprintf(stderr, " -5: Use RDP5 (EXPERIMENTAL!)\n"); |
fprintf(stderr, " -0: attach to console\n"); |
118 |
|
fprintf(stderr, " -4: use RDP version 4\n"); |
119 |
|
fprintf(stderr, " -5: use RDP version 5 (default)\n"); |
120 |
} |
} |
121 |
|
|
122 |
static BOOL |
static BOOL |
155 |
return ret; |
return ret; |
156 |
} |
} |
157 |
|
|
158 |
|
static void |
159 |
|
parse_server_and_port(char *server) |
160 |
|
{ |
161 |
|
char *p; |
162 |
|
#ifdef IPv6 |
163 |
|
int addr_colons; |
164 |
|
#endif |
165 |
|
|
166 |
|
#ifdef IPv6 |
167 |
|
p = server; |
168 |
|
addr_colons = 0; |
169 |
|
while (*p) |
170 |
|
if (*p++ == ':') |
171 |
|
addr_colons++; |
172 |
|
if (addr_colons >= 2) |
173 |
|
{ |
174 |
|
/* numeric IPv6 style address format - [1:2:3::4]:port */ |
175 |
|
p = strchr(server, ']'); |
176 |
|
if (*server == '[' && p != NULL) |
177 |
|
{ |
178 |
|
if (*(p + 1) == ':' && *(p + 2) != '\0') |
179 |
|
tcp_port_rdp = strtol(p + 2, NULL, 10); |
180 |
|
/* remove the port number and brackets from the address */ |
181 |
|
*p = '\0'; |
182 |
|
strncpy(server, server + 1, strlen(server)); |
183 |
|
} |
184 |
|
} |
185 |
|
else |
186 |
|
{ |
187 |
|
/* dns name or IPv4 style address format - server.example.com:port or 1.2.3.4:port */ |
188 |
|
p = strchr(server, ':'); |
189 |
|
if (p != NULL) |
190 |
|
{ |
191 |
|
tcp_port_rdp = strtol(p + 1, NULL, 10); |
192 |
|
*p = 0; |
193 |
|
} |
194 |
|
} |
195 |
|
#else /* no IPv6 support */ |
196 |
|
p = strchr(server, ':'); |
197 |
|
if (p != NULL) |
198 |
|
{ |
199 |
|
tcp_port_rdp = strtol(p + 1, NULL, 10); |
200 |
|
*p = 0; |
201 |
|
} |
202 |
|
#endif /* IPv6 */ |
203 |
|
|
204 |
|
} |
205 |
|
|
206 |
/* Client program */ |
/* Client program */ |
207 |
int |
int |
208 |
main(int argc, char *argv[]) |
main(int argc, char *argv[]) |
210 |
char server[64]; |
char server[64]; |
211 |
char fullhostname[64]; |
char fullhostname[64]; |
212 |
char domain[16]; |
char domain[16]; |
213 |
char password[16]; |
char password[64]; |
214 |
char shell[128]; |
char shell[128]; |
215 |
char directory[32]; |
char directory[32]; |
216 |
BOOL prompt_password; |
BOOL prompt_password, rdp_retval = False; |
217 |
struct passwd *pw; |
struct passwd *pw; |
218 |
uint32 flags; |
uint32 flags; |
219 |
char *p; |
char *p; |
226 |
strcpy(keymapname, "en-us"); |
strcpy(keymapname, "en-us"); |
227 |
|
|
228 |
#ifdef RDP2VNC |
#ifdef RDP2VNC |
229 |
#define VNCOPT "V:E:" |
#define VNCOPT "V:Q:" |
230 |
#else |
#else |
231 |
#define VNCOPT |
#define VNCOPT |
232 |
#endif |
#endif |
233 |
|
|
234 |
while ((c = getopt(argc, argv, VNCOPT "u:d:s:S:c:p:n:k:g:a:fbemCKT:Dh?54")) != -1) |
while ((c = getopt(argc, argv, VNCOPT "u:d:s:S:c:p:n:k:g:a:fbeEmCKT:AD045h?")) != -1) |
235 |
{ |
{ |
236 |
switch (c) |
switch (c) |
237 |
{ |
{ |
242 |
rfb_port += 5900; |
rfb_port += 5900; |
243 |
break; |
break; |
244 |
|
|
245 |
case 'E': |
case 'Q': |
246 |
defer_time = strtol(optarg, NULL, 10); |
defer_time = strtol(optarg, NULL, 10); |
247 |
if (defer_time < 0) |
if (defer_time < 0) |
248 |
defer_time = 0; |
defer_time = 0; |
250 |
#endif |
#endif |
251 |
|
|
252 |
case 'u': |
case 'u': |
253 |
STRNCPY(username, optarg, sizeof(username)); |
STRNCPY(g_username, optarg, sizeof(g_username)); |
254 |
username_option = 1; |
username_option = 1; |
255 |
break; |
break; |
256 |
|
|
265 |
case 'S': |
case 'S': |
266 |
if (!strcmp(optarg, "standard")) |
if (!strcmp(optarg, "standard")) |
267 |
{ |
{ |
268 |
win_button_size = 18; |
g_win_button_size = 18; |
269 |
break; |
break; |
270 |
} |
} |
271 |
|
|
272 |
win_button_size = strtol(optarg, &p, 10); |
g_win_button_size = strtol(optarg, &p, 10); |
273 |
|
|
274 |
if (*p) |
if (*p) |
275 |
{ |
{ |
310 |
case 'g': |
case 'g': |
311 |
if (!strcmp(optarg, "workarea")) |
if (!strcmp(optarg, "workarea")) |
312 |
{ |
{ |
313 |
width = height = 0; |
g_width = g_height = 0; |
314 |
break; |
break; |
315 |
} |
} |
316 |
|
|
317 |
width = strtol(optarg, &p, 10); |
g_width = strtol(optarg, &p, 10); |
318 |
|
if (g_width <= 0) |
319 |
|
{ |
320 |
|
error("invalid geometry\n"); |
321 |
|
return 1; |
322 |
|
} |
323 |
|
|
324 |
if (*p == 'x') |
if (*p == 'x') |
325 |
height = strtol(p + 1, NULL, 10); |
g_height = strtol(p + 1, NULL, 10); |
326 |
|
|
327 |
if ((width == 0) || (height == 0)) |
if (g_height <= 0) |
328 |
{ |
{ |
329 |
error("invalid geometry\n"); |
error("invalid geometry\n"); |
330 |
return 1; |
return 1; |
331 |
} |
} |
332 |
|
|
333 |
|
if (*p == '%') |
334 |
|
g_width = -g_width; |
335 |
|
|
336 |
break; |
break; |
337 |
|
|
338 |
case 'f': |
case 'f': |
339 |
fullscreen = True; |
g_fullscreen = True; |
340 |
break; |
break; |
341 |
|
|
342 |
case 'b': |
case 'b': |
343 |
orders = False; |
g_orders = False; |
344 |
break; |
break; |
345 |
|
|
346 |
case 'e': |
case 'e': |
347 |
encryption = False; |
g_encryption = False; |
348 |
|
break; |
349 |
|
case 'E': |
350 |
|
packet_encryption = False; |
351 |
break; |
break; |
|
|
|
352 |
case 'm': |
case 'm': |
353 |
sendmotion = False; |
g_sendmotion = False; |
354 |
break; |
break; |
355 |
|
|
356 |
case 'C': |
case 'C': |
357 |
owncolmap = True; |
g_owncolmap = True; |
358 |
break; |
break; |
359 |
|
|
360 |
case 'K': |
case 'K': |
361 |
grab_keyboard = False; |
g_grab_keyboard = False; |
362 |
break; |
break; |
363 |
|
|
364 |
case 'T': |
case 'T': |
365 |
STRNCPY(title, optarg, sizeof(title)); |
STRNCPY(g_title, optarg, sizeof(g_title)); |
366 |
break; |
break; |
367 |
|
|
368 |
case 'D': |
case 'D': |
369 |
hide_decorations = True; |
g_hide_decorations = True; |
370 |
break; |
break; |
371 |
|
|
372 |
case 'a': |
case 'a': |
373 |
server_bpp = strtol(optarg, NULL, 10); |
g_server_bpp = strtol(optarg, NULL, 10); |
374 |
if (server_bpp != 8 && server_bpp != 16 && server_bpp != 15 |
if (g_server_bpp != 8 && g_server_bpp != 16 && g_server_bpp != 15 |
375 |
&& server_bpp != 24) |
&& g_server_bpp != 24) |
376 |
{ |
{ |
377 |
error("invalid server bpp\n"); |
error("invalid server bpp\n"); |
378 |
return 1; |
return 1; |
379 |
} |
} |
380 |
break; |
break; |
381 |
|
|
382 |
|
#ifdef WITH_RDPSND |
383 |
|
case 'A': |
384 |
|
g_rdpsnd = False; |
385 |
|
break; |
386 |
|
#endif |
387 |
|
case '0': |
388 |
|
g_console_session = True; |
389 |
|
break; |
390 |
|
|
391 |
|
case '4': |
392 |
|
g_use_rdp5 = False; |
393 |
|
break; |
394 |
|
|
395 |
case '5': |
case '5': |
396 |
use_rdp5 = True; |
g_use_rdp5 = True; |
397 |
break; |
break; |
398 |
|
|
399 |
case 'h': |
case 'h': |
400 |
case '?': |
case '?': |
401 |
default: |
default: |
411 |
} |
} |
412 |
|
|
413 |
STRNCPY(server, argv[optind], sizeof(server)); |
STRNCPY(server, argv[optind], sizeof(server)); |
414 |
p = strchr(server, ':'); |
parse_server_and_port(server); |
|
if (p != NULL) |
|
|
{ |
|
|
tcp_port_rdp = strtol(p + 1, NULL, 10); |
|
|
*p = 0; |
|
|
} |
|
415 |
|
|
416 |
if (!username_option) |
if (!username_option) |
417 |
{ |
{ |
422 |
return 1; |
return 1; |
423 |
} |
} |
424 |
|
|
425 |
STRNCPY(username, pw->pw_name, sizeof(username)); |
STRNCPY(g_username, pw->pw_name, sizeof(g_username)); |
426 |
} |
} |
427 |
|
|
428 |
if (hostname[0] == 0) |
if (hostname[0] == 0) |
443 |
if (prompt_password && read_password(password, sizeof(password))) |
if (prompt_password && read_password(password, sizeof(password))) |
444 |
flags |= RDP_LOGON_AUTO; |
flags |= RDP_LOGON_AUTO; |
445 |
|
|
446 |
if (title[0] == 0) |
if (g_title[0] == 0) |
447 |
{ |
{ |
448 |
strcpy(title, "rdesktop - "); |
strcpy(g_title, "rdesktop - "); |
449 |
strncat(title, server, sizeof(title) - sizeof("rdesktop - ")); |
strncat(g_title, server, sizeof(g_title) - sizeof("rdesktop - ")); |
450 |
} |
} |
451 |
|
|
452 |
#ifdef RDP2VNC |
#ifdef RDP2VNC |
453 |
rdp2vnc_connect(server, flags, domain, password, shell, directory); |
rdp2vnc_connect(server, flags, domain, password, shell, directory); |
454 |
|
return 0; |
455 |
#else |
#else |
456 |
|
|
457 |
if (!ui_init()) |
if (!ui_init()) |
458 |
return 1; |
return 1; |
459 |
|
|
460 |
|
#ifdef WITH_RDPSND |
461 |
|
if (g_rdpsnd) |
462 |
|
{ |
463 |
|
rdpsnd_init(); |
464 |
|
} |
465 |
|
#endif |
466 |
|
/* rdpdr_init(); */ |
467 |
|
|
468 |
if (!rdp_connect(server, flags, domain, password, shell, directory)) |
if (!rdp_connect(server, flags, domain, password, shell, directory)) |
469 |
return 1; |
return 1; |
470 |
|
|
471 |
|
/* By setting encryption to False here, we have an encrypted login |
472 |
|
packet but unencrypted transfer of other packets */ |
473 |
|
if (!packet_encryption) |
474 |
|
g_encryption = False; |
475 |
|
|
476 |
|
|
477 |
DEBUG(("Connection successful.\n")); |
DEBUG(("Connection successful.\n")); |
478 |
memset(password, 0, sizeof(password)); |
memset(password, 0, sizeof(password)); |
479 |
|
|
480 |
if (ui_create_window()) |
if (ui_create_window()) |
481 |
{ |
{ |
482 |
rdp_main_loop(); |
rdp_retval = rdp_main_loop(); |
483 |
ui_destroy_window(); |
ui_destroy_window(); |
484 |
} |
} |
485 |
|
|
487 |
rdp_disconnect(); |
rdp_disconnect(); |
488 |
ui_deinit(); |
ui_deinit(); |
489 |
|
|
490 |
|
if (True == rdp_retval) |
491 |
|
return 0; |
492 |
|
else |
493 |
|
return 2; |
494 |
|
|
495 |
#endif |
#endif |
496 |
|
|
|
return 0; |
|
497 |
} |
} |
498 |
|
|
499 |
#ifdef EGD_SOCKET |
#ifdef EGD_SOCKET |
692 |
if (home == NULL) |
if (home == NULL) |
693 |
return -1; |
return -1; |
694 |
|
|
695 |
path = (char*)xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence.")); |
path = (char *) xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence.")); |
696 |
sprintf(path, "%s/.rdesktop/licence.%s", home, hostname); |
sprintf(path, "%s/.rdesktop/licence.%s", home, hostname); |
697 |
|
|
698 |
fd = open(path, O_RDONLY); |
fd = open(path, O_RDONLY); |
702 |
if (fstat(fd, &st)) |
if (fstat(fd, &st)) |
703 |
return -1; |
return -1; |
704 |
|
|
705 |
*data = (uint8*)xmalloc(st.st_size); |
*data = (uint8 *) xmalloc(st.st_size); |
706 |
length = read(fd, *data, st.st_size); |
length = read(fd, *data, st.st_size); |
707 |
close(fd); |
close(fd); |
708 |
xfree(path); |
xfree(path); |
719 |
if (home == NULL) |
if (home == NULL) |
720 |
return; |
return; |
721 |
|
|
722 |
path = (char*)xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence.")); |
path = (char *) xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence.")); |
723 |
|
|
724 |
sprintf(path, "%s/.rdesktop", home); |
sprintf(path, "%s/.rdesktop", home); |
725 |
if ((mkdir(path, 0700) == -1) && errno != EEXIST) |
if ((mkdir(path, 0700) == -1) && errno != EEXIST) |
731 |
/* write licence to licence.hostname.new, then atomically rename to licence.hostname */ |
/* write licence to licence.hostname.new, then atomically rename to licence.hostname */ |
732 |
|
|
733 |
sprintf(path, "%s/.rdesktop/licence.%s", home, hostname); |
sprintf(path, "%s/.rdesktop/licence.%s", home, hostname); |
734 |
tmppath = (char*)xmalloc(strlen(path) + sizeof(".new")); |
tmppath = (char *) xmalloc(strlen(path) + sizeof(".new")); |
735 |
strcpy(tmppath, path); |
strcpy(tmppath, path); |
736 |
strcat(tmppath, ".new"); |
strcat(tmppath, ".new"); |
737 |
|
|
738 |
fd = open(tmppath, O_WRONLY|O_CREAT|O_TRUNC, 0600); |
fd = open(tmppath, O_WRONLY | O_CREAT | O_TRUNC, 0600); |
739 |
if (fd == -1) |
if (fd == -1) |
740 |
{ |
{ |
741 |
perror(tmppath); |
perror(tmppath); |