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 |
|
BOOL g_numlock_sync = False; |
71 |
extern BOOL g_owncolmap; |
extern BOOL g_owncolmap; |
72 |
|
|
73 |
|
#ifdef WITH_RDPSND |
74 |
|
BOOL g_rdpsnd = False; |
75 |
|
#endif |
76 |
|
|
77 |
|
extern RDPDR_DEVICE g_rdpdr_device[]; |
78 |
|
extern uint32 g_num_devices; |
79 |
|
|
80 |
#ifdef RDP2VNC |
#ifdef RDP2VNC |
81 |
extern int rfb_port; |
extern int rfb_port; |
82 |
extern int defer_time; |
extern int defer_time; |
100 |
fprintf(stderr, " -u: user name\n"); |
fprintf(stderr, " -u: user name\n"); |
101 |
fprintf(stderr, " -d: domain\n"); |
fprintf(stderr, " -d: domain\n"); |
102 |
fprintf(stderr, " -s: shell\n"); |
fprintf(stderr, " -s: shell\n"); |
|
fprintf(stderr, " -S: caption button size (single application mode)\n"); |
|
103 |
fprintf(stderr, " -c: working directory\n"); |
fprintf(stderr, " -c: working directory\n"); |
104 |
fprintf(stderr, " -p: password (- to prompt)\n"); |
fprintf(stderr, " -p: password (- to prompt)\n"); |
105 |
fprintf(stderr, " -n: client hostname\n"); |
fprintf(stderr, " -n: client hostname\n"); |
106 |
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"); |
107 |
fprintf(stderr, " -g: desktop geometry (WxH)\n"); |
fprintf(stderr, " -g: desktop geometry (WxH)\n"); |
108 |
fprintf(stderr, " -f: full-screen mode\n"); |
fprintf(stderr, " -f: full-screen mode\n"); |
109 |
fprintf(stderr, " -b: force bitmap updates\n"); |
fprintf(stderr, " -b: force bitmap updates\n"); |
111 |
fprintf(stderr, " -E: disable encryption from client to server\n"); |
fprintf(stderr, " -E: disable encryption from client to server\n"); |
112 |
fprintf(stderr, " -m: do not send motion events\n"); |
fprintf(stderr, " -m: do not send motion events\n"); |
113 |
fprintf(stderr, " -C: use private colour map\n"); |
fprintf(stderr, " -C: use private colour map\n"); |
114 |
|
fprintf(stderr, " -D: hide window manager decorations\n"); |
115 |
fprintf(stderr, " -K: keep window manager key bindings\n"); |
fprintf(stderr, " -K: keep window manager key bindings\n"); |
116 |
|
fprintf(stderr, " -S: caption button size (single application mode)\n"); |
117 |
fprintf(stderr, " -T: window title\n"); |
fprintf(stderr, " -T: window title\n"); |
118 |
fprintf(stderr, " -D: hide window manager decorations\n"); |
fprintf(stderr, " -N: enable numlock syncronization\n"); |
119 |
fprintf(stderr, " -a: server bpp\n"); |
fprintf(stderr, " -a: connection colour depth\n"); |
120 |
|
fprintf(stderr, " -r: enable specified device redirection (this flag can be repeated)\n"); |
121 |
|
fprintf(stderr, |
122 |
|
" '-r comport:COM1=/dev/ttyS0': enable serial redirection of /dev/ttyS0 to COM1\n"); |
123 |
|
fprintf(stderr, " or COM1=/dev/ttyS0,COM2=/dev/ttyS1\n"); |
124 |
|
fprintf(stderr, |
125 |
|
" '-r disk:A=/mnt/floppy': enable redirection of /mnt/floppy to A:\n"); |
126 |
|
fprintf(stderr, " or A=/mnt/floppy,D=/mnt/cdrom'\n"); |
127 |
|
fprintf(stderr, |
128 |
|
" '-r lptport:LPT1=/dev/lp0': enable parallel redirection of /dev/lp0 to LPT1\n"); |
129 |
|
fprintf(stderr, " or LPT1=/dev/lp0,LPT2=/dev/lp1\n"); |
130 |
|
fprintf(stderr, " '-r printer:mydeskjet': enable printer redirection\n"); |
131 |
|
fprintf(stderr, |
132 |
|
" or mydeskjet=\"HP LaserJet IIIP\" to enter server driver as well\n"); |
133 |
|
fprintf(stderr, " '-r sound': enable sound redirection\n"); |
134 |
fprintf(stderr, " -0: attach to console\n"); |
fprintf(stderr, " -0: attach to console\n"); |
135 |
fprintf(stderr, " -4: use RDP version 4\n"); |
fprintf(stderr, " -4: use RDP version 4\n"); |
136 |
fprintf(stderr, " -5: use RDP version 5 (default)\n"); |
fprintf(stderr, " -5: use RDP version 5 (default)\n"); |
235 |
uint32 flags; |
uint32 flags; |
236 |
char *p; |
char *p; |
237 |
int c; |
int c; |
238 |
|
|
239 |
int username_option = 0; |
int username_option = 0; |
240 |
|
|
241 |
flags = RDP_LOGON_NORMAL; |
flags = RDP_LOGON_NORMAL; |
243 |
domain[0] = password[0] = shell[0] = directory[0] = 0; |
domain[0] = password[0] = shell[0] = directory[0] = 0; |
244 |
strcpy(keymapname, "en-us"); |
strcpy(keymapname, "en-us"); |
245 |
|
|
246 |
|
g_num_devices = 0; |
247 |
|
|
248 |
#ifdef RDP2VNC |
#ifdef RDP2VNC |
249 |
#define VNCOPT "V:Q:" |
#define VNCOPT "V:Q:" |
250 |
#else |
#else |
251 |
#define VNCOPT |
#define VNCOPT |
252 |
#endif |
#endif |
253 |
|
|
254 |
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:fbeEmCDKS:T:Na:r:045h?")) != -1) |
255 |
{ |
{ |
256 |
switch (c) |
switch (c) |
257 |
{ |
{ |
282 |
STRNCPY(shell, optarg, sizeof(shell)); |
STRNCPY(shell, optarg, sizeof(shell)); |
283 |
break; |
break; |
284 |
|
|
|
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; |
|
|
|
|
285 |
case 'c': |
case 'c': |
286 |
STRNCPY(directory, optarg, sizeof(directory)); |
STRNCPY(directory, optarg, sizeof(directory)); |
287 |
break; |
break; |
311 |
break; |
break; |
312 |
|
|
313 |
case 'g': |
case 'g': |
314 |
|
g_fullscreen = False; |
315 |
if (!strcmp(optarg, "workarea")) |
if (!strcmp(optarg, "workarea")) |
316 |
{ |
{ |
317 |
g_width = g_height = 0; |
g_width = g_height = 0; |
319 |
} |
} |
320 |
|
|
321 |
g_width = strtol(optarg, &p, 10); |
g_width = strtol(optarg, &p, 10); |
322 |
|
if (g_width <= 0) |
323 |
|
{ |
324 |
|
error("invalid geometry\n"); |
325 |
|
return 1; |
326 |
|
} |
327 |
|
|
328 |
if (*p == 'x') |
if (*p == 'x') |
329 |
g_height = strtol(p + 1, NULL, 10); |
g_height = strtol(p + 1, NULL, 10); |
330 |
|
|
331 |
if ((g_width == 0) || (g_height == 0)) |
if (g_height <= 0) |
332 |
{ |
{ |
333 |
error("invalid geometry\n"); |
error("invalid geometry\n"); |
334 |
return 1; |
return 1; |
335 |
} |
} |
336 |
|
|
337 |
|
if (*p == '%') |
338 |
|
g_width = -g_width; |
339 |
|
|
340 |
break; |
break; |
341 |
|
|
342 |
case 'f': |
case 'f': |
361 |
g_owncolmap = True; |
g_owncolmap = True; |
362 |
break; |
break; |
363 |
|
|
364 |
|
case 'D': |
365 |
|
g_hide_decorations = True; |
366 |
|
break; |
367 |
|
|
368 |
case 'K': |
case 'K': |
369 |
g_grab_keyboard = False; |
g_grab_keyboard = False; |
370 |
break; |
break; |
371 |
|
|
372 |
|
case 'S': |
373 |
|
if (!strcmp(optarg, "standard")) |
374 |
|
{ |
375 |
|
g_win_button_size = 18; |
376 |
|
break; |
377 |
|
} |
378 |
|
|
379 |
|
g_win_button_size = strtol(optarg, &p, 10); |
380 |
|
|
381 |
|
if (*p) |
382 |
|
{ |
383 |
|
error("invalid button size\n"); |
384 |
|
return 1; |
385 |
|
} |
386 |
|
|
387 |
|
break; |
388 |
|
|
389 |
case 'T': |
case 'T': |
390 |
STRNCPY(g_title, optarg, sizeof(g_title)); |
STRNCPY(g_title, optarg, sizeof(g_title)); |
391 |
break; |
break; |
392 |
|
|
393 |
case 'D': |
case 'N': |
394 |
g_hide_decorations = True; |
g_numlock_sync = True; |
395 |
break; |
break; |
396 |
|
|
397 |
case 'a': |
case 'a': |
404 |
} |
} |
405 |
break; |
break; |
406 |
|
|
407 |
|
case 'r': |
408 |
|
|
409 |
|
if (strncmp("sound", optarg, 5) == 0) |
410 |
|
{ |
411 |
|
#ifdef WITH_RDPSND |
412 |
|
g_rdpsnd = True; |
413 |
|
#else |
414 |
|
warning("Not compiled with sound support"); |
415 |
|
#endif |
416 |
|
} |
417 |
|
else if (strncmp("disk", optarg, 4) == 0) |
418 |
|
{ |
419 |
|
/* -r disk:h:=/mnt/floppy */ |
420 |
|
disk_enum_devices(&g_num_devices, optarg + 4); |
421 |
|
} |
422 |
|
else if (strncmp("comport", optarg, 7) == 0) |
423 |
|
{ |
424 |
|
serial_enum_devices(&g_num_devices, optarg + 7); |
425 |
|
} |
426 |
|
else if (strncmp("lptport", optarg, 7) == 0) |
427 |
|
{ |
428 |
|
parallel_enum_devices(&g_num_devices, optarg + 7); |
429 |
|
} |
430 |
|
else if (strncmp("printer", optarg, 7) == 0) |
431 |
|
{ |
432 |
|
printer_enum_devices(&g_num_devices, optarg + 7); |
433 |
|
} |
434 |
|
else |
435 |
|
{ |
436 |
|
warning("Unknown -r argument\n\n\tPossible arguments are: comport, disk, lptport, printer, sound\n"); |
437 |
|
} |
438 |
|
break; |
439 |
|
|
440 |
case '0': |
case '0': |
441 |
g_console_session = True; |
g_console_session = True; |
442 |
break; |
break; |
511 |
return 1; |
return 1; |
512 |
|
|
513 |
#ifdef WITH_RDPSND |
#ifdef WITH_RDPSND |
514 |
rdpsnd_init(); |
if (g_rdpsnd) |
515 |
|
rdpsnd_init(); |
516 |
#endif |
#endif |
517 |
/* rdpdr_init(); */ |
rdpdr_init(); |
518 |
|
|
519 |
if (!rdp_connect(server, flags, domain, password, shell, directory)) |
if (!rdp_connect(server, flags, domain, password, shell, directory)) |
520 |
return 1; |
return 1; |
704 |
|
|
705 |
/* produce a hex dump */ |
/* produce a hex dump */ |
706 |
void |
void |
707 |
hexdump(unsigned char *p, int len) |
hexdump(unsigned char *p, unsigned int len) |
708 |
{ |
{ |
709 |
unsigned char *line = p; |
unsigned char *line = p; |
710 |
int i, thisline, offset = 0; |
int i, thisline, offset = 0; |
731 |
} |
} |
732 |
} |
} |
733 |
|
|
734 |
|
/* |
735 |
|
input: src is the string we look in for needle. |
736 |
|
Needle may be escaped by a backslash, in |
737 |
|
that case we ignore that particular needle. |
738 |
|
return value: returns next src pointer, for |
739 |
|
succesive executions, like in a while loop |
740 |
|
if retval is 0, then there are no more args. |
741 |
|
pitfalls: |
742 |
|
src is modified. 0x00 chars are inserted to |
743 |
|
terminate strings. |
744 |
|
return val, points on the next val chr after ins |
745 |
|
0x00 |
746 |
|
|
747 |
|
example usage: |
748 |
|
while( (pos = next_arg( optarg, ',')) ){ |
749 |
|
printf("%s\n",optarg); |
750 |
|
optarg=pos; |
751 |
|
} |
752 |
|
|
753 |
|
*/ |
754 |
|
char * |
755 |
|
next_arg(char *src, char needle) |
756 |
|
{ |
757 |
|
char *nextval; |
758 |
|
char *p; |
759 |
|
char *mvp = 0; |
760 |
|
|
761 |
|
/* EOS */ |
762 |
|
if (*src == (char) 0x00) |
763 |
|
return 0; |
764 |
|
|
765 |
|
p = src; |
766 |
|
/* skip escaped needles */ |
767 |
|
while ((nextval = strchr(p, needle))) |
768 |
|
{ |
769 |
|
mvp = nextval - 1; |
770 |
|
/* found backslashed needle */ |
771 |
|
if (*mvp == '\\' && (mvp > src)) |
772 |
|
{ |
773 |
|
/* move string one to the left */ |
774 |
|
while (*(mvp + 1) != (char) 0x00) |
775 |
|
{ |
776 |
|
*mvp = *(mvp + 1); |
777 |
|
*mvp++; |
778 |
|
} |
779 |
|
*mvp = (char) 0x00; |
780 |
|
p = nextval; |
781 |
|
} |
782 |
|
else |
783 |
|
{ |
784 |
|
p = nextval + 1; |
785 |
|
break; |
786 |
|
} |
787 |
|
|
788 |
|
} |
789 |
|
|
790 |
|
/* more args available */ |
791 |
|
if (nextval) |
792 |
|
{ |
793 |
|
*nextval = (char) 0x00; |
794 |
|
return ++nextval; |
795 |
|
} |
796 |
|
|
797 |
|
/* no more args after this, jump to EOS */ |
798 |
|
nextval = src + strlen(src); |
799 |
|
return nextval; |
800 |
|
} |
801 |
|
|
802 |
|
|
803 |
|
void |
804 |
|
toupper_str(char *p) |
805 |
|
{ |
806 |
|
while (*p) |
807 |
|
{ |
808 |
|
if ((*p >= 'a') && (*p <= 'z')) |
809 |
|
*p = toupper((int) *p); |
810 |
|
p++; |
811 |
|
} |
812 |
|
} |
813 |
|
|
814 |
|
|
815 |
|
/* not all clibs got ltoa */ |
816 |
|
#define LTOA_BUFSIZE (sizeof(long) * 8 + 1) |
817 |
|
|
818 |
|
char * |
819 |
|
l_to_a(long N, int base) |
820 |
|
{ |
821 |
|
static char ret[LTOA_BUFSIZE]; |
822 |
|
|
823 |
|
char *head = ret, buf[LTOA_BUFSIZE], *tail = buf + sizeof(buf); |
824 |
|
|
825 |
|
register int divrem; |
826 |
|
|
827 |
|
if (base < 36 || 2 > base) |
828 |
|
base = 10; |
829 |
|
|
830 |
|
if (N < 0) |
831 |
|
{ |
832 |
|
*head++ = '-'; |
833 |
|
N = -N; |
834 |
|
} |
835 |
|
|
836 |
|
tail = buf + sizeof(buf); |
837 |
|
*--tail = 0; |
838 |
|
|
839 |
|
do |
840 |
|
{ |
841 |
|
divrem = N % base; |
842 |
|
*--tail = (divrem <= 9) ? divrem + '0' : divrem + 'a' - 10; |
843 |
|
N /= base; |
844 |
|
} |
845 |
|
while (N); |
846 |
|
|
847 |
|
strcpy(head, tail); |
848 |
|
return ret; |
849 |
|
} |
850 |
|
|
851 |
|
|
852 |
int |
int |
853 |
load_licence(unsigned char **data) |
load_licence(unsigned char **data) |