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) {