Use termios instead of deprecated getpass().

Fix build on cygwin

(cherry picked from commit f3762e8b05)
This commit is contained in:
Alexey Sokolov
2015-10-15 20:00:04 +01:00
parent c6485cddc9
commit ce4dff3b20
2 changed files with 22 additions and 1 deletions
+1 -1
View File
@@ -240,7 +240,7 @@ if test "$POLL" = "yes"; then
fi
AC_CHECK_LIB( gnugetopt, getopt_long,)
AC_CHECK_FUNCS([lstat getopt_long getpassphrase])
AC_CHECK_FUNCS([lstat getopt_long getpassphrase tcsetattr])
# ----- Check for dlopen
+21
View File
@@ -31,6 +31,10 @@
#include <unistd.h>
#include <time.h>
#ifdef HAVE_TCSETATTR
#include <termios.h>
#endif
#ifdef HAVE_ICU
#include <unicode/ucnv.h>
#include <unicode/errorcode.h>
@@ -197,12 +201,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) {