Skip to content

Commit 1dce5b0

Browse files
author
lhark
committed
Write CLI password prompt to stderr
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: keepassxreboot#831, keepassxreboot#1221
1 parent 470a74e commit 1dce5b0

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/cli/Utils.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ void Utils::setStdinEcho(bool enable = true)
5959
QString Utils::getPassword()
6060
{
6161
static QTextStream inputTextStream(stdin, QIODevice::ReadOnly);
62-
static QTextStream outputTextStream(stdout, QIODevice::WriteOnly);
62+
static QTextStream errorTextStream(stderr, QIODevice::WriteOnly);
6363

6464
setStdinEcho(false);
6565
QString line = inputTextStream.readLine();
6666
setStdinEcho(true);
6767

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

7272
return line;
7373
}

src/core/Database.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,8 @@ Database* Database::unlockFromStdin(QString databaseFilename, QString keyFilenam
465465
QTextStream outputTextStream(stdout);
466466
QTextStream errorTextStream(stderr);
467467

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

471471
QString line = Utils::getPassword();
472472
PasswordKey passwordKey;

0 commit comments

Comments
 (0)