CLI: fix missing check for correct credentials (#2629)

* CLI: fix missing check for correct credentials

Before this fix, most/all CLI commands had incorrect behaviour when bad
credentials were supplied: they would carry on regardless, with
potentially catastrophic results.  In particular, the "add" subcommand
seemed to corrupt the database.  "ls" would always report an empty
database.  Haven't tested any others.

Also fixed a related missing check specific to the "merge" subcommand.
This commit is contained in:
Carlo Teubner 2019-01-21 19:24:29 +00:00 committed by Jonathan White
parent b59fd6d06a
commit 94430c300b
2 changed files with 10 additions and 2 deletions

View File

@ -79,6 +79,9 @@ int Merge::execute(const QStringList& arguments)
QSharedPointer<Database> db2;
if (!parser.isSet("same-credentials")) {
db2 = Utils::unlockDatabase(args.at(1), parser.value(keyFileFromOption), Utils::STDOUT, Utils::STDERR);
if (!db2) {
return EXIT_FAILURE;
}
} else {
db2 = QSharedPointer<Database>::create();
QString errorMessage;

View File

@ -135,8 +135,13 @@ QSharedPointer<Database> unlockDatabase(const QString& databaseFilename,
}
auto db = QSharedPointer<Database>::create();
db->open(databaseFilename, compositeKey, nullptr, false);
return db;
QString error;
if (db->open(databaseFilename, compositeKey, &error, false)) {
return db;
} else {
err << error << endl;
return {};
}
}
/**