--- sourceforge.net/trunk/rdesktop/rdesktop.c 2002/07/29 20:35:13 79 +++ sourceforge.net/trunk/rdesktop/rdesktop.c 2002/10/04 14:28:14 211 @@ -1,40 +1,41 @@ /* rdesktop: A Remote Desktop Protocol client. Entrypoint and utility functions - Copyright (C) Matthew Chapman 1999-2001 - + Copyright (C) Matthew Chapman 1999-2002 + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software 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 */ #include "rdesktop.h" +char title[32] = ""; char username[16]; 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; @@ -49,22 +50,64 @@ static void usage(char *program) { - printf("Usage: %s [options] server\n", program); - printf(" -u: user name\n"); - printf(" -d: domain\n"); - printf(" -s: shell\n"); - printf(" -c: working directory\n"); - printf(" -p: password (autologon)\n"); - printf(" -n: client hostname\n"); - printf(" -k: keyboard layout on terminal server (us,sv,gr etc.)\n"); - printf(" -g: desktop geometry (WxH)\n"); - printf(" -f: full-screen mode\n"); - printf(" -b: force bitmap updates\n"); - printf(" -e: disable encryption (French TS)\n"); - printf(" -m: do not send motion events\n"); - printf(" -l: do not request licence\n"); - printf(" -t: rdp tcp port\n"); - printf(" -K: keep window manager key bindings\n"); + fprintf(stderr, "rdesktop: A Remote Desktop Protocol client.\n"); + fprintf(stderr, "Version " VERSION ". Copyright (C) 1999-2002 Matt Chapman.\n"); + fprintf(stderr, "See http://www.rdesktop.org/ for more information.\n\n"); + + fprintf(stderr, "Usage: %s [options] server\n", program); + fprintf(stderr, " -u: user name\n"); + fprintf(stderr, " -d: domain\n"); + fprintf(stderr, " -s: shell\n"); + fprintf(stderr, " -c: working directory\n"); + fprintf(stderr, " -p: password (- to prompt)\n"); + fprintf(stderr, " -P: askpass-program (autologon)\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"); + fprintf(stderr, " -f: full-screen mode\n"); + fprintf(stderr, " -b: force bitmap updates\n"); + fprintf(stderr, " -e: disable encryption (French TS)\n"); + fprintf(stderr, " -m: do not send motion events\n"); + fprintf(stderr, " -l: do not request licence\n"); + fprintf(stderr, " -t: rdp tcp port\n"); + fprintf(stderr, " -K: keep window manager key bindings\n"); + 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 */ @@ -74,24 +117,21 @@ char fullhostname[64]; char domain[16]; char password[16]; + char *askpass_result; char shell[32]; char directory[32]; - char title[32]; + BOOL prompt_password; struct passwd *pw; char *server, *p; uint32 flags; int c; - printf("rdesktop: A Remote Desktop Protocol client.\n"); - printf("Version " VERSION - ". Copyright (C) 1999-2001 Matt Chapman.\n"); - printf("See http://www.rdesktop.org/ for more information.\n\n"); - 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:n:k:g:t:fbemlKh?")) != -1) + while ((c = getopt(argc, argv, "u:d:s:c:p:P:n:k:g:t:fbemlKw:h?")) != -1) { switch (c) { @@ -112,8 +152,29 @@ break; case 'p': + if ((optarg[0] == '-') && (optarg[1] == 0)) + { + prompt_password = True; + break; + } + STRNCPY(password, optarg, sizeof(password)); flags |= RDP_LOGON_AUTO; + + /* try to overwrite argument so it won't appear in ps */ + p = optarg; + while (*p) + *(p++) = 'X'; + 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; break; case 'n': @@ -121,8 +182,7 @@ break; case 'k': - STRNCPY(keymapname, optarg, - sizeof(keymapname)); + STRNCPY(keymapname, optarg, sizeof(keymapname)); break; case 'g': @@ -165,6 +225,10 @@ grab_keyboard = False; break; + case 'w': + strncpy(title, optarg, sizeof(title)); + break; + case 'h': case '?': default: @@ -208,41 +272,33 @@ 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 (prompt_password && read_password(password, sizeof(password))) + flags |= RDP_LOGON_AUTO; - if ((width == 0) || (height == 0)) + if (title[0] == 0) { - width = 800; - height = 600; + strcpy(title, "rdesktop - "); + strncat(title, server, sizeof(title) - sizeof("rdesktop - ")); } - strcpy(title, "rdesktop - "); - strncat(title, server, sizeof(title) - sizeof("rdesktop - ")); - - xkeymap_init1(); + if (!ui_init()) + return 1; if (!rdp_connect(server, flags, domain, password, shell, directory)) return 1; - printf("Connection successful.\n"); + DEBUG(("Connection successful.\n")); + memset(password, 0, sizeof(password)); - if (ui_create_window(title)) + if (ui_create_window()) { rdp_main_loop(); ui_destroy_window(); } - printf("Disconnecting...\n"); + DEBUG(("Disconnecting...\n")); rdp_disconnect(); + ui_deinit(); return 0; } @@ -356,9 +412,7 @@ printf(" "); for (i = 0; i < thisline; i++) - printf("%c", - (line[i] >= 0x20 - && line[i] < 0x7f) ? line[i] : '.'); + printf("%c", (line[i] >= 0x20 && line[i] < 0x7f) ? line[i] : '.'); printf("\n"); offset += thisline; @@ -366,6 +420,7 @@ } } +#ifdef SAVE_LICENCE int load_licence(unsigned char **data) { @@ -419,3 +474,4 @@ write(fd, data, length); close(fd); } +#endif