File: 0003-Disable-local-echo-display-when-in-input-passwords-C.patch

package info (click to toggle)
7zip 25.01%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,560 kB
  • sloc: cpp: 207,815; ansic: 39,747; asm: 4,987; makefile: 2,188; sh: 162
file content (88 lines) | stat: -rw-r--r-- 2,461 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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)

Forwarded: https://sourceforge.net/p/sevenzip/patches/381/
Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1006238
---
 CPP/7zip/UI/Console/UserInputUtils.cpp | 33 ++++++++++++++++++++++++++++++++-
 CPP/Common/StdInStream.h               |  3 +++
 2 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/CPP/7zip/UI/Console/UserInputUtils.cpp b/CPP/7zip/UI/Console/UserInputUtils.cpp
index 6c3c85a..2832b00 100644
--- a/CPP/7zip/UI/Console/UserInputUtils.cpp
+++ b/CPP/7zip/UI/Console/UserInputUtils.cpp
@@ -57,9 +57,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)
@@ -72,7 +81,7 @@ static bool GetPassword(CStdOutStream *outStream, UString &psw)
     outStream->Flush();
   }
 
-  #ifdef MY_DISABLE_ECHO
+  #ifdef MY_DISABLE_ECHO_WIN32
   
   const HANDLE console = GetStdHandle(STD_INPUT_HANDLE);
 
@@ -91,6 +100,28 @@ static bool GetPassword(CStdOutStream *outStream, UString &psw)
   if (wasChanged)
     SetConsoleMode(console, mode);
   
+  #elif defined(MY_DISABLE_ECHO_UNIX)
+
+  const 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;
+  }
+
+  const bool res = g_StdIn.ScanUStringUntilNewLine(psw);
+
+  if (wasChanged) {
+    tcsetattr(ifd, TCSAFLUSH, &old_mode);
+  }
+
   #else
   
   const bool res = g_StdIn.ScanUStringUntilNewLine(psw);
diff --git a/CPP/Common/StdInStream.h b/CPP/Common/StdInStream.h
index 2253c43..69d84fe 100644
--- a/CPP/Common/StdInStream.h
+++ b/CPP/Common/StdInStream.h
@@ -23,7 +23,10 @@ public:
 
   /*
   ~CStdInStream() { Close(); }
+  */
 
+  operator FILE *() { return _stream; }
+  /*
   bool Open(LPCTSTR fileName) throw();
   bool Close() throw();
   */