From: YOKOTA Hiroshi <yokota.hgml@gmail.com>
Date: Tue, 22 Feb 2022 21:02:14 +0900
Subject: Disable local echo display when in input passwords (Closes:
 #1006238)

---
 CPP/7zip/UI/Console/UserInputUtils.cpp | 33 ++++++++++++++++++++++++++++++++-
 CPP/Common/StdInStream.h               |  1 +
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/CPP/7zip/UI/Console/UserInputUtils.cpp b/CPP/7zip/UI/Console/UserInputUtils.cpp
index b3ca88e..6f60a78 100755
--- a/CPP/7zip/UI/Console/UserInputUtils.cpp
+++ b/CPP/7zip/UI/Console/UserInputUtils.cpp
@@ -56,9 +56,18 @@ NUserAnswerMode::EEnum ScanUserYesNoAllQuit(CStdOutStream *outStream)
 #ifdef _WIN32
 #ifndef UNDER_CE
 #define MY_DISABLE_ECHO
+#define MY_DISABLE_ECHO_WIN32
 #endif
 #endif
 
+#ifdef unix
+#include <stdio.h>
+#include <termios.h>
+#include <unistd.h>
+#define MY_DISABLE_ECHO
+#define MY_DISABLE_ECHO_UNIX
+#endif
+
 static bool GetPassword(CStdOutStream *outStream, UString &psw)
 {
   if (outStream)
@@ -71,7 +80,7 @@ static bool GetPassword(CStdOutStream *outStream, UString &psw)
     outStream->Flush();
   }
 
-  #ifdef MY_DISABLE_ECHO
+  #ifdef MY_DISABLE_ECHO_WIN32
   
   HANDLE console = GetStdHandle(STD_INPUT_HANDLE);
   bool wasChanged = false;
@@ -83,6 +92,28 @@ static bool GetPassword(CStdOutStream *outStream, UString &psw)
   if (wasChanged)
     SetConsoleMode(console, mode);
   
+  #elif defined(MY_DISABLE_ECHO_UNIX)
+
+  int ifd = fileno(&(*g_StdIn));
+  bool wasChanged = false;
+  struct termios old_mode = {};
+  struct termios new_mode = {};
+
+  if (tcgetattr(ifd, &old_mode) == 0) {
+    new_mode = old_mode;
+    new_mode.c_lflag &= ~ECHO;
+
+    tcsetattr(ifd, TCSAFLUSH, &new_mode);
+
+    wasChanged = true;
+  }
+
+  bool res = g_StdIn.ScanUStringUntilNewLine(psw);
+
+  if (wasChanged) {
+    tcsetattr(ifd, TCSAFLUSH, &old_mode);
+  }
+
   #else
   
   bool res = g_StdIn.ScanUStringUntilNewLine(psw);
diff --git a/CPP/Common/StdInStream.h b/CPP/Common/StdInStream.h
index 7f27e92..23c7bf8 100755
--- a/CPP/Common/StdInStream.h
+++ b/CPP/Common/StdInStream.h
@@ -23,6 +23,7 @@ public:
 
   ~CStdInStream() { Close(); }
 
+  operator FILE *() { return _stream; }
   bool Open(LPCTSTR fileName) throw();
   bool Close() throw();
 
