client: Make get_password() not echo with POSIX && !HAVE_GETPASS
getpass() is traditional Unix, but has been withdrawn from POSIX. We provide a replacement in case it's missing. The one for Windows suppresses echo, like getpass() does. Implement that for POSIX. The other differences to getpass() remain. Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
parent
ea762c1f08
commit
53b2271d1d
1 changed files with 15 additions and 1 deletions
|
@ -38,6 +38,8 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
#else
|
||||||
|
#include <termios.h>
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
@ -62,7 +64,19 @@ set_echo_if_tty(int on)
|
||||||
return -1;
|
return -1;
|
||||||
return 1;
|
return 1;
|
||||||
#else
|
#else
|
||||||
return 0;
|
struct termios tcattr;
|
||||||
|
|
||||||
|
if (tcgetattr(0, &tcattr) < 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (on)
|
||||||
|
tcattr.c_lflag |= ECHO;
|
||||||
|
else
|
||||||
|
tcattr.c_lflag &= ~ECHO;
|
||||||
|
|
||||||
|
if (tcsetattr(0, TCSAFLUSH, &tcattr) < 0)
|
||||||
|
return -1;
|
||||||
|
return 1;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif /* !HAVE_GETPASS */
|
#endif /* !HAVE_GETPASS */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue