From f3762e8b055b530d7ed0119cbde48c11eef5f7b1 Mon Sep 17 00:00:00 2001 From: Alexey Sokolov Date: Thu, 15 Oct 2015 20:00:04 +0100 Subject: [PATCH] Use termios instead of deprecated getpass(). Also this fixes flaky integration test. Sometimes it hanged because getpass() sometimes didn't want to believe that it already got the password from input. --- configure.ac | 2 +- src/Utils.cpp | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 10a2d9bb..1e90ceab 100644 --- a/configure.ac +++ b/configure.ac @@ -296,7 +296,7 @@ if test "$POLL" = "yes"; then fi AC_CHECK_LIB( gnugetopt, getopt_long,) -AC_CHECK_FUNCS([lstat getopt_long getpassphrase clock_gettime]) +AC_CHECK_FUNCS([lstat getopt_long getpassphrase clock_gettime tcsetattr]) # ----- Check for dlopen diff --git a/src/Utils.cpp b/src/Utils.cpp index 1ccbbdb4..8005b305 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -23,6 +23,10 @@ #endif /* HAVE_LIBSSL */ #include +#ifdef HAVE_TCSETATTR +#include +#endif + #ifdef HAVE_ICU #include #include @@ -200,12 +204,29 @@ CString CUtils::SaltedSHA256Hash(const CString& sPass, const CString& sSalt) { } CString CUtils::GetPass(const CString& sPrompt) { +#ifdef HAVE_TCSETATTR + // Disable echo + struct termios t; + tcgetattr(1, &t); + struct termios t2 = t; + t2.c_lflag &= ~ECHO; + tcsetattr(1, TCSANOW, &t2); + // Read pass + CString r; + GetInput(sPrompt, r); + // Restore echo and go to new line + tcsetattr(1, TCSANOW, &t); + fprintf(stdout, "\n"); + fflush(stdout); + return r; +#else PrintPrompt(sPrompt); #ifdef HAVE_GETPASSPHRASE return getpassphrase(""); #else return getpass(""); #endif +#endif } bool CUtils::GetBoolInput(const CString& sPrompt, bool bDefault) {