From 40ab6c1093012099afe89fbe5944bbcf9184d3a5 Mon Sep 17 00:00:00 2001 From: Karel Klic Date: Wed, 5 May 2010 14:24:40 +0200 Subject: Do not echo password to terminal in abrt-cli --- src/CLI/report.cpp | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/CLI/report.cpp b/src/CLI/report.cpp index bff6a9a0..3946e6bb 100644 --- a/src/CLI/report.cpp +++ b/src/CLI/report.cpp @@ -24,6 +24,7 @@ #include "Plugin.h" // LoadPluginSettings #include #include +#include #if HAVE_CONFIG_H # include #endif @@ -529,6 +530,28 @@ static bool ask_yesno(const char *question) return ((answer[0] | 0x20) == 'y'); } +static void set_echo(bool enabled) +{ + if (isatty(STDIN_FILENO) == 0) + { + /* Clean errno, which is set by isatty. */ + errno = 0; + return; + } + + struct termios t; + if (tcgetattr(STDIN_FILENO, &t) < 0) + perror_msg_and_die("tcgetattr failed"); + + if (enabled) + t.c_lflag |= ECHO; + else + t.c_lflag &= ~ECHO; + + if (tcsetattr(STDIN_FILENO, TCSANOW, &t) < 0) + perror_msg_and_die("tcsetattr failed"); +} + /** * Gets reporter plugin settings. * @param reporters @@ -604,8 +627,11 @@ static void get_reporter_plugin_settings(const vector_string_t& reporters, } if (passwordMissing) { -// TODO: echo off, see http://fixunix.com/unix/84474-echo-off.html + set_echo(false); read_from_stdin(_("Enter your password: "), result, 64); + set_echo(true); + // Newline was not added by pressing Enter because ECHO was disabled, so add it now. + puts(""); single_plugin_settings["Password"] = std::string(result); } } -- cgit