commit adce7208ddcb65daac83ea3429aa8586d9cc4ea5 Author: Gary Ching-Pang Lin Date: Wed Jan 2 17:30:07 2013 +0800 Only change terminal settings tcgetattr() will fail if we send password through a pipeline instead of a TTY. diff --git a/src/mokutil.c b/src/mokutil.c index a99e355..ea8481a 100644 --- a/src/mokutil.c +++ b/src/mokutil.c @@ -278,22 +278,27 @@ read_hidden_line (char **line, size_t *n) { struct termios old, new; int nread; + int isTTY = isatty(fileno (stdin)); - /* Turn echoing off and fail if we can't. */ - if (tcgetattr (fileno (stdin), &old) != 0) - return -1; + if (isTTY) { + /* Turn echoing off and fail if we can't. */ + if (tcgetattr (fileno (stdin), &old) != 0) + return -1; - new = old; - new.c_lflag &= ~ECHO; + new = old; + new.c_lflag &= ~ECHO; - if (tcsetattr (fileno (stdin), TCSAFLUSH, &new) != 0) - return -1; + if (tcsetattr (fileno (stdin), TCSAFLUSH, &new) != 0) + return -1; + } /* Read the password. */ nread = getline (line, n, stdin); - /* Restore terminal. */ - (void) tcsetattr (fileno (stdin), TCSAFLUSH, &old); + if (isTTY) { + /* Restore terminal. */ + (void) tcsetattr (fileno (stdin), TCSAFLUSH, &old); + } /* Remove the newline */ (*line)[nread-1] = '\0';