summaryrefslogblamecommitdiff
path: root/user/kscreenlocker/kscreenlocker-5.8.5-stop-using-getpass.patch
blob: f10789f8892ca3ab41a50e5c9c63f164fc675398 (plain) (tree)





































































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