26 |
#include <sys/stat.h> /* stat */ |
#include <sys/stat.h> /* stat */ |
27 |
#include <sys/time.h> /* gettimeofday */ |
#include <sys/time.h> /* gettimeofday */ |
28 |
#include <sys/times.h> /* times */ |
#include <sys/times.h> /* times */ |
29 |
|
#include <ctype.h> /* toupper */ |
30 |
#include <errno.h> |
#include <errno.h> |
31 |
#include "rdesktop.h" |
#include "rdesktop.h" |
32 |
|
|
46 |
char hostname[16]; |
char hostname[16]; |
47 |
char keymapname[16]; |
char keymapname[16]; |
48 |
int keylayout = 0x409; /* Defaults to US keyboard layout */ |
int keylayout = 0x409; /* Defaults to US keyboard layout */ |
49 |
int g_width = 800; /* If width or height are reset to zero, the geometry will |
|
50 |
be fetched from _NET_WORKAREA */ |
int g_width = 800; /* width is special: If 0, the |
51 |
|
geometry will be fetched from |
52 |
|
_NET_WORKAREA. If negative, |
53 |
|
absolute value specifies the |
54 |
|
percent of the whole screen. */ |
55 |
int g_height = 600; |
int g_height = 600; |
56 |
int tcp_port_rdp = TCP_PORT_RDP; |
int tcp_port_rdp = TCP_PORT_RDP; |
57 |
int g_server_bpp = 8; |
int g_server_bpp = 8; |
67 |
BOOL g_hide_decorations = False; |
BOOL g_hide_decorations = False; |
68 |
BOOL g_use_rdp5 = True; |
BOOL g_use_rdp5 = True; |
69 |
BOOL g_console_session = False; |
BOOL g_console_session = False; |
70 |
extern BOOL g_owncolmap; |
BOOL g_numlock_sync = False; |
71 |
|
BOOL g_owncolmap = False; |
72 |
|
BOOL g_ownbackstore = True; /* We can't rely on external BackingStore */ |
73 |
|
uint32 g_embed_wnd; |
74 |
|
uint32 g_rdp5_performanceflags = |
75 |
|
RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS; |
76 |
|
|
77 |
|
#ifdef WITH_RDPSND |
78 |
|
BOOL g_rdpsnd = False; |
79 |
|
#endif |
80 |
|
|
81 |
|
extern RDPDR_DEVICE g_rdpdr_device[]; |
82 |
|
extern uint32 g_num_devices; |
83 |
|
extern char *g_rdpdr_clientname; |
84 |
|
|
85 |
#ifdef RDP2VNC |
#ifdef RDP2VNC |
86 |
extern int rfb_port; |
extern int rfb_port; |
105 |
fprintf(stderr, " -u: user name\n"); |
fprintf(stderr, " -u: user name\n"); |
106 |
fprintf(stderr, " -d: domain\n"); |
fprintf(stderr, " -d: domain\n"); |
107 |
fprintf(stderr, " -s: shell\n"); |
fprintf(stderr, " -s: shell\n"); |
|
fprintf(stderr, " -S: caption button size (single application mode)\n"); |
|
108 |
fprintf(stderr, " -c: working directory\n"); |
fprintf(stderr, " -c: working directory\n"); |
109 |
fprintf(stderr, " -p: password (- to prompt)\n"); |
fprintf(stderr, " -p: password (- to prompt)\n"); |
110 |
fprintf(stderr, " -n: client hostname\n"); |
fprintf(stderr, " -n: client hostname\n"); |
111 |
fprintf(stderr, " -k: keyboard layout on terminal server (us,sv,gr,etc.)\n"); |
fprintf(stderr, " -k: keyboard layout on server (en-us, de, sv, etc.)\n"); |
112 |
fprintf(stderr, " -g: desktop geometry (WxH)\n"); |
fprintf(stderr, " -g: desktop geometry (WxH)\n"); |
113 |
fprintf(stderr, " -f: full-screen mode\n"); |
fprintf(stderr, " -f: full-screen mode\n"); |
114 |
fprintf(stderr, " -b: force bitmap updates\n"); |
fprintf(stderr, " -b: force bitmap updates\n"); |
115 |
|
fprintf(stderr, " -B: use BackingStore of X-server (if available)\n"); |
116 |
fprintf(stderr, " -e: disable encryption (French TS)\n"); |
fprintf(stderr, " -e: disable encryption (French TS)\n"); |
117 |
fprintf(stderr, " -E: disable encryption from client to server\n"); |
fprintf(stderr, " -E: disable encryption from client to server\n"); |
118 |
fprintf(stderr, " -m: do not send motion events\n"); |
fprintf(stderr, " -m: do not send motion events\n"); |
119 |
fprintf(stderr, " -C: use private colour map\n"); |
fprintf(stderr, " -C: use private colour map\n"); |
120 |
|
fprintf(stderr, " -D: hide window manager decorations\n"); |
121 |
fprintf(stderr, " -K: keep window manager key bindings\n"); |
fprintf(stderr, " -K: keep window manager key bindings\n"); |
122 |
|
fprintf(stderr, " -S: caption button size (single application mode)\n"); |
123 |
fprintf(stderr, " -T: window title\n"); |
fprintf(stderr, " -T: window title\n"); |
124 |
fprintf(stderr, " -D: hide window manager decorations\n"); |
fprintf(stderr, " -N: enable numlock syncronization\n"); |
125 |
fprintf(stderr, " -a: server bpp\n"); |
fprintf(stderr, " -X: embed into another window with a given id.\n"); |
126 |
|
fprintf(stderr, " -a: connection colour depth\n"); |
127 |
|
fprintf(stderr, |
128 |
|
" -x: RDP5 experience (m[odem 28.8], b[roadband], l[an] or hex number)\n"); |
129 |
|
fprintf(stderr, " -r: enable specified device redirection (this flag can be repeated)\n"); |
130 |
|
fprintf(stderr, |
131 |
|
" '-r comport:COM1=/dev/ttyS0': enable serial redirection of /dev/ttyS0 to COM1\n"); |
132 |
|
fprintf(stderr, " or COM1=/dev/ttyS0,COM2=/dev/ttyS1\n"); |
133 |
|
fprintf(stderr, |
134 |
|
" '-r disk:A=/mnt/floppy': enable redirection of /mnt/floppy to A:\n"); |
135 |
|
fprintf(stderr, " or A=/mnt/floppy,D=/mnt/cdrom'\n"); |
136 |
|
fprintf(stderr, " '-r clientname=<client name>': Set the client name displayed\n"); |
137 |
|
fprintf(stderr, " for redirected disks\n"); |
138 |
|
fprintf(stderr, |
139 |
|
" '-r lptport:LPT1=/dev/lp0': enable parallel redirection of /dev/lp0 to LPT1\n"); |
140 |
|
fprintf(stderr, " or LPT1=/dev/lp0,LPT2=/dev/lp1\n"); |
141 |
|
fprintf(stderr, " '-r printer:mydeskjet': enable printer redirection\n"); |
142 |
|
fprintf(stderr, |
143 |
|
" or mydeskjet=\"HP LaserJet IIIP\" to enter server driver as well\n"); |
144 |
|
fprintf(stderr, " '-r sound:[local|off|remote]': enable sound redirection\n"); |
145 |
|
fprintf(stderr, " remote would leave sound on server\n"); |
146 |
fprintf(stderr, " -0: attach to console\n"); |
fprintf(stderr, " -0: attach to console\n"); |
147 |
fprintf(stderr, " -4: use RDP version 4\n"); |
fprintf(stderr, " -4: use RDP version 4\n"); |
148 |
fprintf(stderr, " -5: use RDP version 5 (default)\n"); |
fprintf(stderr, " -5: use RDP version 5 (default)\n"); |
247 |
uint32 flags; |
uint32 flags; |
248 |
char *p; |
char *p; |
249 |
int c; |
int c; |
250 |
|
|
251 |
int username_option = 0; |
int username_option = 0; |
252 |
|
|
253 |
flags = RDP_LOGON_NORMAL; |
flags = RDP_LOGON_NORMAL; |
254 |
prompt_password = False; |
prompt_password = False; |
255 |
domain[0] = password[0] = shell[0] = directory[0] = 0; |
domain[0] = password[0] = shell[0] = directory[0] = 0; |
256 |
strcpy(keymapname, "en-us"); |
strcpy(keymapname, "en-us"); |
257 |
|
g_embed_wnd = 0; |
258 |
|
|
259 |
|
g_num_devices = 0; |
260 |
|
|
261 |
#ifdef RDP2VNC |
#ifdef RDP2VNC |
262 |
#define VNCOPT "V:Q:" |
#define VNCOPT "V:Q:" |
264 |
#define VNCOPT |
#define VNCOPT |
265 |
#endif |
#endif |
266 |
|
|
267 |
while ((c = getopt(argc, argv, VNCOPT "u:d:s:S:c:p:n:k:g:a:fbeEmCKT:D045h?")) != -1) |
while ((c = getopt(argc, argv, VNCOPT "u:d:s:c:p:n:k:g:fbBeEmCDKS:T:NX:a:x:r:045h?")) != -1) |
268 |
{ |
{ |
269 |
switch (c) |
switch (c) |
270 |
{ |
{ |
295 |
STRNCPY(shell, optarg, sizeof(shell)); |
STRNCPY(shell, optarg, sizeof(shell)); |
296 |
break; |
break; |
297 |
|
|
|
case 'S': |
|
|
if (!strcmp(optarg, "standard")) |
|
|
{ |
|
|
g_win_button_size = 18; |
|
|
break; |
|
|
} |
|
|
|
|
|
g_win_button_size = strtol(optarg, &p, 10); |
|
|
|
|
|
if (*p) |
|
|
{ |
|
|
error("invalid button size\n"); |
|
|
return 1; |
|
|
} |
|
|
|
|
|
break; |
|
|
|
|
298 |
case 'c': |
case 'c': |
299 |
STRNCPY(directory, optarg, sizeof(directory)); |
STRNCPY(directory, optarg, sizeof(directory)); |
300 |
break; |
break; |
324 |
break; |
break; |
325 |
|
|
326 |
case 'g': |
case 'g': |
327 |
|
g_fullscreen = False; |
328 |
if (!strcmp(optarg, "workarea")) |
if (!strcmp(optarg, "workarea")) |
329 |
{ |
{ |
330 |
g_width = g_height = 0; |
g_width = g_height = 0; |
332 |
} |
} |
333 |
|
|
334 |
g_width = strtol(optarg, &p, 10); |
g_width = strtol(optarg, &p, 10); |
335 |
|
if (g_width <= 0) |
336 |
|
{ |
337 |
|
error("invalid geometry\n"); |
338 |
|
return 1; |
339 |
|
} |
340 |
|
|
341 |
if (*p == 'x') |
if (*p == 'x') |
342 |
g_height = strtol(p + 1, NULL, 10); |
g_height = strtol(p + 1, NULL, 10); |
343 |
|
|
344 |
if ((g_width == 0) || (g_height == 0)) |
if (g_height <= 0) |
345 |
{ |
{ |
346 |
error("invalid geometry\n"); |
error("invalid geometry\n"); |
347 |
return 1; |
return 1; |
348 |
} |
} |
349 |
|
|
350 |
|
if (*p == '%') |
351 |
|
g_width = -g_width; |
352 |
|
|
353 |
break; |
break; |
354 |
|
|
355 |
case 'f': |
case 'f': |
360 |
g_orders = False; |
g_orders = False; |
361 |
break; |
break; |
362 |
|
|
363 |
|
case 'B': |
364 |
|
g_ownbackstore = False; |
365 |
|
break; |
366 |
|
|
367 |
case 'e': |
case 'e': |
368 |
g_encryption = False; |
g_encryption = False; |
369 |
break; |
break; |
378 |
g_owncolmap = True; |
g_owncolmap = True; |
379 |
break; |
break; |
380 |
|
|
381 |
|
case 'D': |
382 |
|
g_hide_decorations = True; |
383 |
|
break; |
384 |
|
|
385 |
case 'K': |
case 'K': |
386 |
g_grab_keyboard = False; |
g_grab_keyboard = False; |
387 |
break; |
break; |
388 |
|
|
389 |
|
case 'S': |
390 |
|
if (!strcmp(optarg, "standard")) |
391 |
|
{ |
392 |
|
g_win_button_size = 18; |
393 |
|
break; |
394 |
|
} |
395 |
|
|
396 |
|
g_win_button_size = strtol(optarg, &p, 10); |
397 |
|
|
398 |
|
if (*p) |
399 |
|
{ |
400 |
|
error("invalid button size\n"); |
401 |
|
return 1; |
402 |
|
} |
403 |
|
|
404 |
|
break; |
405 |
|
|
406 |
case 'T': |
case 'T': |
407 |
STRNCPY(g_title, optarg, sizeof(g_title)); |
STRNCPY(g_title, optarg, sizeof(g_title)); |
408 |
break; |
break; |
409 |
|
|
410 |
case 'D': |
case 'N': |
411 |
g_hide_decorations = True; |
g_numlock_sync = True; |
412 |
|
break; |
413 |
|
|
414 |
|
case 'X': |
415 |
|
g_embed_wnd = strtol(optarg, NULL, 10); |
416 |
break; |
break; |
417 |
|
|
418 |
case 'a': |
case 'a': |
425 |
} |
} |
426 |
break; |
break; |
427 |
|
|
428 |
|
case 'x': |
429 |
|
|
430 |
|
if (strncmp("modem", optarg, 1) == 0) |
431 |
|
{ |
432 |
|
g_rdp5_performanceflags = |
433 |
|
RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | |
434 |
|
RDP5_NO_MENUANIMATIONS | RDP5_NO_THEMING; |
435 |
|
} |
436 |
|
else if (strncmp("broadband", optarg, 1) == 0) |
437 |
|
{ |
438 |
|
g_rdp5_performanceflags = RDP5_NO_WALLPAPER; |
439 |
|
} |
440 |
|
else if (strncmp("lan", optarg, 1) == 0) |
441 |
|
{ |
442 |
|
g_rdp5_performanceflags = RDP5_DISABLE_NOTHING; |
443 |
|
} |
444 |
|
else |
445 |
|
{ |
446 |
|
g_rdp5_performanceflags = strtol(optarg, NULL, 16); |
447 |
|
} |
448 |
|
break; |
449 |
|
|
450 |
|
case 'r': |
451 |
|
|
452 |
|
if (strncmp("sound", optarg, 5) == 0) |
453 |
|
{ |
454 |
|
optarg += 5; |
455 |
|
|
456 |
|
if (*optarg == ':') |
457 |
|
{ |
458 |
|
*optarg++; |
459 |
|
while ((p = next_arg(optarg, ','))) |
460 |
|
{ |
461 |
|
if (strncmp("remote", optarg, 6) == 0) |
462 |
|
flags |= RDP_LOGON_LEAVE_AUDIO; |
463 |
|
|
464 |
|
if (strncmp("local", optarg, 5) == 0) |
465 |
|
#ifdef WITH_RDPSND |
466 |
|
g_rdpsnd = True; |
467 |
|
#else |
468 |
|
warning("Not compiled with sound support"); |
469 |
|
#endif |
470 |
|
|
471 |
|
if (strncmp("off", optarg, 3) == 0) |
472 |
|
g_rdpsnd = False; |
473 |
|
|
474 |
|
optarg = p; |
475 |
|
} |
476 |
|
} |
477 |
|
else |
478 |
|
{ |
479 |
|
#ifdef WITH_RDPSND |
480 |
|
g_rdpsnd = True; |
481 |
|
#else |
482 |
|
warning("Not compiled with sound support"); |
483 |
|
#endif |
484 |
|
} |
485 |
|
} |
486 |
|
else if (strncmp("disk", optarg, 4) == 0) |
487 |
|
{ |
488 |
|
/* -r disk:h:=/mnt/floppy */ |
489 |
|
disk_enum_devices(&g_num_devices, optarg + 4); |
490 |
|
} |
491 |
|
else if (strncmp("comport", optarg, 7) == 0) |
492 |
|
{ |
493 |
|
serial_enum_devices(&g_num_devices, optarg + 7); |
494 |
|
} |
495 |
|
else if (strncmp("lptport", optarg, 7) == 0) |
496 |
|
{ |
497 |
|
parallel_enum_devices(&g_num_devices, optarg + 7); |
498 |
|
} |
499 |
|
else if (strncmp("printer", optarg, 7) == 0) |
500 |
|
{ |
501 |
|
printer_enum_devices(&g_num_devices, optarg + 7); |
502 |
|
} |
503 |
|
else if (strncmp("clientname", optarg, 7) == 0) |
504 |
|
{ |
505 |
|
g_rdpdr_clientname = xmalloc(strlen(optarg + 11) + 1); |
506 |
|
strcpy(g_rdpdr_clientname, optarg + 11); |
507 |
|
} |
508 |
|
else |
509 |
|
{ |
510 |
|
warning("Unknown -r argument\n\n\tPossible arguments are: comport, disk, lptport, printer, sound\n"); |
511 |
|
} |
512 |
|
break; |
513 |
|
|
514 |
case '0': |
case '0': |
515 |
g_console_session = True; |
g_console_session = True; |
516 |
break; |
break; |
531 |
} |
} |
532 |
} |
} |
533 |
|
|
534 |
if (argc - optind < 1) |
if (argc - optind != 1) |
535 |
{ |
{ |
536 |
usage(argv[0]); |
usage(argv[0]); |
537 |
return 1; |
return 1; |
585 |
return 1; |
return 1; |
586 |
|
|
587 |
#ifdef WITH_RDPSND |
#ifdef WITH_RDPSND |
588 |
rdpsnd_init(); |
if (g_rdpsnd) |
589 |
|
rdpsnd_init(); |
590 |
#endif |
#endif |
591 |
/* rdpdr_init(); */ |
rdpdr_init(); |
592 |
|
|
593 |
if (!rdp_connect(server, flags, domain, password, shell, directory)) |
if (!rdp_connect(server, flags, domain, password, shell, directory)) |
594 |
return 1; |
return 1; |
778 |
|
|
779 |
/* produce a hex dump */ |
/* produce a hex dump */ |
780 |
void |
void |
781 |
hexdump(unsigned char *p, int len) |
hexdump(unsigned char *p, unsigned int len) |
782 |
{ |
{ |
783 |
unsigned char *line = p; |
unsigned char *line = p; |
784 |
int i, thisline, offset = 0; |
int i, thisline, offset = 0; |
805 |
} |
} |
806 |
} |
} |
807 |
|
|
808 |
|
/* |
809 |
|
input: src is the string we look in for needle. |
810 |
|
Needle may be escaped by a backslash, in |
811 |
|
that case we ignore that particular needle. |
812 |
|
return value: returns next src pointer, for |
813 |
|
succesive executions, like in a while loop |
814 |
|
if retval is 0, then there are no more args. |
815 |
|
pitfalls: |
816 |
|
src is modified. 0x00 chars are inserted to |
817 |
|
terminate strings. |
818 |
|
return val, points on the next val chr after ins |
819 |
|
0x00 |
820 |
|
|
821 |
|
example usage: |
822 |
|
while( (pos = next_arg( optarg, ',')) ){ |
823 |
|
printf("%s\n",optarg); |
824 |
|
optarg=pos; |
825 |
|
} |
826 |
|
|
827 |
|
*/ |
828 |
|
char * |
829 |
|
next_arg(char *src, char needle) |
830 |
|
{ |
831 |
|
char *nextval; |
832 |
|
char *p; |
833 |
|
char *mvp = 0; |
834 |
|
|
835 |
|
/* EOS */ |
836 |
|
if (*src == (char) 0x00) |
837 |
|
return 0; |
838 |
|
|
839 |
|
p = src; |
840 |
|
/* skip escaped needles */ |
841 |
|
while ((nextval = strchr(p, needle))) |
842 |
|
{ |
843 |
|
mvp = nextval - 1; |
844 |
|
/* found backslashed needle */ |
845 |
|
if (*mvp == '\\' && (mvp > src)) |
846 |
|
{ |
847 |
|
/* move string one to the left */ |
848 |
|
while (*(mvp + 1) != (char) 0x00) |
849 |
|
{ |
850 |
|
*mvp = *(mvp + 1); |
851 |
|
*mvp++; |
852 |
|
} |
853 |
|
*mvp = (char) 0x00; |
854 |
|
p = nextval; |
855 |
|
} |
856 |
|
else |
857 |
|
{ |
858 |
|
p = nextval + 1; |
859 |
|
break; |
860 |
|
} |
861 |
|
|
862 |
|
} |
863 |
|
|
864 |
|
/* more args available */ |
865 |
|
if (nextval) |
866 |
|
{ |
867 |
|
*nextval = (char) 0x00; |
868 |
|
return ++nextval; |
869 |
|
} |
870 |
|
|
871 |
|
/* no more args after this, jump to EOS */ |
872 |
|
nextval = src + strlen(src); |
873 |
|
return nextval; |
874 |
|
} |
875 |
|
|
876 |
|
|
877 |
|
void |
878 |
|
toupper_str(char *p) |
879 |
|
{ |
880 |
|
while (*p) |
881 |
|
{ |
882 |
|
if ((*p >= 'a') && (*p <= 'z')) |
883 |
|
*p = toupper((int) *p); |
884 |
|
p++; |
885 |
|
} |
886 |
|
} |
887 |
|
|
888 |
|
|
889 |
|
/* not all clibs got ltoa */ |
890 |
|
#define LTOA_BUFSIZE (sizeof(long) * 8 + 1) |
891 |
|
|
892 |
|
char * |
893 |
|
l_to_a(long N, int base) |
894 |
|
{ |
895 |
|
static char ret[LTOA_BUFSIZE]; |
896 |
|
|
897 |
|
char *head = ret, buf[LTOA_BUFSIZE], *tail = buf + sizeof(buf); |
898 |
|
|
899 |
|
register int divrem; |
900 |
|
|
901 |
|
if (base < 36 || 2 > base) |
902 |
|
base = 10; |
903 |
|
|
904 |
|
if (N < 0) |
905 |
|
{ |
906 |
|
*head++ = '-'; |
907 |
|
N = -N; |
908 |
|
} |
909 |
|
|
910 |
|
tail = buf + sizeof(buf); |
911 |
|
*--tail = 0; |
912 |
|
|
913 |
|
do |
914 |
|
{ |
915 |
|
divrem = N % base; |
916 |
|
*--tail = (divrem <= 9) ? divrem + '0' : divrem + 'a' - 10; |
917 |
|
N /= base; |
918 |
|
} |
919 |
|
while (N); |
920 |
|
|
921 |
|
strcpy(head, tail); |
922 |
|
return ret; |
923 |
|
} |
924 |
|
|
925 |
|
|
926 |
int |
int |
927 |
load_licence(unsigned char **data) |
load_licence(unsigned char **data) |