summaryrefslogtreecommitdiffstats
path: root/cups-getpass.patch
blob: 7b089a72397e0bab0ca8719ffe2279cb3ce0ff54 (plain)
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
diff -up cups-1.5b1/cups/usersys.c.getpass cups-1.5b1/cups/usersys.c
--- cups-1.5b1/cups/usersys.c.getpass	2011-05-20 05:49:49.000000000 +0200
+++ cups-1.5b1/cups/usersys.c	2011-05-24 15:41:33.000000000 +0200
@@ -43,6 +43,8 @@
 #include "cups-private.h"
 #include <stdlib.h>
 #include <sys/stat.h>
+#include <termios.h>
+#include <signal.h>
 #ifdef WIN32
 #  include <windows.h>
 #else
@@ -501,13 +503,31 @@ _cupsGetPassword(const char *prompt)	/* 
   * empty password is treated as canceling the authentication request.
   */
 
-  const char	*password = getpass(prompt);
-					/* Password string */
-
-  if (!password || !password[0])
-    return (NULL);
-  else
+  static char password[100];
+  struct termios oldtio, newtio;
+  sigset_t oldset, newset;
+  int nread;
+  sigprocmask (SIG_BLOCK, NULL, &newset);
+  sigaddset (&newset, SIGINT);
+  sigaddset (&newset, SIGTSTP);
+  sigprocmask (SIG_BLOCK, &newset, &oldset);
+  tcgetattr (STDIN_FILENO, &oldtio);
+  newtio = oldtio;
+  newtio.c_lflag &= ~ECHO;
+  tcsetattr (STDIN_FILENO, TCSAFLUSH, &newtio);
+  fputs (prompt, stdout);
+  fflush (stdout);
+  nread = read (STDIN_FILENO, password, sizeof (password));
+  tcsetattr (STDIN_FILENO, TCSAFLUSH, &oldtio);
+  fputc ('\n', stdout);
+  sigprocmask (SIG_SETMASK, &oldset, NULL);
+  if (nread > 0)
+  {
+    password[nread - 1] = '\0';
     return (password);
+  }
+  else
+    return (NULL);
 #endif /* WIN32 */
 }