Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | ssh_get_password has become ssh_get_line, so it can handle usernames as well. This should fix the multiple-reads-on-stdin bug in plink. |
|---|---|
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA1: |
fa069c172aceb9ecb15eba1fa081a900 |
| User & Date: | simon 2001-03-12 09:31:53.000 |
Context
|
2001-03-13
| ||
| 03:41 | Add dependencies for x11fwd.obj to Makefile (thanks Catbells :-) check-in: d0f8edee33 user: simon tags: trunk | |
|
2001-03-12
| ||
| 09:31 | ssh_get_password has become ssh_get_line, so it can handle usernames as well. This should fix the multiple-reads-on-stdin bug in plink. check-in: fa069c172a user: simon tags: trunk | |
| 09:12 | Zero length passwords no longer cause an assertion failure :-) check-in: b982530d97 user: simon tags: trunk | |
Changes
Changes to plink.c.
| ︙ | ︙ | |||
156 157 158 159 160 161 162 |
struct input_data {
DWORD len;
char buffer[4096];
HANDLE event, eventback;
};
| | | | < | > > > > > > | | 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
struct input_data {
DWORD len;
char buffer[4096];
HANDLE event, eventback;
};
static int get_line(const char *prompt, char *str, int maxlen, int is_pw)
{
HANDLE hin, hout;
DWORD savemode, newmode, i;
if (is_pw && password) {
static int tried_once = 0;
if (tried_once) {
return 0;
} else {
strncpy(str, password, maxlen);
str[maxlen-1] = '\0';
tried_once = 1;
return 1;
}
}
hin = GetStdHandle(STD_INPUT_HANDLE);
hout = GetStdHandle(STD_OUTPUT_HANDLE);
if (hin == INVALID_HANDLE_VALUE || hout == INVALID_HANDLE_VALUE) {
fprintf(stderr, "Cannot get standard input/output handles");
return 0;
}
GetConsoleMode(hin, &savemode);
newmode = savemode | ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT;
if (is_pw)
newmode &= ~ENABLE_ECHO_INPUT;
else
newmode |= ENABLE_ECHO_INPUT;
SetConsoleMode(hin, newmode);
WriteFile(hout, prompt, strlen(prompt), &i, NULL);
ReadFile(hin, str, maxlen-1, &i, NULL);
SetConsoleMode(hin, savemode);
if ((int)i > maxlen) i = maxlen-1; else i = i - 2;
str[i] = '\0';
if (is_pw)
WriteFile(hout, "\r\n", 2, &i, NULL);
return 1;
}
static DWORD WINAPI stdin_read_thread(void *param) {
struct input_data *idata = (struct input_data *)param;
HANDLE inhandle;
|
| ︙ | ︙ | |||
261 262 263 264 265 266 267 |
struct input_data idata;
int sending;
int portnumber = -1;
SOCKET *sklist;
int skcount, sksize;
int connopen;
| | | 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
struct input_data idata;
int sending;
int portnumber = -1;
SOCKET *sklist;
int skcount, sksize;
int connopen;
ssh_get_line = get_line;
sklist = NULL; skcount = sksize = 0;
flags = FLAG_STDERR;
/*
* Process the command line.
*/
|
| ︙ | ︙ |
Changes to psftp.c.
| ︙ | ︙ | |||
856 857 858 859 860 861 862 |
if (select(1, &readfds, NULL, NULL, NULL) < 0)
return; /* doom */
select_result((WPARAM)sftp_ssh_socket, (LPARAM)FD_READ);
}
}
static char *password = NULL;
| | | | 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 |
if (select(1, &readfds, NULL, NULL, NULL) < 0)
return; /* doom */
select_result((WPARAM)sftp_ssh_socket, (LPARAM)FD_READ);
}
}
static char *password = NULL;
static int get_line(const char *prompt, char *str, int maxlen, int is_pw)
{
HANDLE hin, hout;
DWORD savemode, newmode, i;
if (password) {
static int tried_once = 0;
if (tried_once) {
return 0;
} else {
|
| ︙ | ︙ | |||
882 883 884 885 886 887 888 |
hout = GetStdHandle(STD_OUTPUT_HANDLE);
if (hin == INVALID_HANDLE_VALUE || hout == INVALID_HANDLE_VALUE) {
fprintf(stderr, "Cannot get standard input/output handles\n");
exit(1);
}
GetConsoleMode(hin, &savemode);
| < | > > > > > > | | 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 |
hout = GetStdHandle(STD_OUTPUT_HANDLE);
if (hin == INVALID_HANDLE_VALUE || hout == INVALID_HANDLE_VALUE) {
fprintf(stderr, "Cannot get standard input/output handles\n");
exit(1);
}
GetConsoleMode(hin, &savemode);
newmode = savemode | ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT;
if (is_pw)
newmode &= ~ENABLE_ECHO_INPUT;
else
newmode |= ENABLE_ECHO_INPUT;
SetConsoleMode(hin, newmode);
WriteFile(hout, prompt, strlen(prompt), &i, NULL);
ReadFile(hin, str, maxlen-1, &i, NULL);
SetConsoleMode(hin, savemode);
if ((int)i > maxlen) i = maxlen-1; else i = i - 2;
str[i] = '\0';
if (is_pw)
WriteFile(hout, "\r\n", 2, &i, NULL);
return 1;
}
/*
* Initialize the Win$ock driver.
*/
|
| ︙ | ︙ | |||
944 945 946 947 948 949 950 |
{
int i;
int portnumber = 0;
char *user, *host, *userhost, *realhost;
char *err;
flags = FLAG_STDERR;
| | | 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 |
{
int i;
int portnumber = 0;
char *user, *host, *userhost, *realhost;
char *err;
flags = FLAG_STDERR;
ssh_get_line = &get_line;
init_winsock();
sk_init();
userhost = user = NULL;
for (i = 1; i < argc; i++) {
if (argv[i][0] != '-') {
|
| ︙ | ︙ |
Changes to putty.h.
| ︙ | ︙ | |||
378 379 380 381 382 383 384 | extern Backend telnet_backend; /* * Exports from ssh.c. */ | | > | 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 |
extern Backend telnet_backend;
/*
* Exports from ssh.c.
*/
extern int (*ssh_get_line)(const char *prompt, char *str, int maxlen,
int is_pw);
extern Backend ssh_backend;
/*
* Exports from ldisc.c.
*/
extern void ldisc_send(char *buf, int len);
|
| ︙ | ︙ |
Changes to scp.c.
| ︙ | ︙ | |||
391 392 393 394 395 396 397 |
char ch;
back->special(TS_EOF);
ssh_scp_recv(&ch, 1);
}
exit(1);
}
| | | | | 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 |
char ch;
back->special(TS_EOF);
ssh_scp_recv(&ch, 1);
}
exit(1);
}
static int get_line(const char *prompt, char *str, int maxlen, int is_pw)
{
HANDLE hin, hout;
DWORD savemode, newmode, i;
if (is_pw && password) {
static int tried_once = 0;
if (tried_once) {
return 0;
} else {
strncpy(str, password, maxlen);
str[maxlen-1] = '\0';
|
| ︙ | ︙ | |||
419 420 421 422 423 424 425 |
} else {
hin = GetStdHandle(STD_INPUT_HANDLE);
hout = GetStdHandle(STD_OUTPUT_HANDLE);
if (hin == INVALID_HANDLE_VALUE || hout == INVALID_HANDLE_VALUE)
bump("Cannot get standard input/output handles");
GetConsoleMode(hin, &savemode);
| < | > > > > > > | | 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 |
} else {
hin = GetStdHandle(STD_INPUT_HANDLE);
hout = GetStdHandle(STD_OUTPUT_HANDLE);
if (hin == INVALID_HANDLE_VALUE || hout == INVALID_HANDLE_VALUE)
bump("Cannot get standard input/output handles");
GetConsoleMode(hin, &savemode);
newmode = savemode | ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT;
if (is_pw)
newmode &= ~ENABLE_ECHO_INPUT;
else
newmode |= ENABLE_ECHO_INPUT;
SetConsoleMode(hin, newmode);
WriteFile(hout, prompt, strlen(prompt), &i, NULL);
ReadFile(hin, str, maxlen-1, &i, NULL);
SetConsoleMode(hin, savemode);
if ((int)i > maxlen) i = maxlen-1; else i = i - 2;
str[i] = '\0';
if (is_pw)
WriteFile(hout, "\r\n", 2, &i, NULL);
}
return 1;
}
/*
* Open an SSH connection to user@host and execute cmd.
|
| ︙ | ︙ | |||
1219 1220 1221 1222 1223 1224 1225 |
{
int i;
int list = 0;
default_protocol = PROT_TELNET;
flags = FLAG_STDERR;
| | | 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 |
{
int i;
int list = 0;
default_protocol = PROT_TELNET;
flags = FLAG_STDERR;
ssh_get_line = &get_line;
init_winsock();
sk_init();
for (i = 1; i < argc; i++) {
if (argv[i][0] != '-')
break;
if (strcmp(argv[i], "-v") == 0)
|
| ︙ | ︙ |
Changes to ssh.c.
| ︙ | ︙ | |||
265 266 267 268 269 270 271 | static const struct ssh_mac *csmac = NULL; static const struct ssh_mac *scmac = NULL; static const struct ssh_compress *cscomp = NULL; static const struct ssh_compress *sccomp = NULL; static const struct ssh_kex *kex = NULL; static const struct ssh_signkey *hostkey = NULL; static unsigned char ssh2_session_id[20]; | | > | 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
static const struct ssh_mac *csmac = NULL;
static const struct ssh_mac *scmac = NULL;
static const struct ssh_compress *cscomp = NULL;
static const struct ssh_compress *sccomp = NULL;
static const struct ssh_kex *kex = NULL;
static const struct ssh_signkey *hostkey = NULL;
static unsigned char ssh2_session_id[20];
int (*ssh_get_line)(const char *prompt, char *str, int maxlen,
int is_pw) = NULL;
static char *savedhost;
static int savedport;
static int ssh_send_ok;
static int ssh_echoing, ssh_editing;
static tree234 *ssh_channels; /* indexed by local id */
|
| ︙ | ︙ | |||
1499 1500 1501 1502 1503 1504 1505 |
logevent("Successfully started encryption");
fflush(stdout);
{
static int pos = 0;
static char c;
if ((flags & FLAG_INTERACTIVE) && !*cfg.username) {
| > > > > > > > > > > > > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > | | 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 |
logevent("Successfully started encryption");
fflush(stdout);
{
static int pos = 0;
static char c;
if ((flags & FLAG_INTERACTIVE) && !*cfg.username) {
if (ssh_get_line) {
if (!ssh_get_line("login as: ",
username, sizeof(username), FALSE)) {
/*
* get_line failed to get a username.
* Terminate.
*/
logevent("No username provided. Abandoning session.");
ssh_state = SSH_STATE_CLOSED;
crReturn(1);
}
} else {
c_write_str("login as: ");
ssh_send_ok = 1;
while (pos >= 0) {
crWaitUntil(!ispkt);
while (inlen--) switch (c = *in++) {
case 10: case 13:
username[pos] = 0;
pos = -1;
break;
case 8: case 127:
if (pos > 0) {
c_write_str("\b \b");
pos--;
}
break;
case 21: case 27:
while (pos > 0) {
c_write_str("\b \b");
pos--;
}
break;
case 3: case 4:
random_save_seed();
exit(0);
break;
default:
if (((c >= ' ' && c <= '~') ||
((unsigned char)c >= 160)) && pos < 40) {
username[pos++] = c;
c_write(&c, 1);
}
break;
}
}
c_write_str("\r\n");
username[strcspn(username, "\n\r")] = '\0';
}
} else {
strncpy(username, cfg.username, 99);
username[99] = '\0';
}
send_packet(SSH1_CMSG_USER, PKT_STR, username, PKT_END);
{
char userlog[22+sizeof(username)];
|
| ︙ | ︙ | |||
1737 1738 1739 1740 1741 1742 1743 |
c_write_str("No passphrase required.\r\n");
goto tryauth;
}
sprintf(prompt, "Passphrase for key \"%.100s\": ", comment);
sfree(comment);
}
| | | | | | < | 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 |
c_write_str("No passphrase required.\r\n");
goto tryauth;
}
sprintf(prompt, "Passphrase for key \"%.100s\": ", comment);
sfree(comment);
}
if (ssh_get_line) {
if (!ssh_get_line(prompt, password, sizeof(password), TRUE)) {
/*
* get_line failed to get a password (for example
* because one was supplied on the command line
* which has already failed to work). Terminate.
*/
logevent("No more passwords to try");
ssh_state = SSH_STATE_CLOSED;
crReturn(1);
}
} else {
c_write_str(prompt);
|
| ︙ | ︙ | |||
2839 2840 2841 2842 2843 2844 2845 |
static char c;
/*
* Get a username.
*/
pos = 0;
if ((flags & FLAG_INTERACTIVE) && !*cfg.username) {
| > > > > > > > > > > > > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > | 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 |
static char c;
/*
* Get a username.
*/
pos = 0;
if ((flags & FLAG_INTERACTIVE) && !*cfg.username) {
if (ssh_get_line) {
if (!ssh_get_line("login as: ",
username, sizeof(username), FALSE)) {
/*
* get_line failed to get a username.
* Terminate.
*/
logevent("No username provided. Abandoning session.");
ssh_state = SSH_STATE_CLOSED;
crReturn(1);
}
} else {
c_write_str("login as: ");
ssh_send_ok = 1;
while (pos >= 0) {
crWaitUntilV(!ispkt);
while (inlen--) switch (c = *in++) {
case 10: case 13:
username[pos] = 0;
pos = -1;
break;
case 8: case 127:
if (pos > 0) {
c_write_str("\b \b");
pos--;
}
break;
case 21: case 27:
while (pos > 0) {
c_write_str("\b \b");
pos--;
}
break;
case 3: case 4:
random_save_seed();
exit(0);
break;
default:
if (((c >= ' ' && c <= '~') ||
((unsigned char)c >= 160)) && pos < 40) {
username[pos++] = c;
c_write(&c, 1);
}
break;
}
}
}
c_write_str("\r\n");
username[strcspn(username, "\n\r")] = '\0';
} else {
char stuff[200];
strncpy(username, cfg.username, 99);
username[99] = '\0';
if ((flags & FLAG_VERBOSE) || (flags & FLAG_INTERACTIVE)) {
|
| ︙ | ︙ | |||
3154 3155 3156 3157 3158 3159 3160 |
if (!method && can_passwd) {
method = AUTH_PASSWORD;
sprintf(pwprompt, "%.90s@%.90s's password: ", username, savedhost);
need_pw = TRUE;
}
if (need_pw) {
| | | > | | | | | 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 |
if (!method && can_passwd) {
method = AUTH_PASSWORD;
sprintf(pwprompt, "%.90s@%.90s's password: ", username, savedhost);
need_pw = TRUE;
}
if (need_pw) {
if (ssh_get_line) {
if (!ssh_get_line(pwprompt, password,
sizeof(password), TRUE)) {
/*
* get_line failed to get a password (for
* example because one was supplied on the
* command line which has already failed to
* work). Terminate.
*/
logevent("No more passwords to try");
ssh_state = SSH_STATE_CLOSED;
crReturnV;
}
} else {
static int pos = 0;
|
| ︙ | ︙ |