1 |
/* -*- c-basic-offset: 8 -*- |
/* -*- c-basic-offset: 8 -*- |
2 |
rdesktop: A Remote Desktop Protocol client. |
rdesktop: A Remote Desktop Protocol client. |
3 |
Entrypoint and utility functions |
Entrypoint and utility functions |
4 |
Copyright (C) Matthew Chapman 1999-2005 |
Copyright (C) Matthew Chapman 1999-2008 |
5 |
|
|
6 |
This program is free software; you can redistribute it and/or modify |
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 |
it under the terms of the GNU General Public License as published by |
30 |
#include <errno.h> |
#include <errno.h> |
31 |
#include "rdesktop.h" |
#include "rdesktop.h" |
32 |
|
|
|
#ifdef HAVE_ICONV |
|
33 |
#ifdef HAVE_LOCALE_H |
#ifdef HAVE_LOCALE_H |
34 |
#include <locale.h> |
#include <locale.h> |
35 |
#endif |
#endif |
36 |
|
#ifdef HAVE_ICONV |
37 |
#ifdef HAVE_LANGINFO_H |
#ifdef HAVE_LANGINFO_H |
38 |
#include <langinfo.h> |
#include <langinfo.h> |
39 |
#endif |
#endif |
45 |
#include <sys/un.h> /* sockaddr_un */ |
#include <sys/un.h> /* sockaddr_un */ |
46 |
#endif |
#endif |
47 |
|
|
48 |
#include <openssl/md5.h> |
#include "ssl.h" |
49 |
|
|
50 |
char g_title[64] = ""; |
char g_title[64] = ""; |
51 |
char g_username[64]; |
char *g_username; |
52 |
char g_hostname[16]; |
char g_hostname[16]; |
53 |
char keymapname[16]; |
char g_keymapname[PATH_MAX] = ""; |
54 |
int g_keylayout = 0x409; /* Defaults to US keyboard layout */ |
unsigned int g_keylayout = 0x409; /* Defaults to US keyboard layout */ |
55 |
|
int g_keyboard_type = 0x4; /* Defaults to US keyboard layout */ |
56 |
|
int g_keyboard_subtype = 0x0; /* Defaults to US keyboard layout */ |
57 |
|
int g_keyboard_functionkeys = 0xc; /* Defaults to US keyboard layout */ |
58 |
|
|
59 |
int g_width = 800; /* width is special: If 0, the |
int g_width = 800; /* width is special: If 0, the |
60 |
geometry will be fetched from |
geometry will be fetched from |
69 |
2 xpos neg, |
2 xpos neg, |
70 |
4 ypos neg */ |
4 ypos neg */ |
71 |
extern int g_tcp_port_rdp; |
extern int g_tcp_port_rdp; |
72 |
int g_server_bpp = 8; |
int g_server_depth = -1; |
73 |
int g_win_button_size = 0; /* If zero, disable single app mode */ |
int g_win_button_size = 0; /* If zero, disable single app mode */ |
74 |
BOOL g_bitmap_compression = True; |
RD_BOOL g_bitmap_compression = True; |
75 |
BOOL g_sendmotion = True; |
RD_BOOL g_sendmotion = True; |
76 |
BOOL g_bitmap_cache = True; |
RD_BOOL g_bitmap_cache = True; |
77 |
BOOL g_bitmap_cache_persist_enable = False; |
RD_BOOL g_bitmap_cache_persist_enable = False; |
78 |
BOOL g_bitmap_cache_precache = True; |
RD_BOOL g_bitmap_cache_precache = True; |
79 |
BOOL g_encryption = True; |
RD_BOOL g_encryption = True; |
80 |
BOOL packet_encryption = True; |
RD_BOOL g_packet_encryption = True; |
81 |
BOOL g_desktop_save = True; /* desktop save order */ |
RD_BOOL g_desktop_save = True; /* desktop save order */ |
82 |
BOOL g_polygon_ellipse_orders = True; /* polygon / ellipse orders */ |
RD_BOOL g_polygon_ellipse_orders = True; /* polygon / ellipse orders */ |
83 |
BOOL g_fullscreen = False; |
RD_BOOL g_fullscreen = False; |
84 |
BOOL g_grab_keyboard = True; |
RD_BOOL g_grab_keyboard = True; |
85 |
BOOL g_hide_decorations = False; |
RD_BOOL g_hide_decorations = False; |
86 |
BOOL g_use_rdp5 = True; |
RD_BOOL g_use_rdp5 = True; |
87 |
BOOL g_console_session = False; |
RD_BOOL g_rdpclip = True; |
88 |
BOOL g_numlock_sync = False; |
RD_BOOL g_console_session = False; |
89 |
BOOL g_owncolmap = False; |
RD_BOOL g_numlock_sync = False; |
90 |
BOOL g_ownbackstore = True; /* We can't rely on external BackingStore */ |
RD_BOOL g_lspci_enabled = False; |
91 |
|
RD_BOOL g_owncolmap = False; |
92 |
|
RD_BOOL g_ownbackstore = True; /* We can't rely on external BackingStore */ |
93 |
|
RD_BOOL g_seamless_rdp = False; |
94 |
uint32 g_embed_wnd; |
uint32 g_embed_wnd; |
95 |
uint32 g_rdp5_performanceflags = |
uint32 g_rdp5_performanceflags = |
96 |
RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS; |
RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS; |
97 |
|
/* Session Directory redirection */ |
98 |
|
RD_BOOL g_redirect = False; |
99 |
|
char g_redirect_server[64]; |
100 |
|
char g_redirect_domain[16]; |
101 |
|
char g_redirect_password[64]; |
102 |
|
char *g_redirect_username; |
103 |
|
char g_redirect_cookie[128]; |
104 |
|
uint32 g_redirect_flags = 0; |
105 |
|
|
106 |
#ifdef WITH_RDPSND |
#ifdef WITH_RDPSND |
107 |
BOOL g_rdpsnd = False; |
RD_BOOL g_rdpsnd = False; |
108 |
#endif |
#endif |
109 |
|
|
110 |
#ifdef HAVE_ICONV |
#ifdef HAVE_ICONV |
127 |
usage(char *program) |
usage(char *program) |
128 |
{ |
{ |
129 |
fprintf(stderr, "rdesktop: A Remote Desktop Protocol client.\n"); |
fprintf(stderr, "rdesktop: A Remote Desktop Protocol client.\n"); |
130 |
fprintf(stderr, "Version " VERSION ". Copyright (C) 1999-2005 Matt Chapman.\n"); |
fprintf(stderr, "Version " VERSION ". Copyright (C) 1999-2008 Matthew Chapman.\n"); |
131 |
fprintf(stderr, "See http://www.rdesktop.org/ for more information.\n\n"); |
fprintf(stderr, "See http://www.rdesktop.org/ for more information.\n\n"); |
132 |
|
|
133 |
fprintf(stderr, "Usage: %s [options] server[:port]\n", program); |
fprintf(stderr, "Usage: %s [options] server[:port]\n", program); |
148 |
#ifdef HAVE_ICONV |
#ifdef HAVE_ICONV |
149 |
fprintf(stderr, " -L: local codepage\n"); |
fprintf(stderr, " -L: local codepage\n"); |
150 |
#endif |
#endif |
151 |
|
fprintf(stderr, " -A: enable SeamlessRDP mode\n"); |
152 |
fprintf(stderr, " -B: use BackingStore of X-server (if available)\n"); |
fprintf(stderr, " -B: use BackingStore of X-server (if available)\n"); |
153 |
fprintf(stderr, " -e: disable encryption (French TS)\n"); |
fprintf(stderr, " -e: disable encryption (French TS)\n"); |
154 |
fprintf(stderr, " -E: disable encryption from client to server\n"); |
fprintf(stderr, " -E: disable encryption from client to server\n"); |
179 |
fprintf(stderr, " '-r printer:mydeskjet': enable printer redirection\n"); |
fprintf(stderr, " '-r printer:mydeskjet': enable printer redirection\n"); |
180 |
fprintf(stderr, |
fprintf(stderr, |
181 |
" or mydeskjet=\"HP LaserJet IIIP\" to enter server driver as well\n"); |
" or mydeskjet=\"HP LaserJet IIIP\" to enter server driver as well\n"); |
182 |
fprintf(stderr, " '-r sound:[local|off|remote]': enable sound redirection\n"); |
#ifdef WITH_RDPSND |
183 |
|
fprintf(stderr, |
184 |
|
" '-r sound:[local[:driver[:device]]|off|remote]': enable sound redirection\n"); |
185 |
fprintf(stderr, " remote would leave sound on server\n"); |
fprintf(stderr, " remote would leave sound on server\n"); |
186 |
|
fprintf(stderr, " available drivers for 'local':\n"); |
187 |
|
rdpsnd_show_help(); |
188 |
|
#endif |
189 |
|
fprintf(stderr, |
190 |
|
" '-r clipboard:[off|PRIMARYCLIPBOARD|CLIPBOARD]': enable clipboard\n"); |
191 |
|
fprintf(stderr, " redirection.\n"); |
192 |
|
fprintf(stderr, |
193 |
|
" 'PRIMARYCLIPBOARD' looks at both PRIMARY and CLIPBOARD\n"); |
194 |
|
fprintf(stderr, " when sending data to server.\n"); |
195 |
|
fprintf(stderr, " 'CLIPBOARD' looks at only CLIPBOARD.\n"); |
196 |
|
#ifdef WITH_SCARD |
197 |
|
fprintf(stderr, " '-r scard[:\"Scard Name\"=\"Alias Name[;Vendor Name]\"[,...]]\n"); |
198 |
|
fprintf(stderr, " example: -r scard:\"eToken PRO 00 00\"=\"AKS ifdh 0\"\n"); |
199 |
|
fprintf(stderr, |
200 |
|
" \"eToken PRO 00 00\" -> Device in Linux/Unix enviroment\n"); |
201 |
|
fprintf(stderr, |
202 |
|
" \"AKS ifdh 0\" -> Device shown in Windows enviroment \n"); |
203 |
|
fprintf(stderr, " example: -r scard:\"eToken PRO 00 00\"=\"AKS ifdh 0;AKS\"\n"); |
204 |
|
fprintf(stderr, |
205 |
|
" \"eToken PRO 00 00\" -> Device in Linux/Unix enviroment\n"); |
206 |
|
fprintf(stderr, |
207 |
|
" \"AKS ifdh 0\" -> Device shown in Windows enviroment \n"); |
208 |
|
fprintf(stderr, |
209 |
|
" \"AKS\" -> Device vendor name \n"); |
210 |
|
#endif |
211 |
fprintf(stderr, " -0: attach to console\n"); |
fprintf(stderr, " -0: attach to console\n"); |
212 |
fprintf(stderr, " -4: use RDP version 4\n"); |
fprintf(stderr, " -4: use RDP version 4\n"); |
213 |
fprintf(stderr, " -5: use RDP version 5 (default)\n"); |
fprintf(stderr, " -5: use RDP version 5 (default)\n"); |
214 |
} |
} |
215 |
|
|
216 |
void |
static void |
217 |
print_disconnect_reason(uint16 reason) |
print_disconnect_reason(uint16 reason) |
218 |
{ |
{ |
219 |
char *text; |
char *text; |
313 |
fprintf(stderr, "disconnect: %s.\n", text); |
fprintf(stderr, "disconnect: %s.\n", text); |
314 |
} |
} |
315 |
|
|
316 |
static BOOL |
static void |
317 |
|
rdesktop_reset_state(void) |
318 |
|
{ |
319 |
|
rdp_reset_state(); |
320 |
|
} |
321 |
|
|
322 |
|
static RD_BOOL |
323 |
read_password(char *password, int size) |
read_password(char *password, int size) |
324 |
{ |
{ |
325 |
struct termios tios; |
struct termios tios; |
326 |
BOOL ret = False; |
RD_BOOL ret = False; |
327 |
int istty = 0; |
int istty = 0; |
328 |
char *p; |
char *p; |
329 |
|
|
411 |
char fullhostname[64]; |
char fullhostname[64]; |
412 |
char domain[16]; |
char domain[16]; |
413 |
char password[64]; |
char password[64]; |
414 |
char shell[128]; |
char shell[256]; |
415 |
char directory[32]; |
char directory[256]; |
416 |
BOOL prompt_password, deactivated; |
RD_BOOL prompt_password, deactivated; |
417 |
struct passwd *pw; |
struct passwd *pw; |
418 |
uint32 flags, ext_disc_reason = 0; |
uint32 flags, ext_disc_reason = 0; |
419 |
char *p; |
char *p; |
420 |
int c; |
int c; |
421 |
|
char *locale = NULL; |
422 |
int username_option = 0; |
int username_option = 0; |
423 |
|
RD_BOOL geometry_option = False; |
424 |
|
int run_count = 0; /* Session Directory support */ |
425 |
|
RD_BOOL continue_connect = True; /* Session Directory support */ |
426 |
|
#ifdef WITH_RDPSND |
427 |
|
char *rdpsnd_optarg = NULL; |
428 |
|
#endif |
429 |
|
|
430 |
|
#ifdef HAVE_LOCALE_H |
431 |
|
/* Set locale according to environment */ |
432 |
|
locale = setlocale(LC_ALL, ""); |
433 |
|
if (locale) |
434 |
|
{ |
435 |
|
locale = xstrdup(locale); |
436 |
|
} |
437 |
|
|
438 |
|
#endif |
439 |
flags = RDP_LOGON_NORMAL; |
flags = RDP_LOGON_NORMAL; |
440 |
prompt_password = False; |
prompt_password = False; |
441 |
domain[0] = password[0] = shell[0] = directory[0] = 0; |
domain[0] = password[0] = shell[0] = directory[0] = 0; |
|
strcpy(keymapname, "en-us"); |
|
442 |
g_embed_wnd = 0; |
g_embed_wnd = 0; |
443 |
|
|
444 |
g_num_devices = 0; |
g_num_devices = 0; |
450 |
#endif |
#endif |
451 |
|
|
452 |
while ((c = getopt(argc, argv, |
while ((c = getopt(argc, argv, |
453 |
VNCOPT "u:L:d:s:c:p:n:k:g:fbBeEmzCDKS:T:NX:a:x:Pr:045h?")) != -1) |
VNCOPT "Au:L:d:s:c:p:n:k:g:fbBeEmzCDKS:T:NX:a:x:Pr:045h?")) != -1) |
454 |
{ |
{ |
455 |
switch (c) |
switch (c) |
456 |
{ |
{ |
468 |
break; |
break; |
469 |
#endif |
#endif |
470 |
|
|
471 |
|
case 'A': |
472 |
|
g_seamless_rdp = True; |
473 |
|
break; |
474 |
|
|
475 |
case 'u': |
case 'u': |
476 |
STRNCPY(g_username, optarg, sizeof(g_username)); |
g_username = (char *) xmalloc(strlen(optarg) + 1); |
477 |
|
STRNCPY(g_username, optarg, strlen(optarg) + 1); |
478 |
username_option = 1; |
username_option = 1; |
479 |
break; |
break; |
480 |
|
|
519 |
break; |
break; |
520 |
|
|
521 |
case 'k': |
case 'k': |
522 |
STRNCPY(keymapname, optarg, sizeof(keymapname)); |
STRNCPY(g_keymapname, optarg, sizeof(g_keymapname)); |
523 |
break; |
break; |
524 |
|
|
525 |
case 'g': |
case 'g': |
526 |
|
geometry_option = True; |
527 |
g_fullscreen = False; |
g_fullscreen = False; |
528 |
if (!strcmp(optarg, "workarea")) |
if (!strcmp(optarg, "workarea")) |
529 |
{ |
{ |
583 |
g_encryption = False; |
g_encryption = False; |
584 |
break; |
break; |
585 |
case 'E': |
case 'E': |
586 |
packet_encryption = False; |
g_packet_encryption = False; |
587 |
break; |
break; |
588 |
case 'm': |
case 'm': |
589 |
g_sendmotion = False; |
g_sendmotion = False; |
631 |
break; |
break; |
632 |
|
|
633 |
case 'a': |
case 'a': |
634 |
g_server_bpp = strtol(optarg, NULL, 10); |
g_server_depth = strtol(optarg, NULL, 10); |
635 |
if (g_server_bpp != 8 && g_server_bpp != 16 && g_server_bpp != 15 |
if (g_server_depth != 8 && |
636 |
&& g_server_bpp != 24) |
g_server_depth != 16 && |
637 |
|
g_server_depth != 15 && g_server_depth != 24 |
638 |
|
&& g_server_depth != 32) |
639 |
{ |
{ |
640 |
error("invalid server bpp\n"); |
error("Invalid server colour depth.\n"); |
641 |
return 1; |
return 1; |
642 |
} |
} |
643 |
break; |
break; |
644 |
|
|
645 |
case 'z': |
case 'z': |
646 |
DEBUG(("rdp compression enabled\n")); |
DEBUG(("rdp compression enabled\n")); |
647 |
flags |= RDP_COMPRESSION; |
flags |= (RDP_LOGON_COMPRESSION | RDP_LOGON_COMPRESSION2); |
648 |
break; |
break; |
649 |
|
|
650 |
case 'x': |
case 'x': |
651 |
if (strncmp("modem", optarg, 1) == 0) |
if (str_startswith(optarg, "m")) /* modem */ |
652 |
{ |
{ |
653 |
g_rdp5_performanceflags = |
g_rdp5_performanceflags = |
654 |
RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | |
RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | |
655 |
RDP5_NO_MENUANIMATIONS | RDP5_NO_THEMING; |
RDP5_NO_MENUANIMATIONS | RDP5_NO_THEMING; |
656 |
} |
} |
657 |
else if (strncmp("broadband", optarg, 1) == 0) |
else if (str_startswith(optarg, "b")) /* broadband */ |
658 |
{ |
{ |
659 |
g_rdp5_performanceflags = RDP5_NO_WALLPAPER; |
g_rdp5_performanceflags = RDP5_NO_WALLPAPER; |
660 |
} |
} |
661 |
else if (strncmp("lan", optarg, 1) == 0) |
else if (str_startswith(optarg, "l")) /* lan */ |
662 |
{ |
{ |
663 |
g_rdp5_performanceflags = RDP5_DISABLE_NOTHING; |
g_rdp5_performanceflags = RDP5_DISABLE_NOTHING; |
664 |
} |
} |
674 |
|
|
675 |
case 'r': |
case 'r': |
676 |
|
|
677 |
if (strncmp("sound", optarg, 5) == 0) |
if (str_startswith(optarg, "sound")) |
678 |
{ |
{ |
679 |
optarg += 5; |
optarg += 5; |
680 |
|
|
681 |
if (*optarg == ':') |
if (*optarg == ':') |
682 |
{ |
{ |
683 |
*optarg++; |
optarg++; |
684 |
while ((p = next_arg(optarg, ','))) |
while ((p = next_arg(optarg, ','))) |
685 |
{ |
{ |
686 |
if (strncmp("remote", optarg, 6) == 0) |
if (str_startswith(optarg, "remote")) |
687 |
flags |= RDP_LOGON_LEAVE_AUDIO; |
flags |= RDP_LOGON_LEAVE_AUDIO; |
688 |
|
|
689 |
if (strncmp("local", optarg, 5) == 0) |
if (str_startswith(optarg, "local")) |
690 |
#ifdef WITH_RDPSND |
#ifdef WITH_RDPSND |
691 |
|
{ |
692 |
|
rdpsnd_optarg = |
693 |
|
next_arg(optarg, ':'); |
694 |
g_rdpsnd = True; |
g_rdpsnd = True; |
695 |
|
} |
696 |
|
|
697 |
#else |
#else |
698 |
warning("Not compiled with sound support\n"); |
warning("Not compiled with sound support\n"); |
699 |
#endif |
#endif |
700 |
|
|
701 |
if (strncmp("off", optarg, 3) == 0) |
if (str_startswith(optarg, "off")) |
702 |
#ifdef WITH_RDPSND |
#ifdef WITH_RDPSND |
703 |
g_rdpsnd = False; |
g_rdpsnd = False; |
704 |
#else |
#else |
717 |
#endif |
#endif |
718 |
} |
} |
719 |
} |
} |
720 |
else if (strncmp("disk", optarg, 4) == 0) |
else if (str_startswith(optarg, "disk")) |
721 |
{ |
{ |
722 |
/* -r disk:h:=/mnt/floppy */ |
/* -r disk:h:=/mnt/floppy */ |
723 |
disk_enum_devices(&g_num_devices, optarg + 4); |
disk_enum_devices(&g_num_devices, optarg + 4); |
724 |
} |
} |
725 |
else if (strncmp("comport", optarg, 7) == 0) |
else if (str_startswith(optarg, "comport")) |
726 |
{ |
{ |
727 |
serial_enum_devices(&g_num_devices, optarg + 7); |
serial_enum_devices(&g_num_devices, optarg + 7); |
728 |
} |
} |
729 |
else if (strncmp("lptport", optarg, 7) == 0) |
else if (str_startswith(optarg, "lspci")) |
730 |
|
{ |
731 |
|
g_lspci_enabled = True; |
732 |
|
} |
733 |
|
else if (str_startswith(optarg, "lptport")) |
734 |
{ |
{ |
735 |
parallel_enum_devices(&g_num_devices, optarg + 7); |
parallel_enum_devices(&g_num_devices, optarg + 7); |
736 |
} |
} |
737 |
else if (strncmp("printer", optarg, 7) == 0) |
else if (str_startswith(optarg, "printer")) |
738 |
{ |
{ |
739 |
printer_enum_devices(&g_num_devices, optarg + 7); |
printer_enum_devices(&g_num_devices, optarg + 7); |
740 |
} |
} |
741 |
else if (strncmp("clientname", optarg, 7) == 0) |
else if (str_startswith(optarg, "clientname")) |
742 |
{ |
{ |
743 |
g_rdpdr_clientname = xmalloc(strlen(optarg + 11) + 1); |
g_rdpdr_clientname = xmalloc(strlen(optarg + 11) + 1); |
744 |
strcpy(g_rdpdr_clientname, optarg + 11); |
strcpy(g_rdpdr_clientname, optarg + 11); |
745 |
} |
} |
746 |
|
else if (str_startswith(optarg, "clipboard")) |
747 |
|
{ |
748 |
|
optarg += 9; |
749 |
|
|
750 |
|
if (*optarg == ':') |
751 |
|
{ |
752 |
|
optarg++; |
753 |
|
|
754 |
|
if (str_startswith(optarg, "off")) |
755 |
|
g_rdpclip = False; |
756 |
|
else |
757 |
|
cliprdr_set_mode(optarg); |
758 |
|
} |
759 |
|
else |
760 |
|
g_rdpclip = True; |
761 |
|
} |
762 |
|
else if (strncmp("scard", optarg, 5) == 0) |
763 |
|
{ |
764 |
|
#ifdef WITH_SCARD |
765 |
|
scard_enum_devices(&g_num_devices, optarg + 5); |
766 |
|
#else |
767 |
|
warning("Not compiled with smartcard support\n"); |
768 |
|
#endif |
769 |
|
} |
770 |
else |
else |
771 |
{ |
{ |
772 |
warning("Unknown -r argument\n\n\tPossible arguments are: comport, disk, lptport, printer, sound\n"); |
warning("Unknown -r argument\n\n\tPossible arguments are: comport, disk, lptport, printer, sound, clipboard, scard\n"); |
773 |
} |
} |
774 |
break; |
break; |
775 |
|
|
802 |
STRNCPY(server, argv[optind], sizeof(server)); |
STRNCPY(server, argv[optind], sizeof(server)); |
803 |
parse_server_and_port(server); |
parse_server_and_port(server); |
804 |
|
|
805 |
|
if (g_seamless_rdp) |
806 |
|
{ |
807 |
|
if (g_win_button_size) |
808 |
|
{ |
809 |
|
error("You cannot use -S and -A at the same time\n"); |
810 |
|
return 1; |
811 |
|
} |
812 |
|
g_rdp5_performanceflags &= ~RDP5_NO_FULLWINDOWDRAG; |
813 |
|
if (geometry_option) |
814 |
|
{ |
815 |
|
error("You cannot use -g and -A at the same time\n"); |
816 |
|
return 1; |
817 |
|
} |
818 |
|
if (g_fullscreen) |
819 |
|
{ |
820 |
|
error("You cannot use -f and -A at the same time\n"); |
821 |
|
return 1; |
822 |
|
} |
823 |
|
if (g_hide_decorations) |
824 |
|
{ |
825 |
|
error("You cannot use -D and -A at the same time\n"); |
826 |
|
return 1; |
827 |
|
} |
828 |
|
if (g_embed_wnd) |
829 |
|
{ |
830 |
|
error("You cannot use -X and -A at the same time\n"); |
831 |
|
return 1; |
832 |
|
} |
833 |
|
if (!g_use_rdp5) |
834 |
|
{ |
835 |
|
error("You cannot use -4 and -A at the same time\n"); |
836 |
|
return 1; |
837 |
|
} |
838 |
|
g_width = -100; |
839 |
|
g_grab_keyboard = False; |
840 |
|
} |
841 |
|
|
842 |
if (!username_option) |
if (!username_option) |
843 |
{ |
{ |
844 |
pw = getpwuid(getuid()); |
pw = getpwuid(getuid()); |
847 |
error("could not determine username, use -u\n"); |
error("could not determine username, use -u\n"); |
848 |
return 1; |
return 1; |
849 |
} |
} |
850 |
|
/* +1 for trailing \0 */ |
851 |
STRNCPY(g_username, pw->pw_name, sizeof(g_username)); |
int pwlen = strlen(pw->pw_name) + 1; |
852 |
|
g_username = (char *) xmalloc(pwlen); |
853 |
|
STRNCPY(g_username, pw->pw_name, pwlen); |
854 |
} |
} |
855 |
|
|
856 |
#ifdef HAVE_ICONV |
#ifdef HAVE_ICONV |
882 |
STRNCPY(g_hostname, fullhostname, sizeof(g_hostname)); |
STRNCPY(g_hostname, fullhostname, sizeof(g_hostname)); |
883 |
} |
} |
884 |
|
|
885 |
if ((flags & RDP_COMPRESSION) && (g_server_bpp > 8)) |
if (g_keymapname[0] == 0) |
886 |
{ |
{ |
887 |
warning("rdp compression not supported for bpp > 8, compression disabled\n"); |
if (locale && xkeymap_from_locale(locale)) |
888 |
flags ^= RDP_COMPRESSION; |
{ |
889 |
|
fprintf(stderr, "Autoselected keyboard map %s\n", g_keymapname); |
890 |
|
} |
891 |
|
else |
892 |
|
{ |
893 |
|
STRNCPY(g_keymapname, "en-us", sizeof(g_keymapname)); |
894 |
|
} |
895 |
} |
} |
896 |
|
if (locale) |
897 |
|
xfree(locale); |
898 |
|
|
899 |
|
|
900 |
if (prompt_password && read_password(password, sizeof(password))) |
if (prompt_password && read_password(password, sizeof(password))) |
901 |
flags |= RDP_LOGON_AUTO; |
flags |= RDP_LOGON_AUTO; |
916 |
|
|
917 |
#ifdef WITH_RDPSND |
#ifdef WITH_RDPSND |
918 |
if (g_rdpsnd) |
if (g_rdpsnd) |
919 |
rdpsnd_init(); |
{ |
920 |
|
if (!rdpsnd_init(rdpsnd_optarg)) |
921 |
|
{ |
922 |
|
warning("Initializing sound-support failed!\n"); |
923 |
|
} |
924 |
|
} |
925 |
#endif |
#endif |
926 |
|
|
927 |
|
if (g_lspci_enabled) |
928 |
|
lspci_init(); |
929 |
|
|
930 |
rdpdr_init(); |
rdpdr_init(); |
931 |
|
|
932 |
if (!rdp_connect(server, flags, domain, password, shell, directory)) |
while (run_count < 2 && continue_connect) /* add support for Session Directory; only reconnect once */ |
933 |
return 1; |
{ |
934 |
|
if (run_count == 0) |
935 |
|
{ |
936 |
|
if (!rdp_connect(server, flags, domain, password, shell, directory)) |
937 |
|
return 1; |
938 |
|
} |
939 |
|
else if (!rdp_reconnect |
940 |
|
(server, flags, domain, password, shell, directory, g_redirect_cookie)) |
941 |
|
return 1; |
942 |
|
|
943 |
/* By setting encryption to False here, we have an encrypted login |
/* By setting encryption to False here, we have an encrypted login |
944 |
packet but unencrypted transfer of other packets */ |
packet but unencrypted transfer of other packets */ |
945 |
if (!packet_encryption) |
if (!g_packet_encryption) |
946 |
g_encryption = False; |
g_encryption = False; |
947 |
|
|
948 |
|
|
949 |
DEBUG(("Connection successful.\n")); |
DEBUG(("Connection successful.\n")); |
950 |
memset(password, 0, sizeof(password)); |
memset(password, 0, sizeof(password)); |
951 |
|
|
952 |
if (ui_create_window()) |
if (run_count == 0) |
953 |
{ |
if (!ui_create_window()) |
954 |
rdp_main_loop(&deactivated, &ext_disc_reason); |
continue_connect = False; |
955 |
ui_destroy_window(); |
|
956 |
|
if (continue_connect) |
957 |
|
rdp_main_loop(&deactivated, &ext_disc_reason); |
958 |
|
|
959 |
|
DEBUG(("Disconnecting...\n")); |
960 |
|
rdp_disconnect(); |
961 |
|
|
962 |
|
if ((g_redirect == True) && (run_count == 0)) /* Support for Session Directory */ |
963 |
|
{ |
964 |
|
/* reset state of major globals */ |
965 |
|
rdesktop_reset_state(); |
966 |
|
|
967 |
|
STRNCPY(domain, g_redirect_domain, sizeof(domain)); |
968 |
|
xfree(g_username); |
969 |
|
g_username = (char *) xmalloc(strlen(g_redirect_username) + 1); |
970 |
|
STRNCPY(g_username, g_redirect_username, sizeof(g_username)); |
971 |
|
STRNCPY(password, g_redirect_password, sizeof(password)); |
972 |
|
STRNCPY(server, g_redirect_server, sizeof(server)); |
973 |
|
flags |= RDP_LOGON_AUTO; |
974 |
|
|
975 |
|
g_redirect = False; |
976 |
|
} |
977 |
|
else |
978 |
|
{ |
979 |
|
continue_connect = False; |
980 |
|
ui_destroy_window(); |
981 |
|
break; |
982 |
|
} |
983 |
|
|
984 |
|
run_count++; |
985 |
} |
} |
986 |
|
|
|
DEBUG(("Disconnecting...\n")); |
|
|
rdp_disconnect(); |
|
987 |
cache_save_state(); |
cache_save_state(); |
988 |
ui_deinit(); |
ui_deinit(); |
989 |
|
|
1011 |
} |
} |
1012 |
|
|
1013 |
#endif |
#endif |
1014 |
|
if (g_redirect_username) |
1015 |
|
xfree(g_redirect_username); |
1016 |
|
|
1017 |
|
xfree(g_username); |
1018 |
} |
} |
1019 |
|
|
1020 |
#ifdef EGD_SOCKET |
#ifdef EGD_SOCKET |
1021 |
/* Read 32 random bytes from PRNGD or EGD socket (based on OpenSSL RAND_egd) */ |
/* Read 32 random bytes from PRNGD or EGD socket (based on OpenSSL RAND_egd) */ |
1022 |
static BOOL |
static RD_BOOL |
1023 |
generate_random_egd(uint8 * buf) |
generate_random_egd(uint8 * buf) |
1024 |
{ |
{ |
1025 |
struct sockaddr_un addr; |
struct sockaddr_un addr; |
1026 |
BOOL ret = False; |
RD_BOOL ret = False; |
1027 |
int fd; |
int fd; |
1028 |
|
|
1029 |
fd = socket(AF_UNIX, SOCK_STREAM, 0); |
fd = socket(AF_UNIX, SOCK_STREAM, 0); |
1061 |
{ |
{ |
1062 |
struct stat st; |
struct stat st; |
1063 |
struct tms tmsbuf; |
struct tms tmsbuf; |
1064 |
MD5_CTX md5; |
SSL_MD5 md5; |
1065 |
uint32 *r; |
uint32 *r; |
1066 |
int fd, n; |
int fd, n; |
1067 |
|
|
1093 |
r[7] = st.st_ctime; |
r[7] = st.st_ctime; |
1094 |
|
|
1095 |
/* Hash both halves with MD5 to obscure possible patterns */ |
/* Hash both halves with MD5 to obscure possible patterns */ |
1096 |
MD5_Init(&md5); |
ssl_md5_init(&md5); |
1097 |
MD5_Update(&md5, random, 16); |
ssl_md5_update(&md5, random, 16); |
1098 |
MD5_Final(random, &md5); |
ssl_md5_final(&md5, random); |
1099 |
MD5_Update(&md5, random + 16, 16); |
ssl_md5_update(&md5, random + 16, 16); |
1100 |
MD5_Final(random + 16, &md5); |
ssl_md5_final(&md5, random + 16); |
1101 |
} |
} |
1102 |
|
|
1103 |
/* malloc; exit if out of memory */ |
/* malloc; exit if out of memory */ |
1113 |
return mem; |
return mem; |
1114 |
} |
} |
1115 |
|
|
1116 |
|
/* Exit on NULL pointer. Use to verify result from XGetImage etc */ |
1117 |
|
void |
1118 |
|
exit_if_null(void *ptr) |
1119 |
|
{ |
1120 |
|
if (ptr == NULL) |
1121 |
|
{ |
1122 |
|
error("unexpected null pointer. Out of memory?\n"); |
1123 |
|
exit(1); |
1124 |
|
} |
1125 |
|
} |
1126 |
|
|
1127 |
|
/* strdup */ |
1128 |
|
char * |
1129 |
|
xstrdup(const char *s) |
1130 |
|
{ |
1131 |
|
char *mem = strdup(s); |
1132 |
|
if (mem == NULL) |
1133 |
|
{ |
1134 |
|
perror("strdup"); |
1135 |
|
exit(1); |
1136 |
|
} |
1137 |
|
return mem; |
1138 |
|
} |
1139 |
|
|
1140 |
/* realloc; exit if out of memory */ |
/* realloc; exit if out of memory */ |
1141 |
void * |
void * |
1142 |
xrealloc(void *oldmem, int size) |
xrealloc(void *oldmem, size_t size) |
1143 |
{ |
{ |
1144 |
void *mem; |
void *mem; |
1145 |
|
|
1146 |
if (size < 1) |
if (size == 0) |
1147 |
size = 1; |
size = 1; |
1148 |
mem = realloc(oldmem, size); |
mem = realloc(oldmem, size); |
1149 |
if (mem == NULL) |
if (mem == NULL) |
1150 |
{ |
{ |
1151 |
error("xrealloc %d\n", size); |
error("xrealloc %ld\n", size); |
1152 |
exit(1); |
exit(1); |
1153 |
} |
} |
1154 |
return mem; |
return mem; |
1272 |
while (*(mvp + 1) != (char) 0x00) |
while (*(mvp + 1) != (char) 0x00) |
1273 |
{ |
{ |
1274 |
*mvp = *(mvp + 1); |
*mvp = *(mvp + 1); |
1275 |
*mvp++; |
mvp++; |
1276 |
} |
} |
1277 |
*mvp = (char) 0x00; |
*mvp = (char) 0x00; |
1278 |
p = nextval; |
p = nextval; |
1310 |
} |
} |
1311 |
|
|
1312 |
|
|
1313 |
|
RD_BOOL |
1314 |
|
str_startswith(const char *s, const char *prefix) |
1315 |
|
{ |
1316 |
|
return (strncmp(s, prefix, strlen(prefix)) == 0); |
1317 |
|
} |
1318 |
|
|
1319 |
|
|
1320 |
|
/* Split input into lines, and call linehandler for each |
1321 |
|
line. Incomplete lines are saved in the rest variable, which should |
1322 |
|
initially point to NULL. When linehandler returns False, stop and |
1323 |
|
return False. Otherwise, return True. */ |
1324 |
|
RD_BOOL |
1325 |
|
str_handle_lines(const char *input, char **rest, str_handle_lines_t linehandler, void *data) |
1326 |
|
{ |
1327 |
|
char *buf, *p; |
1328 |
|
char *oldrest; |
1329 |
|
size_t inputlen; |
1330 |
|
size_t buflen; |
1331 |
|
size_t restlen = 0; |
1332 |
|
RD_BOOL ret = True; |
1333 |
|
|
1334 |
|
/* Copy data to buffer */ |
1335 |
|
inputlen = strlen(input); |
1336 |
|
if (*rest) |
1337 |
|
restlen = strlen(*rest); |
1338 |
|
buflen = restlen + inputlen + 1; |
1339 |
|
buf = (char *) xmalloc(buflen); |
1340 |
|
buf[0] = '\0'; |
1341 |
|
if (*rest) |
1342 |
|
STRNCPY(buf, *rest, buflen); |
1343 |
|
strncat(buf, input, inputlen); |
1344 |
|
p = buf; |
1345 |
|
|
1346 |
|
while (1) |
1347 |
|
{ |
1348 |
|
char *newline = strchr(p, '\n'); |
1349 |
|
if (newline) |
1350 |
|
{ |
1351 |
|
*newline = '\0'; |
1352 |
|
if (!linehandler(p, data)) |
1353 |
|
{ |
1354 |
|
p = newline + 1; |
1355 |
|
ret = False; |
1356 |
|
break; |
1357 |
|
} |
1358 |
|
p = newline + 1; |
1359 |
|
} |
1360 |
|
else |
1361 |
|
{ |
1362 |
|
break; |
1363 |
|
|
1364 |
|
} |
1365 |
|
} |
1366 |
|
|
1367 |
|
/* Save in rest */ |
1368 |
|
oldrest = *rest; |
1369 |
|
restlen = buf + buflen - p; |
1370 |
|
*rest = (char *) xmalloc(restlen); |
1371 |
|
STRNCPY((*rest), p, restlen); |
1372 |
|
xfree(oldrest); |
1373 |
|
|
1374 |
|
xfree(buf); |
1375 |
|
return ret; |
1376 |
|
} |
1377 |
|
|
1378 |
|
/* Execute the program specified by argv. For each line in |
1379 |
|
stdout/stderr output, call linehandler. Returns false on failure. */ |
1380 |
|
RD_BOOL |
1381 |
|
subprocess(char *const argv[], str_handle_lines_t linehandler, void *data) |
1382 |
|
{ |
1383 |
|
pid_t child; |
1384 |
|
int fd[2]; |
1385 |
|
int n = 1; |
1386 |
|
char output[256]; |
1387 |
|
char *rest = NULL; |
1388 |
|
|
1389 |
|
if (pipe(fd) < 0) |
1390 |
|
{ |
1391 |
|
perror("pipe"); |
1392 |
|
return False; |
1393 |
|
} |
1394 |
|
|
1395 |
|
if ((child = fork()) < 0) |
1396 |
|
{ |
1397 |
|
perror("fork"); |
1398 |
|
return False; |
1399 |
|
} |
1400 |
|
|
1401 |
|
/* Child */ |
1402 |
|
if (child == 0) |
1403 |
|
{ |
1404 |
|
/* Close read end */ |
1405 |
|
close(fd[0]); |
1406 |
|
|
1407 |
|
/* Redirect stdout and stderr to pipe */ |
1408 |
|
dup2(fd[1], 1); |
1409 |
|
dup2(fd[1], 2); |
1410 |
|
|
1411 |
|
/* Execute */ |
1412 |
|
execvp(argv[0], argv); |
1413 |
|
perror("Error executing child"); |
1414 |
|
_exit(128); |
1415 |
|
} |
1416 |
|
|
1417 |
|
/* Parent. Close write end. */ |
1418 |
|
close(fd[1]); |
1419 |
|
while (n > 0) |
1420 |
|
{ |
1421 |
|
n = read(fd[0], output, 255); |
1422 |
|
output[n] = '\0'; |
1423 |
|
str_handle_lines(output, &rest, linehandler, data); |
1424 |
|
} |
1425 |
|
xfree(rest); |
1426 |
|
|
1427 |
|
return True; |
1428 |
|
} |
1429 |
|
|
1430 |
|
|
1431 |
/* not all clibs got ltoa */ |
/* not all clibs got ltoa */ |
1432 |
#define LTOA_BUFSIZE (sizeof(long) * 8 + 1) |
#define LTOA_BUFSIZE (sizeof(long) * 8 + 1) |
1433 |
|
|
1543 |
} |
} |
1544 |
|
|
1545 |
/* Create the bitmap cache directory */ |
/* Create the bitmap cache directory */ |
1546 |
BOOL |
RD_BOOL |
1547 |
rd_pstcache_mkdir(void) |
rd_pstcache_mkdir(void) |
1548 |
{ |
{ |
1549 |
char *home; |
char *home; |
1620 |
} |
} |
1621 |
|
|
1622 |
/* do a write lock on a file */ |
/* do a write lock on a file */ |
1623 |
BOOL |
RD_BOOL |
1624 |
rd_lock_file(int fd, int start, int len) |
rd_lock_file(int fd, int start, int len) |
1625 |
{ |
{ |
1626 |
struct flock lock; |
struct flock lock; |