--- sourceforge.net/trunk/rdesktop/rdesktop.c 2005/04/16 11:42:34 886 +++ sourceforge.net/trunk/rdesktop/rdesktop.c 2005/08/31 13:00:57 1010 @@ -30,10 +30,10 @@ #include #include "rdesktop.h" -#ifdef HAVE_ICONV #ifdef HAVE_LOCALE_H #include #endif +#ifdef HAVE_ICONV #ifdef HAVE_LANGINFO_H #include #endif @@ -50,8 +50,11 @@ char g_title[64] = ""; char g_username[64]; char g_hostname[16]; -char keymapname[16]; +char g_keymapname[PATH_MAX] = ""; int g_keylayout = 0x409; /* Defaults to US keyboard layout */ +int g_keyboard_type = 0x4; /* Defaults to US keyboard layout */ +int g_keyboard_subtype = 0x0; /* Defaults to US keyboard layout */ +int g_keyboard_functionkeys = 0xc; /* Defaults to US keyboard layout */ int g_width = 800; /* width is special: If 0, the geometry will be fetched from @@ -85,10 +88,17 @@ BOOL g_numlock_sync = False; BOOL g_owncolmap = False; BOOL g_ownbackstore = True; /* We can't rely on external BackingStore */ -BOOL g_rdp_compression = False; uint32 g_embed_wnd; uint32 g_rdp5_performanceflags = RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS; +/* Session Directory redirection */ +BOOL g_redirect = False; +char g_redirect_server[64]; +char g_redirect_domain[16]; +char g_redirect_password[64]; +char g_redirect_username[64]; +char g_redirect_cookie[128]; +uint32 g_redirect_flags = 0; #ifdef WITH_RDPSND BOOL g_rdpsnd = False; @@ -172,7 +182,7 @@ fprintf(stderr, " -5: use RDP version 5 (default)\n"); } -void +static void print_disconnect_reason(uint16 reason) { char *text; @@ -272,6 +282,12 @@ fprintf(stderr, "disconnect: %s.\n", text); } +static void +rdesktop_reset_state(void) +{ + rdp_reset_state(); +} + static BOOL read_password(char *password, int size) { @@ -371,13 +387,23 @@ uint32 flags, ext_disc_reason = 0; char *p; int c; - + char *locale = NULL; int username_option = 0; + int run_count = 0; /* Session Directory support */ + BOOL continue_connect = True; /* Session Directory support */ +#ifdef HAVE_LOCALE_H + /* Set locale according to environment */ + locale = setlocale(LC_ALL, ""); + if (locale) + { + locale = xstrdup(locale); + } + +#endif flags = RDP_LOGON_NORMAL; prompt_password = False; domain[0] = password[0] = shell[0] = directory[0] = 0; - strcpy(keymapname, "en-us"); g_embed_wnd = 0; g_num_devices = 0; @@ -453,7 +479,7 @@ break; case 'k': - STRNCPY(keymapname, optarg, sizeof(keymapname)); + STRNCPY(g_keymapname, optarg, sizeof(g_keymapname)); break; case 'g': @@ -575,22 +601,21 @@ case 'z': DEBUG(("rdp compression enabled\n")); - flags |= RDP_COMPRESSION; - g_rdp_compression = True; + flags |= (RDP_LOGON_COMPRESSION | RDP_LOGON_COMPRESSION2); break; case 'x': - if (strncmp("modem", optarg, 1) == 0) + if (str_startswith(optarg, "m")) /* modem */ { g_rdp5_performanceflags = RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS | RDP5_NO_THEMING; } - else if (strncmp("broadband", optarg, 1) == 0) + else if (str_startswith(optarg, "b")) /* broadband */ { g_rdp5_performanceflags = RDP5_NO_WALLPAPER; } - else if (strncmp("lan", optarg, 1) == 0) + else if (str_startswith(optarg, "l")) /* lan */ { g_rdp5_performanceflags = RDP5_DISABLE_NOTHING; } @@ -606,7 +631,7 @@ case 'r': - if (strncmp("sound", optarg, 5) == 0) + if (str_startswith(optarg, "sound")) { optarg += 5; @@ -615,17 +640,17 @@ *optarg++; while ((p = next_arg(optarg, ','))) { - if (strncmp("remote", optarg, 6) == 0) + if (str_startswith(optarg, "remote")) flags |= RDP_LOGON_LEAVE_AUDIO; - if (strncmp("local", optarg, 5) == 0) + if (str_startswith(optarg, "local")) #ifdef WITH_RDPSND g_rdpsnd = True; #else warning("Not compiled with sound support\n"); #endif - if (strncmp("off", optarg, 3) == 0) + if (str_startswith(optarg, "off")) #ifdef WITH_RDPSND g_rdpsnd = False; #else @@ -644,24 +669,24 @@ #endif } } - else if (strncmp("disk", optarg, 4) == 0) + else if (str_startswith(optarg, "disk")) { /* -r disk:h:=/mnt/floppy */ disk_enum_devices(&g_num_devices, optarg + 4); } - else if (strncmp("comport", optarg, 7) == 0) + else if (str_startswith(optarg, "comport")) { serial_enum_devices(&g_num_devices, optarg + 7); } - else if (strncmp("lptport", optarg, 7) == 0) + else if (str_startswith(optarg, "lptport")) { parallel_enum_devices(&g_num_devices, optarg + 7); } - else if (strncmp("printer", optarg, 7) == 0) + else if (str_startswith(optarg, "printer")) { printer_enum_devices(&g_num_devices, optarg + 7); } - else if (strncmp("clientname", optarg, 7) == 0) + else if (str_startswith(optarg, "clientname")) { g_rdpdr_clientname = xmalloc(strlen(optarg + 11) + 1); strcpy(g_rdpdr_clientname, optarg + 11); @@ -742,6 +767,21 @@ STRNCPY(g_hostname, fullhostname, sizeof(g_hostname)); } + if (g_keymapname[0] == 0) + { + if (locale && xkeymap_from_locale(locale)) + { + fprintf(stderr, "Autoselected keyboard map %s\n", g_keymapname); + } + else + { + STRNCPY(g_keymapname, "en-us", sizeof(g_keymapname)); + } + } + if (locale) + xfree(locale); + + if (prompt_password && read_password(password, sizeof(password))) flags |= RDP_LOGON_AUTO; @@ -765,26 +805,59 @@ #endif rdpdr_init(); - if (!rdp_connect(server, flags, domain, password, shell, directory)) - return 1; + while (run_count < 2 && continue_connect) /* add support for Session Directory; only reconnect once */ + { + if (run_count == 0) + { + if (!rdp_connect(server, flags, domain, password, shell, directory)) + return 1; + } + else if (!rdp_reconnect + (server, flags, domain, password, shell, directory, g_redirect_cookie)) + return 1; - /* By setting encryption to False here, we have an encrypted login - packet but unencrypted transfer of other packets */ - if (!packet_encryption) - g_encryption = False; + /* By setting encryption to False here, we have an encrypted login + packet but unencrypted transfer of other packets */ + if (!packet_encryption) + g_encryption = False; - DEBUG(("Connection successful.\n")); - memset(password, 0, sizeof(password)); + DEBUG(("Connection successful.\n")); + memset(password, 0, sizeof(password)); - if (ui_create_window()) - { - rdp_main_loop(&deactivated, &ext_disc_reason); - ui_destroy_window(); + if (run_count == 0) + if (!ui_create_window()) + continue_connect = False; + + if (continue_connect) + rdp_main_loop(&deactivated, &ext_disc_reason); + + DEBUG(("Disconnecting...\n")); + rdp_disconnect(); + + if ((g_redirect == True) && (run_count == 0)) /* Support for Session Directory */ + { + /* reset state of major globals */ + rdesktop_reset_state(); + + STRNCPY(domain, g_redirect_domain, sizeof(domain)); + STRNCPY(g_username, g_redirect_username, sizeof(g_username)); + STRNCPY(password, g_redirect_password, sizeof(password)); + STRNCPY(server, g_redirect_server, sizeof(server)); + flags |= RDP_LOGON_AUTO; + + g_redirect = False; + } + else + { + continue_connect = False; + ui_destroy_window(); + break; + } + + run_count++; } - DEBUG(("Disconnecting...\n")); - rdp_disconnect(); cache_save_state(); ui_deinit(); @@ -911,6 +984,19 @@ return mem; } +/* strdup */ +char * +xstrdup(const char *s) +{ + char *mem = strdup(s); + if (mem == NULL) + { + perror("strdup"); + exit(1); + } + return mem; +} + /* realloc; exit if out of memory */ void * xrealloc(void *oldmem, int size) @@ -1084,6 +1170,13 @@ } +BOOL +str_startswith(const char *s, const char *prefix) +{ + return (strncmp(s, prefix, strlen(prefix)) == 0); +} + + /* not all clibs got ltoa */ #define LTOA_BUFSIZE (sizeof(long) * 8 + 1)