--- sourceforge.net/trunk/rdesktop/rdesktop.c 2003/04/16 13:04:15 367 +++ sourceforge.net/trunk/rdesktop/rdesktop.c 2003/08/21 23:23:15 447 @@ -41,25 +41,26 @@ #endif char title[32] = ""; -char username[16]; +char g_username[16]; char hostname[16]; char keymapname[16]; int keylayout = 0x409; /* Defaults to US keyboard layout */ -int width = 800; /* If width or height are reset to zero, the geometry will +int g_width = 800; /* If width or height are reset to zero, the geometry will be fetched from _NET_WORKAREA */ -int height = 600; +int g_height = 600; int tcp_port_rdp = TCP_PORT_RDP; -int server_bpp = 8; +int g_server_bpp = 8; int win_button_size = 0; /* If zero, disable single app mode */ -BOOL bitmap_compression = True; -BOOL sendmotion = True; -BOOL orders = True; -BOOL encryption = True; -BOOL desktop_save = True; -BOOL fullscreen = False; +BOOL g_bitmap_compression = True; +BOOL g_sendmotion = True; +BOOL g_orders = True; +BOOL g_encryption = True; +BOOL packet_encryption = True; +BOOL g_desktop_save = True; +BOOL g_fullscreen = False; BOOL grab_keyboard = True; BOOL hide_decorations = False; -BOOL use_rdp5 = False; +BOOL g_use_rdp5 = False; extern BOOL owncolmap; #ifdef RDP2VNC @@ -94,6 +95,7 @@ fprintf(stderr, " -f: full-screen mode\n"); fprintf(stderr, " -b: force bitmap updates\n"); fprintf(stderr, " -e: disable encryption (French TS)\n"); + fprintf(stderr, " -E: disable encryption of everything but the logon packet\n"); fprintf(stderr, " -m: do not send motion events\n"); fprintf(stderr, " -C: use private colour map\n"); fprintf(stderr, " -K: keep window manager key bindings\n"); @@ -139,6 +141,54 @@ return ret; } +static void +parse_server_and_port(char *server) +{ + char *p; +#ifdef IPv6 + int addr_colons; +#endif + +#ifdef IPv6 + p = server; + addr_colons = 0; + while (*p) + if (*p++ == ':') + addr_colons++; + if (addr_colons >= 2) + { + /* numeric IPv6 style address format - [1:2:3::4]:port */ + p = strchr(server, ']'); + if (*server == '[' && p != NULL) + { + if (*(p + 1) == ':' && *(p + 2) != '\0') + tcp_port_rdp = strtol(p + 2, NULL, 10); + /* remove the port number and brackets from the address */ + *p = '\0'; + strncpy(server, server + 1, strlen(server)); + } + } + else + { + /* dns name or IPv4 style address format - server.example.com:port or 1.2.3.4:port */ + p = strchr(server, ':'); + if (p != NULL) + { + tcp_port_rdp = strtol(p + 1, NULL, 10); + *p = 0; + } + } +#else /* no IPv6 support */ + p = strchr(server, ':'); + if (p != NULL) + { + tcp_port_rdp = strtol(p + 1, NULL, 10); + *p = 0; + } +#endif /* IPv6 */ + +} + /* Client program */ int main(int argc, char *argv[]) @@ -149,7 +199,7 @@ char password[16]; char shell[128]; char directory[32]; - BOOL prompt_password; + BOOL prompt_password, rdp_retval = False; struct passwd *pw; uint32 flags; char *p; @@ -167,7 +217,7 @@ #define VNCOPT #endif - while ((c = getopt(argc, argv, VNCOPT "u:d:s:S:c:p:n:k:g:a:fbemCKT:Dh?54")) != -1) + while ((c = getopt(argc, argv, VNCOPT "u:d:s:S:c:p:n:k:g:a:fbeEmCKT:Dh?54")) != -1) { switch (c) { @@ -186,7 +236,7 @@ #endif case 'u': - STRNCPY(username, optarg, sizeof(username)); + STRNCPY(g_username, optarg, sizeof(g_username)); username_option = 1; break; @@ -246,15 +296,15 @@ case 'g': if (!strcmp(optarg, "workarea")) { - width = height = 0; + g_width = g_height = 0; break; } - width = strtol(optarg, &p, 10); + g_width = strtol(optarg, &p, 10); if (*p == 'x') - height = strtol(p + 1, NULL, 10); + g_height = strtol(p + 1, NULL, 10); - if ((width == 0) || (height == 0)) + if ((g_width == 0) || (g_height == 0)) { error("invalid geometry\n"); return 1; @@ -262,19 +312,21 @@ break; case 'f': - fullscreen = True; + g_fullscreen = True; break; case 'b': - orders = False; + g_orders = False; break; case 'e': - encryption = False; + g_encryption = False; + break; + case 'E': + packet_encryption = False; break; - case 'm': - sendmotion = False; + g_sendmotion = False; break; case 'C': @@ -294,9 +346,9 @@ break; case 'a': - server_bpp = strtol(optarg, NULL, 10); - if (server_bpp != 8 && server_bpp != 16 && server_bpp != 15 - && server_bpp != 24) + g_server_bpp = strtol(optarg, NULL, 10); + if (g_server_bpp != 8 && g_server_bpp != 16 && g_server_bpp != 15 + && g_server_bpp != 24) { error("invalid server bpp\n"); return 1; @@ -304,7 +356,7 @@ break; case '5': - use_rdp5 = True; + g_use_rdp5 = True; break; case 'h': case '?': @@ -321,12 +373,7 @@ } STRNCPY(server, argv[optind], sizeof(server)); - p = strchr(server, ':'); - if (p != NULL) - { - tcp_port_rdp = strtol(p + 1, NULL, 10); - *p = 0; - } + parse_server_and_port(server); if (!username_option) { @@ -337,7 +384,7 @@ return 1; } - STRNCPY(username, pw->pw_name, sizeof(username)); + STRNCPY(g_username, pw->pw_name, sizeof(g_username)); } if (hostname[0] == 0) @@ -366,20 +413,30 @@ #ifdef RDP2VNC rdp2vnc_connect(server, flags, domain, password, shell, directory); + return 0; #else if (!ui_init()) return 1; + /* rdpsnd_init(); */ + /* rdpdr_init(); */ + if (!rdp_connect(server, flags, domain, password, shell, directory)) 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; + + DEBUG(("Connection successful.\n")); memset(password, 0, sizeof(password)); if (ui_create_window()) { - rdp_main_loop(); + rdp_retval = rdp_main_loop(); ui_destroy_window(); } @@ -387,9 +444,13 @@ rdp_disconnect(); ui_deinit(); + if (True == rdp_retval) + return 0; + else + return 2; + #endif - return 0; } #ifdef EGD_SOCKET @@ -549,11 +610,10 @@ /* produce a hex dump */ void -hexdump(unsigned char *p, unsigned int len) +hexdump(unsigned char *p, int len) { unsigned char *line = p; - unsigned int thisline, offset = 0; - int i; + int i, thisline, offset = 0; while (offset < len) { @@ -589,7 +649,7 @@ if (home == NULL) return -1; - path = xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence.")); + path = (char *) xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence.")); sprintf(path, "%s/.rdesktop/licence.%s", home, hostname); fd = open(path, O_RDONLY); @@ -599,7 +659,7 @@ if (fstat(fd, &st)) return -1; - *data = xmalloc(st.st_size); + *data = (uint8 *) xmalloc(st.st_size); length = read(fd, *data, st.st_size); close(fd); xfree(path); @@ -616,7 +676,7 @@ if (home == NULL) return; - path = xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence.")); + path = (char *) xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence.")); sprintf(path, "%s/.rdesktop", home); if ((mkdir(path, 0700) == -1) && errno != EEXIST) @@ -628,11 +688,11 @@ /* write licence to licence.hostname.new, then atomically rename to licence.hostname */ sprintf(path, "%s/.rdesktop/licence.%s", home, hostname); - tmppath = xmalloc(strlen(path) + sizeof(".new")); + tmppath = (char *) xmalloc(strlen(path) + sizeof(".new")); strcpy(tmppath, path); strcat(tmppath, ".new"); - fd = open(tmppath, O_WRONLY|O_CREAT|O_TRUNC, 0600); + fd = open(tmppath, O_WRONLY | O_CREAT | O_TRUNC, 0600); if (fd == -1) { perror(tmppath);