summaryrefslogtreecommitdiff
path: root/user/kscreenlocker/kscreenlocker-5.8.5-stop-using-getpass.patch
blob: f10789f8892ca3ab41a50e5c9c63f164fc675398 (plain) (blame)
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
--- kscreenlocker-5.8.5/kcheckpass/kcheckpass.c.old	2016-12-27 11:25:36.000000000 +0000
+++ kscreenlocker-5.8.5/kcheckpass/kcheckpass.c	2017-01-31 04:32:44.858227055 +0000
@@ -56,6 +56,7 @@
 #include <stdlib.h>
 #include <errno.h>
 #include <time.h>
+#include <termios.h>
 
 #include <config-kscreenlocker.h>
 #if HAVE_SYS_PRCTL_H
@@ -75,9 +76,41 @@
 static int havetty, sfd = -1, nullpass;
 
 static char *
+better_getpass (void)
+{
+    char                *password = NULL, *nl;
+    size_t              buf_len = 0;
+    ssize_t             pass_len;
+    struct termios      ti;
+
+    tcgetattr(STDIN_FILENO, &ti);
+    ti.c_lflag &= ~ECHO;
+    tcsetattr(STDIN_FILENO, TCSANOW, &ti);
+
+    pass_len = getdelim(&password, &buf_len, '\n', stdin);
+
+    if (pass_len < 0) {
+        free(password);
+        return NULL;
+    }
+
+    ti.c_lflag |= ECHO;
+    tcsetattr(STDIN_FILENO, TCSANOW, &ti);
+
+    /* Do not include the \n at the end */
+    nl = strchr(password, '\n');
+    if (nl) {
+        *nl = '\0';
+    }
+
+    return password;
+}
+
+
+static char *
 conv_legacy (ConvRequest what, const char *prompt)
 {
-    char		*p, *p2;
+    char		*p2;
     int			len;
     char		buf[1024];
 
@@ -99,13 +132,10 @@
 	return strdup(buf);
     case ConvGetHidden:
 	if (havetty) {
-#ifdef HAVE_GETPASSPHRASE
-	    p = getpassphrase(prompt ? prompt : "Password: ");
-#else
-	    p = getpass(prompt ? prompt : "Password: ");
-#endif
-	    p2 = strdup(p);
-	    memset(p, 0, strlen(p));
+	    fputs(prompt ? prompt : "Password: ", stdout);
+	    fflush(stdout);
+	    p2 = better_getpass();
+	    printf("\n");
 	    return p2;
 	} else {
 	    if (prompt)