diff options
Diffstat (limited to 'winsup/cygwin/passwd.cc')
-rw-r--r-- | winsup/cygwin/passwd.cc | 60 |
1 files changed, 17 insertions, 43 deletions
diff --git a/winsup/cygwin/passwd.cc b/winsup/cygwin/passwd.cc index c6abb0205..962bf776e 100644 --- a/winsup/cygwin/passwd.cc +++ b/winsup/cygwin/passwd.cc @@ -58,7 +58,7 @@ pwdgrp::read_passwd () bool searchentry = true; struct passwd *pw; /* must be static */ - static char NO_COPY pretty_ls[] = "????????:*:-1:-1:::"; + static char NO_COPY pretty_ls[] = "????????:*:-1:-1:"; add_line (pretty_ls); cygsid tu = cygheap->user.sid (); @@ -269,55 +269,29 @@ setpassent () return 0; } -static void -_getpass_close_fd (void *arg) -{ - if (arg) - fclose ((FILE *) arg); -} - extern "C" char * getpass (const char * prompt) { char *pass = _my_tls.locals.pass; struct termios ti, newti; - bool tc_set = false; - - /* Try to use controlling tty in the first place. Use stdin and stderr - only as fallback. */ - FILE *in = stdin, *err = stderr; - FILE *tty = fopen ("/dev/tty", "w+b"); - pthread_cleanup_push (_getpass_close_fd, tty); - if (tty) - { - /* Set close-on-exec for obvious reasons. */ - fcntl (fileno (tty), F_SETFD, fcntl (fileno (tty), F_GETFD) | FD_CLOEXEC); - in = err = tty; - } - /* Make sure to notice if stdin is closed. */ - if (fileno (in) >= 0) + cygheap_fdget fhstdin (0); + + if (fhstdin < 0) + pass[0] = '\0'; + else { - flockfile (in); - /* Change tty attributes if possible. */ - if (!tcgetattr (fileno (in), &ti)) - { - newti = ti; - newti.c_lflag &= ~(ECHO | ISIG); /* No echo, no signal handling. */ - if (!tcsetattr (fileno (in), TCSANOW, &newti)) - tc_set = true; - } - fputs (prompt, err); - fflush (err); - fgets (pass, _PASSWORD_LEN, in); - fprintf (err, "\n"); - if (tc_set) - tcsetattr (fileno (in), TCSANOW, &ti); - funlockfile (in); - char *crlf = strpbrk (pass, "\r\n"); - if (crlf) - *crlf = '\0'; + fhstdin->tcgetattr (&ti); + newti = ti; + newti.c_lflag &= ~ECHO; + fhstdin->tcsetattr (TCSANOW, &newti); + fputs (prompt, stderr); + fgets (pass, _PASSWORD_LEN, stdin); + fprintf (stderr, "\n"); + for (int i=0; pass[i]; i++) + if (pass[i] == '\r' || pass[i] == '\n') + pass[i] = '\0'; + fhstdin->tcsetattr (TCSANOW, &ti); } - pthread_cleanup_pop (1); return pass; } |