fix sftp.exe client to work using password authentication
ssh.exe client invoked underneath was not able to send password prompt and read password from user as stdin and stdout handles were redirected to sockets by sftp.exe ; stderr which is not redirected is used to show prompt to users and data is read from console
This commit is contained in:
parent
0d3a933c2a
commit
6d167ae0f6
|
@ -72,6 +72,7 @@ static fd_set write_sfd_set;
|
||||||
|
|
||||||
int PassInputFd = STDIN_FILENO;
|
int PassInputFd = STDIN_FILENO;
|
||||||
int PassOutputFd = STDOUT_FILENO;
|
int PassOutputFd = STDOUT_FILENO;
|
||||||
|
int PassErrorFd = STDERR_FILENO;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We store cookies for authorize
|
* We store cookies for authorize
|
||||||
|
|
125
readpass.c
125
readpass.c
|
@ -54,6 +54,7 @@
|
||||||
|
|
||||||
extern int PassInputFd;
|
extern int PassInputFd;
|
||||||
extern int PassOutputFd;
|
extern int PassOutputFd;
|
||||||
|
extern int PassErrorFd;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -334,110 +335,40 @@ read_passphrase(const char *prompt, int flags)
|
||||||
* Show prompt for user.
|
* Show prompt for user.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
_write(PassOutputFd, prompt, strlen(prompt));
|
_write(PassErrorFd, prompt, strlen(prompt));
|
||||||
|
|
||||||
/*
|
|
||||||
* Disable stdin echo.
|
|
||||||
*/
|
|
||||||
|
|
||||||
GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &mode);
|
|
||||||
|
|
||||||
SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), mode & (~ENABLE_ECHO_INPUT));
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Read pass from stdin socket.
|
|
||||||
*/
|
|
||||||
|
|
||||||
len = retr = 0;
|
len = retr = 0;
|
||||||
|
int bufsize = sizeof(buf);
|
||||||
do
|
|
||||||
{
|
|
||||||
retr = _read(PassInputFd, buf + len, sizeof(buf) - 1 - len);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If read error.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (retr == -1)
|
|
||||||
{
|
|
||||||
int winerr = GetLastError();
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Non fatal. Only write message and try again.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (errno == EINTR || errno == EAGAIN ||
|
|
||||||
winerr == WSAENOTSOCK || winerr == WSAEWOULDBLOCK)
|
|
||||||
{
|
|
||||||
debug("ERROR. read_passphrase() : [errno = %d, winerr = %d], "
|
|
||||||
"trying again...\n", errno, winerr);
|
|
||||||
|
|
||||||
fflush(stderr);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Fatal error. Break loop with empty string.
|
|
||||||
*/
|
|
||||||
|
|
||||||
else
|
while (_kbhit())
|
||||||
{
|
_getch();
|
||||||
error("ERROR. read_passphrase() : fatal error"
|
|
||||||
" [errno = %d, winerr = %d]...\n", errno, winerr);
|
|
||||||
|
|
||||||
fflush(stderr);
|
|
||||||
|
|
||||||
buf[0] = 0;
|
|
||||||
|
|
||||||
len = 1;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
while ( len < bufsize ) {
|
||||||
* No error.
|
|
||||||
*/
|
|
||||||
|
|
||||||
else
|
|
||||||
{
|
|
||||||
len += retr;
|
|
||||||
}
|
|
||||||
} while (len < sizeof(buf) - 1 && buf[len] == '\r');
|
|
||||||
|
|
||||||
/*
|
buf[len] = (unsigned char) _getch() ;
|
||||||
* Put zero at string end.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (len > 0)
|
|
||||||
{
|
|
||||||
buf[len - 1] = '\0';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
buf[0] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
_write(PassOutputFd, "\n", strlen("\n"));
|
|
||||||
|
|
||||||
len = strlen(buf);
|
if ( buf[len] == '\r' ) {
|
||||||
|
if (_kbhit() )
|
||||||
while (len > 0 && buf[len - 1] == 0xa || buf[len - 1] == 0xd)
|
_getch(); // read linefeed if its there
|
||||||
{
|
break;
|
||||||
buf[len - 1] = 0;
|
}
|
||||||
|
else if ( buf[len] == '\n' ) {
|
||||||
len --;
|
break;
|
||||||
}
|
}
|
||||||
|
else if ( buf[len] == '\b' ) { // backspace
|
||||||
/*
|
if (len > 0 )
|
||||||
* Set stdin echo back.
|
len--; // overwrite last character
|
||||||
*/
|
}
|
||||||
|
else {
|
||||||
SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), mode | ENABLE_ECHO_INPUT);
|
|
||||||
|
_putch( (int) '*' ); // show a star in place of what is typed
|
||||||
/*
|
len++; // keep reading in the loop
|
||||||
* Return copy of pass readed from stdin.
|
}
|
||||||
*/
|
}
|
||||||
|
|
||||||
|
buf[len] = '\0' ; // get rid of the cr/lf
|
||||||
|
|
||||||
ret = xstrdup(buf);
|
ret = xstrdup(buf);
|
||||||
|
|
||||||
memset(buf, 'x', sizeof(buf));
|
memset(buf, 'x', sizeof(buf));
|
||||||
|
|
Loading…
Reference in New Issue