From 54b1e7e167fd594d39ff91fd78e34cb8b411162b Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sun, 27 Dec 2020 11:48:52 +0100 Subject: [PATCH] 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 --- src/client/getpass.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/client/getpass.c b/src/client/getpass.c index 6e151f41e..b04ec7e50 100644 --- a/src/client/getpass.c +++ b/src/client/getpass.c @@ -38,6 +38,8 @@ #include #ifdef _WIN32 #include +#else +#include #endif #endif #include "misc.h" @@ -62,7 +64,19 @@ set_echo_if_tty(int on) return -1; return 1; #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 /* !HAVE_GETPASS */ -- 2.43.0