* passwd.cc (getpass): Make check for closed stream more reliable.
Check if setting tty attributes worked and only revert to old state if so.
This commit is contained in:
parent
821c8b9aac
commit
7c4626ed08
@ -1,4 +1,10 @@
|
|||||||
2012-07-08 Corinna Vinschen <corinna@vinschen.de>
|
2012-07-09 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
|
* passwd.cc (getpass): Make check for closed stream more reliable.
|
||||||
|
Check if setting tty attributes worked and only revert to old state
|
||||||
|
if so.
|
||||||
|
|
||||||
|
2012-07-09 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
* Makefile.in, configure.in, mkvers.sh: Revert accidental checkin from
|
* Makefile.in, configure.in, mkvers.sh: Revert accidental checkin from
|
||||||
2012-07-06.
|
2012-07-06.
|
||||||
|
@ -281,6 +281,7 @@ getpass (const char * prompt)
|
|||||||
{
|
{
|
||||||
char *pass = _my_tls.locals.pass;
|
char *pass = _my_tls.locals.pass;
|
||||||
struct termios ti, newti;
|
struct termios ti, newti;
|
||||||
|
bool tc_set = false;
|
||||||
|
|
||||||
/* Try to use controlling tty in the first place. Use stdin and stderr
|
/* Try to use controlling tty in the first place. Use stdin and stderr
|
||||||
only as fallback. */
|
only as fallback. */
|
||||||
@ -295,18 +296,22 @@ getpass (const char * prompt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Make sure to notice if stdin is closed. */
|
/* Make sure to notice if stdin is closed. */
|
||||||
if (tcgetattr (fileno (in), &ti) == -1)
|
if (fileno (in) >= 0)
|
||||||
pass[0] = '\0';
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
flockfile (in);
|
flockfile (in);
|
||||||
|
/* Change tty attributes if possible. */
|
||||||
|
if (!tcgetattr (fileno (in), &ti))
|
||||||
|
{
|
||||||
newti = ti;
|
newti = ti;
|
||||||
newti.c_lflag &= ~(ECHO | ISIG); /* No echo, no signal handling. */
|
newti.c_lflag &= ~(ECHO | ISIG); /* No echo, no signal handling. */
|
||||||
tcsetattr (fileno (in), TCSANOW, &newti);
|
if (!tcsetattr (fileno (in), TCSANOW, &newti))
|
||||||
|
tc_set = true;
|
||||||
|
}
|
||||||
fputs (prompt, err);
|
fputs (prompt, err);
|
||||||
fflush (err);
|
fflush (err);
|
||||||
fgets (pass, _PASSWORD_LEN, in);
|
fgets (pass, _PASSWORD_LEN, in);
|
||||||
fprintf (err, "\n");
|
fprintf (err, "\n");
|
||||||
|
if (tc_set)
|
||||||
tcsetattr (fileno (in), TCSANOW, &ti);
|
tcsetattr (fileno (in), TCSANOW, &ti);
|
||||||
funlockfile (in);
|
funlockfile (in);
|
||||||
char *crlf = strpbrk (pass, "\r\n");
|
char *crlf = strpbrk (pass, "\r\n");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user