mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-11-29 01:03:57 +03:00
getpass: Don't fail if stdin is not a tty.
We don't need to manipulate the tty state (such as turning off echo) when prompting for passwords if we're not reading from a tty.
This commit is contained in:
@@ -220,6 +220,7 @@ int ssh_getpass(const char *prompt,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isatty(STDIN_FILENO)) {
|
||||||
ZERO_STRUCT(attr);
|
ZERO_STRUCT(attr);
|
||||||
ZERO_STRUCT(old_attr);
|
ZERO_STRUCT(old_attr);
|
||||||
|
|
||||||
@@ -246,6 +247,7 @@ int ssh_getpass(const char *prompt,
|
|||||||
perror("tcsetattr");
|
perror("tcsetattr");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* disable nonblocking I/O */
|
/* disable nonblocking I/O */
|
||||||
if (fd & O_NDELAY) {
|
if (fd & O_NDELAY) {
|
||||||
@@ -254,8 +256,10 @@ int ssh_getpass(const char *prompt,
|
|||||||
|
|
||||||
ok = ssh_gets(prompt, buf, len, verify);
|
ok = ssh_gets(prompt, buf, len, verify);
|
||||||
|
|
||||||
|
if (isatty(STDIN_FILENO)) {
|
||||||
/* reset terminal */
|
/* reset terminal */
|
||||||
tcsetattr(STDIN_FILENO, TCSANOW, &old_attr);
|
tcsetattr(STDIN_FILENO, TCSANOW, &old_attr);
|
||||||
|
}
|
||||||
|
|
||||||
/* close fd */
|
/* close fd */
|
||||||
if (fd & O_NDELAY) {
|
if (fd & O_NDELAY) {
|
||||||
|
|||||||
Reference in New Issue
Block a user