|
@@ -45,17 +45,22 @@ char * getpass (const char *prompt)
|
|
|
|
|
|
If we can't open the terminal, use stderr and stdin. */
|
|
|
|
|
|
- in = fopen ("/dev/tty", "r+");
|
|
|
+ out = in = fopen ("/dev/tty", "r+");
|
|
|
if (in == NULL)
|
|
|
{
|
|
|
in = stdin;
|
|
|
out = stderr;
|
|
|
}
|
|
|
else
|
|
|
- out = in;
|
|
|
+ {
|
|
|
+
|
|
|
+ * fseek and buffering for read/write auto-transitioning. */
|
|
|
+ setvbuf(in, NULL, _IONBF, 0);
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
|
+ tty_changed = 0;
|
|
|
if (tcgetattr (fileno (in), &t) == 0)
|
|
|
{
|
|
|
|
|
@@ -63,41 +68,28 @@ char * getpass (const char *prompt)
|
|
|
|
|
|
t.c_lflag &= ~(ECHO|ISIG);
|
|
|
tty_changed = (tcsetattr (fileno (in), TCSAFLUSH|TCSASOFT, &t) == 0);
|
|
|
- if (in != stdin) {
|
|
|
-
|
|
|
- * fseek and buffering for read/write auto-transitioning. */
|
|
|
- setvbuf(in, NULL, _IONBF, 0);
|
|
|
- }
|
|
|
}
|
|
|
- else
|
|
|
- tty_changed = 0;
|
|
|
|
|
|
|
|
|
fputs(prompt, out);
|
|
|
fflush(out);
|
|
|
|
|
|
|
|
|
- fgets (buf, PWD_BUFFER_SIZE-1, in);
|
|
|
- if (buf != NULL)
|
|
|
+ if (!fgets (buf, sizeof(buf)-1, in))
|
|
|
+ buf[0] = '\0';
|
|
|
+ nread = strlen(buf);
|
|
|
+ if (nread > 0 && buf[nread - 1] == '\n')
|
|
|
+
|
|
|
+ buf[nread - 1] = '\0';
|
|
|
+
|
|
|
+ if (tty_changed)
|
|
|
{
|
|
|
- nread = strlen(buf);
|
|
|
- if (nread < 0)
|
|
|
- buf[0] = '\0';
|
|
|
- else if (buf[nread - 1] == '\n')
|
|
|
- {
|
|
|
-
|
|
|
- buf[nread - 1] = '\0';
|
|
|
- if (tty_changed)
|
|
|
-
|
|
|
- putc('\n', out);
|
|
|
- }
|
|
|
+
|
|
|
+ putc('\n', out);
|
|
|
+
|
|
|
+ (void) tcsetattr (fileno (in), TCSAFLUSH|TCSASOFT, &s);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- if (tty_changed) {
|
|
|
- (void) tcsetattr (fileno (in), TCSAFLUSH|TCSASOFT, &s);
|
|
|
- }
|
|
|
-
|
|
|
if (in != stdin)
|
|
|
|
|
|
fclose (in);
|