--- sourceforge.net/trunk/rdesktop/rdesktop.c 2005/04/16 11:42:34 886 +++ sourceforge.net/trunk/rdesktop/rdesktop.c 2005/08/15 12:06:59 980 @@ -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,8 +601,7 @@ case 'z': DEBUG(("rdp compression enabled\n")); - flags |= RDP_COMPRESSION; - g_rdp_compression = True; + flags |= (RDP_LOGON_COMPRESSION | RDP_LOGON_COMPRESSION2); break; case 'x': @@ -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(); @@ -909,6 +982,19 @@ exit(1); } 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 */