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 |
50 |
char g_title[64] = ""; |
char g_title[64] = ""; |
51 |
char g_username[64]; |
char g_username[64]; |
52 |
char g_hostname[16]; |
char g_hostname[16]; |
53 |
char keymapname[PATH_MAX]; |
char g_keymapname[PATH_MAX] = ""; |
54 |
int g_keylayout = 0x409; /* Defaults to US keyboard layout */ |
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 |
91 |
uint32 g_embed_wnd; |
uint32 g_embed_wnd; |
92 |
uint32 g_rdp5_performanceflags = |
uint32 g_rdp5_performanceflags = |
93 |
RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS; |
RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS; |
94 |
|
/* Session Directory redirection */ |
95 |
|
BOOL g_redirect = False; |
96 |
|
char g_redirect_server[64]; |
97 |
|
char g_redirect_domain[16]; |
98 |
|
char g_redirect_password[64]; |
99 |
|
char g_redirect_username[64]; |
100 |
|
char g_redirect_cookie[128]; |
101 |
|
uint32 g_redirect_flags = 0; |
102 |
|
|
103 |
#ifdef WITH_RDPSND |
#ifdef WITH_RDPSND |
104 |
BOOL g_rdpsnd = False; |
BOOL g_rdpsnd = False; |
282 |
fprintf(stderr, "disconnect: %s.\n", text); |
fprintf(stderr, "disconnect: %s.\n", text); |
283 |
} |
} |
284 |
|
|
285 |
|
static void |
286 |
|
rdesktop_reset_state(void) |
287 |
|
{ |
288 |
|
rdp_reset_state(); |
289 |
|
} |
290 |
|
|
291 |
static BOOL |
static BOOL |
292 |
read_password(char *password, int size) |
read_password(char *password, int size) |
293 |
{ |
{ |
387 |
uint32 flags, ext_disc_reason = 0; |
uint32 flags, ext_disc_reason = 0; |
388 |
char *p; |
char *p; |
389 |
int c; |
int c; |
390 |
|
char *locale = NULL; |
391 |
int username_option = 0; |
int username_option = 0; |
392 |
|
int run_count = 0; /* Session Directory support */ |
393 |
|
BOOL continue_connect = True; /* Session Directory support */ |
394 |
|
|
395 |
|
#ifdef HAVE_LOCALE_H |
396 |
|
/* Set locale according to environment */ |
397 |
|
locale = setlocale(LC_ALL, ""); |
398 |
|
if (locale) |
399 |
|
{ |
400 |
|
locale = xstrdup(locale); |
401 |
|
} |
402 |
|
|
403 |
|
#endif |
404 |
flags = RDP_LOGON_NORMAL; |
flags = RDP_LOGON_NORMAL; |
405 |
prompt_password = False; |
prompt_password = False; |
406 |
domain[0] = password[0] = shell[0] = directory[0] = 0; |
domain[0] = password[0] = shell[0] = directory[0] = 0; |
|
strcpy(keymapname, "en-us"); |
|
407 |
g_embed_wnd = 0; |
g_embed_wnd = 0; |
408 |
|
|
409 |
g_num_devices = 0; |
g_num_devices = 0; |
479 |
break; |
break; |
480 |
|
|
481 |
case 'k': |
case 'k': |
482 |
STRNCPY(keymapname, optarg, sizeof(keymapname)); |
STRNCPY(g_keymapname, optarg, sizeof(g_keymapname)); |
483 |
break; |
break; |
484 |
|
|
485 |
case 'g': |
case 'g': |
605 |
break; |
break; |
606 |
|
|
607 |
case 'x': |
case 'x': |
608 |
if (strncmp("modem", optarg, 1) == 0) |
if (str_startswith(optarg, "m")) /* modem */ |
609 |
{ |
{ |
610 |
g_rdp5_performanceflags = |
g_rdp5_performanceflags = |
611 |
RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | |
RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | |
612 |
RDP5_NO_MENUANIMATIONS | RDP5_NO_THEMING; |
RDP5_NO_MENUANIMATIONS | RDP5_NO_THEMING; |
613 |
} |
} |
614 |
else if (strncmp("broadband", optarg, 1) == 0) |
else if (str_startswith(optarg, "b")) /* broadband */ |
615 |
{ |
{ |
616 |
g_rdp5_performanceflags = RDP5_NO_WALLPAPER; |
g_rdp5_performanceflags = RDP5_NO_WALLPAPER; |
617 |
} |
} |
618 |
else if (strncmp("lan", optarg, 1) == 0) |
else if (str_startswith(optarg, "l")) /* lan */ |
619 |
{ |
{ |
620 |
g_rdp5_performanceflags = RDP5_DISABLE_NOTHING; |
g_rdp5_performanceflags = RDP5_DISABLE_NOTHING; |
621 |
} |
} |
631 |
|
|
632 |
case 'r': |
case 'r': |
633 |
|
|
634 |
if (strncmp("sound", optarg, 5) == 0) |
if (str_startswith(optarg, "sound")) |
635 |
{ |
{ |
636 |
optarg += 5; |
optarg += 5; |
637 |
|
|
640 |
*optarg++; |
*optarg++; |
641 |
while ((p = next_arg(optarg, ','))) |
while ((p = next_arg(optarg, ','))) |
642 |
{ |
{ |
643 |
if (strncmp("remote", optarg, 6) == 0) |
if (str_startswith(optarg, "remote")) |
644 |
flags |= RDP_LOGON_LEAVE_AUDIO; |
flags |= RDP_LOGON_LEAVE_AUDIO; |
645 |
|
|
646 |
if (strncmp("local", optarg, 5) == 0) |
if (str_startswith(optarg, "local")) |
647 |
#ifdef WITH_RDPSND |
#ifdef WITH_RDPSND |
648 |
g_rdpsnd = True; |
g_rdpsnd = True; |
649 |
#else |
#else |
650 |
warning("Not compiled with sound support\n"); |
warning("Not compiled with sound support\n"); |
651 |
#endif |
#endif |
652 |
|
|
653 |
if (strncmp("off", optarg, 3) == 0) |
if (str_startswith(optarg, "off")) |
654 |
#ifdef WITH_RDPSND |
#ifdef WITH_RDPSND |
655 |
g_rdpsnd = False; |
g_rdpsnd = False; |
656 |
#else |
#else |
669 |
#endif |
#endif |
670 |
} |
} |
671 |
} |
} |
672 |
else if (strncmp("disk", optarg, 4) == 0) |
else if (str_startswith(optarg, "disk")) |
673 |
{ |
{ |
674 |
/* -r disk:h:=/mnt/floppy */ |
/* -r disk:h:=/mnt/floppy */ |
675 |
disk_enum_devices(&g_num_devices, optarg + 4); |
disk_enum_devices(&g_num_devices, optarg + 4); |
676 |
} |
} |
677 |
else if (strncmp("comport", optarg, 7) == 0) |
else if (str_startswith(optarg, "comport")) |
678 |
{ |
{ |
679 |
serial_enum_devices(&g_num_devices, optarg + 7); |
serial_enum_devices(&g_num_devices, optarg + 7); |
680 |
} |
} |
681 |
else if (strncmp("lptport", optarg, 7) == 0) |
else if (str_startswith(optarg, "lptport")) |
682 |
{ |
{ |
683 |
parallel_enum_devices(&g_num_devices, optarg + 7); |
parallel_enum_devices(&g_num_devices, optarg + 7); |
684 |
} |
} |
685 |
else if (strncmp("printer", optarg, 7) == 0) |
else if (str_startswith(optarg, "printer")) |
686 |
{ |
{ |
687 |
printer_enum_devices(&g_num_devices, optarg + 7); |
printer_enum_devices(&g_num_devices, optarg + 7); |
688 |
} |
} |
689 |
else if (strncmp("clientname", optarg, 7) == 0) |
else if (str_startswith(optarg, "clientname")) |
690 |
{ |
{ |
691 |
g_rdpdr_clientname = xmalloc(strlen(optarg + 11) + 1); |
g_rdpdr_clientname = xmalloc(strlen(optarg + 11) + 1); |
692 |
strcpy(g_rdpdr_clientname, optarg + 11); |
strcpy(g_rdpdr_clientname, optarg + 11); |
767 |
STRNCPY(g_hostname, fullhostname, sizeof(g_hostname)); |
STRNCPY(g_hostname, fullhostname, sizeof(g_hostname)); |
768 |
} |
} |
769 |
|
|
770 |
|
if (g_keymapname[0] == 0) |
771 |
|
{ |
772 |
|
if (locale && xkeymap_from_locale(locale)) |
773 |
|
{ |
774 |
|
fprintf(stderr, "Autoselected keyboard map %s\n", g_keymapname); |
775 |
|
} |
776 |
|
else |
777 |
|
{ |
778 |
|
STRNCPY(g_keymapname, "en-us", sizeof(g_keymapname)); |
779 |
|
} |
780 |
|
} |
781 |
|
if (locale) |
782 |
|
xfree(locale); |
783 |
|
|
784 |
|
|
785 |
if (prompt_password && read_password(password, sizeof(password))) |
if (prompt_password && read_password(password, sizeof(password))) |
786 |
flags |= RDP_LOGON_AUTO; |
flags |= RDP_LOGON_AUTO; |
787 |
|
|
805 |
#endif |
#endif |
806 |
rdpdr_init(); |
rdpdr_init(); |
807 |
|
|
808 |
if (!rdp_connect(server, flags, domain, password, shell, directory)) |
while (run_count < 2 && continue_connect) /* add support for Session Directory; only reconnect once */ |
809 |
return 1; |
{ |
810 |
|
if (run_count == 0) |
811 |
|
{ |
812 |
|
if (!rdp_connect(server, flags, domain, password, shell, directory)) |
813 |
|
return 1; |
814 |
|
} |
815 |
|
else if (!rdp_reconnect |
816 |
|
(server, flags, domain, password, shell, directory, g_redirect_cookie)) |
817 |
|
return 1; |
818 |
|
|
819 |
/* By setting encryption to False here, we have an encrypted login |
/* By setting encryption to False here, we have an encrypted login |
820 |
packet but unencrypted transfer of other packets */ |
packet but unencrypted transfer of other packets */ |
821 |
if (!packet_encryption) |
if (!packet_encryption) |
822 |
g_encryption = False; |
g_encryption = False; |
823 |
|
|
824 |
|
|
825 |
DEBUG(("Connection successful.\n")); |
DEBUG(("Connection successful.\n")); |
826 |
memset(password, 0, sizeof(password)); |
memset(password, 0, sizeof(password)); |
827 |
|
|
828 |
if (ui_create_window()) |
if (run_count == 0) |
829 |
{ |
if (!ui_create_window()) |
830 |
rdp_main_loop(&deactivated, &ext_disc_reason); |
continue_connect = False; |
831 |
ui_destroy_window(); |
|
832 |
|
if (continue_connect) |
833 |
|
rdp_main_loop(&deactivated, &ext_disc_reason); |
834 |
|
|
835 |
|
DEBUG(("Disconnecting...\n")); |
836 |
|
rdp_disconnect(); |
837 |
|
|
838 |
|
if ((g_redirect == True) && (run_count == 0)) /* Support for Session Directory */ |
839 |
|
{ |
840 |
|
/* reset state of major globals */ |
841 |
|
rdesktop_reset_state(); |
842 |
|
|
843 |
|
STRNCPY(domain, g_redirect_domain, sizeof(domain)); |
844 |
|
STRNCPY(g_username, g_redirect_username, sizeof(g_username)); |
845 |
|
STRNCPY(password, g_redirect_password, sizeof(password)); |
846 |
|
STRNCPY(server, g_redirect_server, sizeof(server)); |
847 |
|
flags |= RDP_LOGON_AUTO; |
848 |
|
|
849 |
|
g_redirect = False; |
850 |
|
} |
851 |
|
else |
852 |
|
{ |
853 |
|
continue_connect = False; |
854 |
|
ui_destroy_window(); |
855 |
|
break; |
856 |
|
} |
857 |
|
|
858 |
|
run_count++; |
859 |
} |
} |
860 |
|
|
|
DEBUG(("Disconnecting...\n")); |
|
|
rdp_disconnect(); |
|
861 |
cache_save_state(); |
cache_save_state(); |
862 |
ui_deinit(); |
ui_deinit(); |
863 |
|
|
984 |
return mem; |
return mem; |
985 |
} |
} |
986 |
|
|
987 |
|
/* strdup */ |
988 |
|
char * |
989 |
|
xstrdup(const char *s) |
990 |
|
{ |
991 |
|
char *mem = strdup(s); |
992 |
|
if (mem == NULL) |
993 |
|
{ |
994 |
|
perror("strdup"); |
995 |
|
exit(1); |
996 |
|
} |
997 |
|
return mem; |
998 |
|
} |
999 |
|
|
1000 |
/* realloc; exit if out of memory */ |
/* realloc; exit if out of memory */ |
1001 |
void * |
void * |
1002 |
xrealloc(void *oldmem, int size) |
xrealloc(void *oldmem, int size) |
1170 |
} |
} |
1171 |
|
|
1172 |
|
|
1173 |
|
BOOL |
1174 |
|
str_startswith(const char *s, const char *prefix) |
1175 |
|
{ |
1176 |
|
return (strncmp(s, prefix, strlen(prefix)) == 0); |
1177 |
|
} |
1178 |
|
|
1179 |
|
|
1180 |
/* not all clibs got ltoa */ |
/* not all clibs got ltoa */ |
1181 |
#define LTOA_BUFSIZE (sizeof(long) * 8 + 1) |
#define LTOA_BUFSIZE (sizeof(long) * 8 + 1) |
1182 |
|
|