summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Klic <kklic@redhat.com>2010-05-05 14:24:40 +0200
committerKarel Klic <kklic@redhat.com>2010-05-05 14:24:40 +0200
commit40ab6c1093012099afe89fbe5944bbcf9184d3a5 (patch)
tree80ea646cb8712018f0c63d527b8bddee5e66703a
parent1c85ad384fbab756ae9c51acfc6c232791889b50 (diff)
downloadabrt-40ab6c1093012099afe89fbe5944bbcf9184d3a5.tar.gz
abrt-40ab6c1093012099afe89fbe5944bbcf9184d3a5.tar.xz
abrt-40ab6c1093012099afe89fbe5944bbcf9184d3a5.zip
Do not echo password to terminal in abrt-cli
-rw-r--r--src/CLI/report.cpp28
1 files changed, 27 insertions, 1 deletions
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 <cassert>
#include <algorithm>
+#include <termios.h>
#if HAVE_CONFIG_H
# include <config.h>
#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);
}
}