--- sourceforge.net/trunk/rdesktop/rdesktop.c 2002/09/14 11:54:11 122 +++ sourceforge.net/trunk/rdesktop/rdesktop.c 2002/10/06 13:30:30 213 @@ -18,12 +18,12 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include /* malloc realloc free */ #include /* va_list va_start va_end */ #include /* read close getuid getgid getpid getppid gethostname */ #include /* open */ #include /* getpwuid */ #include /* PATH_MAX */ +#include /* tcgetattr tcsetattr */ #include /* stat */ #include /* gettimeofday */ #include /* times */ @@ -34,8 +34,8 @@ char hostname[16]; char keymapname[16]; int keylayout = 0x409; /* Defaults to US keyboard layout */ -int width; -int height; +int width = 800; +int height = 600; int tcp_port_rdp = TCP_PORT_RDP; BOOL bitmap_compression = True; BOOL sendmotion = True; @@ -59,8 +59,7 @@ fprintf(stderr, " -d: domain\n"); fprintf(stderr, " -s: shell\n"); fprintf(stderr, " -c: working directory\n"); - fprintf(stderr, " -p: password (autologon)\n"); - fprintf(stderr, " -P: askpass-program (autologon)\n"); + fprintf(stderr, " -p: password (- to prompt)\n"); fprintf(stderr, " -n: client hostname\n"); fprintf(stderr, " -k: keyboard layout on terminal server (us,sv,gr etc.)\n"); fprintf(stderr, " -g: desktop geometry (WxH)\n"); @@ -74,6 +73,42 @@ fprintf(stderr, " -w: window title\n"); } +static BOOL +read_password(char *password, int size) +{ + struct termios tios; + BOOL ret = False; + int istty = 0; + char *p; + + if (tcgetattr(STDIN_FILENO, &tios) == 0) + { + fprintf(stderr, "Password: "); + tios.c_lflag &= ~ECHO; + tcsetattr(STDIN_FILENO, TCSANOW, &tios); + istty = 1; + } + + if (fgets(password, size, stdin) != NULL) + { + ret = True; + + /* strip final newline */ + p = strchr(password, '\n'); + if (p != NULL) + *p = 0; + } + + if (istty) + { + tios.c_lflag |= ECHO; + tcsetattr(STDIN_FILENO, TCSANOW, &tios); + fprintf(stderr, "\n"); + } + + return ret; +} + /* Client program */ int main(int argc, char *argv[]) @@ -81,19 +116,20 @@ char fullhostname[64]; char domain[16]; char password[16]; - char *askpass_result; char shell[32]; char directory[32]; + BOOL prompt_password; struct passwd *pw; char *server, *p; uint32 flags; int c; flags = RDP_LOGON_NORMAL; + prompt_password = False; domain[0] = password[0] = shell[0] = directory[0] = 0; strcpy(keymapname, "us"); - while ((c = getopt(argc, argv, "u:d:s:c:p:P:n:k:g:t:fbemlKw:h?")) != -1) + while ((c = getopt(argc, argv, "u:d:s:c:p:n:k:g:t:fbemlKw:h?")) != -1) { switch (c) { @@ -114,18 +150,19 @@ break; case 'p': + if ((optarg[0] == '-') && (optarg[1] == 0)) + { + prompt_password = True; + break; + } + STRNCPY(password, optarg, sizeof(password)); flags |= RDP_LOGON_AUTO; - break; - case 'P': - askpass_result = askpass(optarg, "Enter password"); - if (askpass_result == NULL) - exit(1); - - STRNCPY(password, askpass_result, sizeof(password)); - free(askpass_result); - flags |= RDP_LOGON_AUTO; + /* try to overwrite argument so it won't appear in ps */ + p = optarg; + while (*p) + *(p++) = 'X'; break; case 'n': @@ -223,29 +260,10 @@ STRNCPY(hostname, fullhostname, sizeof(hostname)); } - if (!strcmp(password, "-")) - { - p = getpass("Password: "); - if (p == NULL) - { - error("failed to read password\n"); - return 0; - } - STRNCPY(password, p, sizeof(password)); - } - - if ((width == 0) || (height == 0)) - { - width = 800; - height = 600; - } - else - { - /* make sure width is a multiple of 4 */ - width = (width + 3) & ~3; - } + if (prompt_password && read_password(password, sizeof(password))) + flags |= RDP_LOGON_AUTO; - if (!strlen(title)) + if (title[0] == 0) { strcpy(title, "rdesktop - "); strncat(title, server, sizeof(title) - sizeof("rdesktop - ")); @@ -258,6 +276,7 @@ return 1; DEBUG(("Connection successful.\n")); + memset(password, 0, sizeof(password)); if (ui_create_window()) { @@ -267,6 +286,7 @@ DEBUG(("Disconnecting...\n")); rdp_disconnect(); + ui_deinit(); return 0; } @@ -368,26 +388,27 @@ while (offset < len) { - fprintf(stderr, "%04x ", offset); + printf("%04x ", offset); thisline = len - offset; if (thisline > 16) thisline = 16; for (i = 0; i < thisline; i++) - fprintf(stderr, "%02x ", line[i]); + printf("%02x ", line[i]); for (; i < 16; i++) - fprintf(stderr, " "); + printf(" "); for (i = 0; i < thisline; i++) - fprintf(stderr, "%c", (line[i] >= 0x20 && line[i] < 0x7f) ? line[i] : '.'); + printf("%c", (line[i] >= 0x20 && line[i] < 0x7f) ? line[i] : '.'); - fprintf(stderr, "\n"); + printf("\n"); offset += thisline; line += thisline; } } +#ifdef SAVE_LICENCE int load_licence(unsigned char **data) { @@ -441,3 +462,4 @@ write(fd, data, length); close(fd); } +#endif