Skip to content

Commit

Permalink
Write CLI password prompt to stderr
Browse files Browse the repository at this point in the history
Writing the prompt to stderr greatly helps with the use of keepassxc-cli
in automated scripts or as a password provider for programs like mutt or
borg.

This is done in accordance with POSIX that specifies that diagnostic
messages be sent to stderr.

This commit should be a first step in solving the following
issues: #831, #1221
  • Loading branch information
lhark committed Jul 10, 2018
1 parent 470a74e commit 1dce5b0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/cli/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ void Utils::setStdinEcho(bool enable = true)
QString Utils::getPassword()
{
static QTextStream inputTextStream(stdin, QIODevice::ReadOnly);
static QTextStream outputTextStream(stdout, QIODevice::WriteOnly);
static QTextStream errorTextStream(stderr, QIODevice::WriteOnly);

setStdinEcho(false);
QString line = inputTextStream.readLine();
setStdinEcho(true);

// The new line was also not echoed, but we do want to echo it.
outputTextStream << "\n";
outputTextStream.flush();
errorTextStream << "\n";
errorTextStream.flush();

return line;
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,8 @@ Database* Database::unlockFromStdin(QString databaseFilename, QString keyFilenam
QTextStream outputTextStream(stdout);
QTextStream errorTextStream(stderr);

outputTextStream << QObject::tr("Insert password to unlock %1: ").arg(databaseFilename);
outputTextStream.flush();
errorTextStream << QObject::tr("Insert password to unlock %1: ").arg(databaseFilename);
errorTextStream.flush();

QString line = Utils::getPassword();
PasswordKey passwordKey;
Expand Down

0 comments on commit 1dce5b0

Please sign in to comment.