From 7000e80465eeda140c6e530f38ee2e33a904e2f8 Mon Sep 17 00:00:00 2001 From: Jack Thomasson Date: Mon, 24 Oct 2016 12:22:02 -0600 Subject: [PATCH] add command line option --pw-stdin to accept password from stdin --- src/main.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 655fb91ec..bcbfb9c42 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,6 +17,7 @@ #include #include +#include #include "config-keepassx.h" #include "core/Config.h" @@ -61,11 +62,14 @@ int main(int argc, char** argv) QCommandLineOption keyfileOption("keyfile", QCoreApplication::translate("main", "key file of the database"), "keyfile"); + QCommandLineOption pwstdinOption("pw-stdin", + QCoreApplication::translate("main", "read password of the database from stdin")); parser.addHelpOption(); parser.addVersionOption(); parser.addOption(configOption); parser.addOption(keyfileOption); + parser.addOption(pwstdinOption); parser.process(app); const QStringList args = parser.positionalArguments(); @@ -90,7 +94,12 @@ int main(int argc, char** argv) for (int ii=0; ii < args.length(); ii++) { QString filename = args[ii]; if (!filename.isEmpty() && QFile::exists(filename)) { - mainWindow.openDatabase(filename, QString(), parser.value(keyfileOption)); + QString password; + if (parser.isSet(pwstdinOption)) { + static QTextStream in(stdin, QIODevice::ReadOnly); + password = in.readLine(); + } + mainWindow.openDatabase(filename, password, parser.value(keyfileOption)); } }