diff --git a/src/cli/Add.cpp b/src/cli/Add.cpp
index bb3b87d7..2f4f14d6 100644
--- a/src/cli/Add.cpp
+++ b/src/cli/Add.cpp
@@ -15,18 +15,12 @@
* along with this program. If not, see .
*/
-#include
-#include
-
#include "Add.h"
-#include "cli/Generate.h"
-#include "cli/TextStream.h"
-#include "cli/Utils.h"
-#include "core/Database.h"
+#include "Generate.h"
+#include "Utils.h"
#include "core/Entry.h"
#include "core/Group.h"
-#include "core/PasswordGenerator.h"
const QCommandLineOption Add::UsernameOption = QCommandLineOption(QStringList() << "u"
<< "username",
diff --git a/src/cli/Add.h b/src/cli/Add.h
index 8c5e5ab5..e36ec5eb 100644
--- a/src/cli/Add.h
+++ b/src/cli/Add.h
@@ -32,7 +32,6 @@ public:
static const QCommandLineOption NotesOption;
static const QCommandLineOption PasswordPromptOption;
static const QCommandLineOption GenerateOption;
- static const QCommandLineOption PasswordLengthOption;
};
#endif // KEEPASSXC_ADD_H
diff --git a/src/cli/AddGroup.cpp b/src/cli/AddGroup.cpp
index be6bfbf3..11c57f10 100644
--- a/src/cli/AddGroup.cpp
+++ b/src/cli/AddGroup.cpp
@@ -15,14 +15,9 @@
* along with this program. If not, see .
*/
-#include
-#include
-
#include "AddGroup.h"
-#include "cli/TextStream.h"
-#include "cli/Utils.h"
-#include "core/Database.h"
+#include "Utils.h"
#include "core/Entry.h"
#include "core/Group.h"
diff --git a/src/cli/Analyze.cpp b/src/cli/Analyze.cpp
index 51f8dea7..4498e197 100644
--- a/src/cli/Analyze.cpp
+++ b/src/cli/Analyze.cpp
@@ -16,16 +16,14 @@
*/
#include "Analyze.h"
-#include "cli/Utils.h"
+
+#include "Utils.h"
+#include "core/Group.h"
#include "core/HibpOffline.h"
+#include "core/Tools.h"
#include
#include
-#include
-
-#include "cli/TextStream.h"
-#include "core/Group.h"
-#include "core/Tools.h"
const QCommandLineOption Analyze::HIBPDatabaseOption = QCommandLineOption(
{"H", "hibp"},
@@ -84,23 +82,21 @@ int Analyze::executeWithDatabase(QSharedPointer database, QSharedPoint
}
}
- for (auto& finding : findings) {
- printHibpFinding(finding.first, finding.second, out);
+ for (const auto& finding : findings) {
+ const auto entry = finding.first;
+ auto count = finding.second;
+
+ QString path = entry->title();
+ for (auto g = entry->group(); g && g != g->database()->rootGroup(); g = g->parentGroup()) {
+ path.prepend("/").prepend(g->name());
+ }
+
+ if (count > 0) {
+ out << QObject::tr("Password for '%1' has been leaked %2 time(s)!", "", count).arg(path).arg(count) << endl;
+ } else {
+ out << QObject::tr("Password for '%1' has been leaked!", "", count).arg(path) << endl;
+ }
}
return EXIT_SUCCESS;
}
-
-void Analyze::printHibpFinding(const Entry* entry, int count, QTextStream& out)
-{
- QString path = entry->title();
- for (auto g = entry->group(); g && g != g->database()->rootGroup(); g = g->parentGroup()) {
- path.prepend("/").prepend(g->name());
- }
-
- if (count > 0) {
- out << QObject::tr("Password for '%1' has been leaked %2 time(s)!", "", count).arg(path).arg(count) << endl;
- } else {
- out << QObject::tr("Password for '%1' has been leaked!", "", count).arg(path) << endl;
- }
-}
diff --git a/src/cli/Analyze.h b/src/cli/Analyze.h
index a616093a..dec6b914 100644
--- a/src/cli/Analyze.h
+++ b/src/cli/Analyze.h
@@ -28,9 +28,6 @@ public:
static const QCommandLineOption HIBPDatabaseOption;
static const QCommandLineOption OkonOption;
-
-private:
- void printHibpFinding(const Entry* entry, int count, QTextStream& out);
};
#endif // KEEPASSXC_HIBP_H
diff --git a/src/cli/Clip.cpp b/src/cli/Clip.cpp
index ac8e5b3f..1096d4ff 100644
--- a/src/cli/Clip.cpp
+++ b/src/cli/Clip.cpp
@@ -15,18 +15,12 @@
* along with this program. If not, see .
*/
-#include
-#include
-#include
-
#include "Clip.h"
-#include "cli/TextStream.h"
-#include "cli/Utils.h"
-#include "core/Database.h"
+#include "Utils.h"
#include "core/Entry.h"
-#include "core/Global.h"
#include "core/Group.h"
+#include "core/Tools.h"
const QCommandLineOption Clip::AttributeOption = QCommandLineOption(
QStringList() << "a"
@@ -155,7 +149,7 @@ int Clip::executeWithDatabase(QSharedPointer database, QSharedPointer<
out << '\r' << QString(lastLine.size(), ' ') << '\r';
lastLine = QObject::tr("Clearing the clipboard in %1 second(s)…", "", timeoutSeconds).arg(timeoutSeconds);
out << lastLine << flush;
- std::this_thread::sleep_for(std::chrono::milliseconds(1000));
+ Tools::sleep(1000);
--timeoutSeconds;
}
Utils::clipText("");
diff --git a/src/cli/Close.cpp b/src/cli/Close.cpp
index 4ff3bcda..58d123a8 100644
--- a/src/cli/Close.cpp
+++ b/src/cli/Close.cpp
@@ -17,13 +17,6 @@
#include "Close.h"
-#include
-#include
-
-#include "DatabaseCommand.h"
-#include "TextStream.h"
-#include "Utils.h"
-
Close::Close()
{
name = QString("close");
diff --git a/src/cli/Command.cpp b/src/cli/Command.cpp
index 260d9b2b..82b22cb0 100644
--- a/src/cli/Command.cpp
+++ b/src/cli/Command.cpp
@@ -15,13 +15,6 @@
* along with this program. If not, see .
*/
-#include
-#include
-#include
-
-#include
-#include
-
#include "Command.h"
#include "Add.h"
@@ -47,9 +40,11 @@
#include "Remove.h"
#include "RemoveGroup.h"
#include "Show.h"
-#include "TextStream.h"
#include "Utils.h"
+#include
+#include
+
const QCommandLineOption Command::HelpOption = QCommandLineOption(QStringList()
#ifdef Q_OS_WIN
<< QStringLiteral("?")
diff --git a/src/cli/Command.h b/src/cli/Command.h
index 4381bf18..c296f6fd 100644
--- a/src/cli/Command.h
+++ b/src/cli/Command.h
@@ -21,7 +21,6 @@
#include
#include
#include
-#include
#include
#include
diff --git a/src/cli/Create.cpp b/src/cli/Create.cpp
index e2bbfac2..c253312d 100644
--- a/src/cli/Create.cpp
+++ b/src/cli/Create.cpp
@@ -15,21 +15,12 @@
* along with this program. If not, see .
*/
-#include
-#include
+#include "Create.h"
+
+#include "Utils.h"
+#include "keys/FileKey.h"
#include
-#include
-#include
-
-#include "Create.h"
-#include "Utils.h"
-
-#include "core/Database.h"
-
-#include "keys/CompositeKey.h"
-#include "keys/FileKey.h"
-#include "keys/Key.h"
const QCommandLineOption Create::DecryptionTimeOption =
QCommandLineOption(QStringList() << "t"
diff --git a/src/cli/DatabaseCommand.cpp b/src/cli/DatabaseCommand.cpp
index 08104c12..7456f418 100644
--- a/src/cli/DatabaseCommand.cpp
+++ b/src/cli/DatabaseCommand.cpp
@@ -16,7 +16,6 @@
*/
#include "DatabaseCommand.h"
-
#include "Utils.h"
DatabaseCommand::DatabaseCommand()
diff --git a/src/cli/DatabaseCommand.h b/src/cli/DatabaseCommand.h
index 61847ffa..7e8818e5 100644
--- a/src/cli/DatabaseCommand.h
+++ b/src/cli/DatabaseCommand.h
@@ -18,11 +18,7 @@
#ifndef KEEPASSXC_DATABASECOMMAND_H
#define KEEPASSXC_DATABASECOMMAND_H
-#include
-
#include "Command.h"
-#include "Utils.h"
-#include "core/Database.h"
class DatabaseCommand : public Command
{
diff --git a/src/cli/Diceware.cpp b/src/cli/Diceware.cpp
index d0deb907..cd73bed3 100644
--- a/src/cli/Diceware.cpp
+++ b/src/cli/Diceware.cpp
@@ -15,13 +15,9 @@
* along with this program. If not, see .
*/
-#include
-#include
-
#include "Diceware.h"
#include "Utils.h"
-#include "cli/TextStream.h"
#include "core/PassphraseGenerator.h"
const QCommandLineOption Diceware::WordCountOption =
diff --git a/src/cli/Edit.cpp b/src/cli/Edit.cpp
index 4dcda4fd..d4564f8f 100644
--- a/src/cli/Edit.cpp
+++ b/src/cli/Edit.cpp
@@ -15,19 +15,13 @@
* along with this program. If not, see .
*/
-#include
-#include
-
#include "Edit.h"
-#include "cli/Add.h"
-#include "cli/Generate.h"
-#include "cli/TextStream.h"
-#include "cli/Utils.h"
-#include "core/Database.h"
+#include "Add.h"
+#include "Generate.h"
+#include "Utils.h"
#include "core/Entry.h"
#include "core/Group.h"
-#include "core/PasswordGenerator.h"
const QCommandLineOption Edit::TitleOption = QCommandLineOption(QStringList() << "t"
<< "title",
diff --git a/src/cli/Estimate.cpp b/src/cli/Estimate.cpp
index aca3118b..f97c8d1e 100644
--- a/src/cli/Estimate.cpp
+++ b/src/cli/Estimate.cpp
@@ -16,21 +16,11 @@
*/
#include "Estimate.h"
-#include "cli/Utils.h"
-#include "cli/TextStream.h"
+#include "Utils.h"
#include "core/PasswordHealth.h"
-#include
-#include
-#include
-#include
-/* For pre-compiled headers under windows */
-#ifdef _WIN32
-#ifndef __MINGW32__
-#include "stdafx.h"
-#endif
-#endif
+#include
const QCommandLineOption Estimate::AdvancedOption =
QCommandLineOption(QStringList() << "a"
diff --git a/src/cli/Exit.cpp b/src/cli/Exit.cpp
index 768088e4..83254203 100644
--- a/src/cli/Exit.cpp
+++ b/src/cli/Exit.cpp
@@ -17,10 +17,6 @@
#include "Exit.h"
-#include
-#include
-#include
-
Exit::Exit(const QString& name)
{
this->name = name;
diff --git a/src/cli/Export.cpp b/src/cli/Export.cpp
index 930324da..78778117 100644
--- a/src/cli/Export.cpp
+++ b/src/cli/Export.cpp
@@ -15,14 +15,10 @@
* along with this program. If not, see .
*/
-#include
-#include
-
#include "Export.h"
-#include "cli/TextStream.h"
-#include "cli/Utils.h"
-#include "core/Database.h"
+#include "TextStream.h"
+#include "Utils.h"
#include "format/CsvExporter.h"
const QCommandLineOption Export::FormatOption = QCommandLineOption(
diff --git a/src/cli/Generate.cpp b/src/cli/Generate.cpp
index c4761e6f..fef828f6 100644
--- a/src/cli/Generate.cpp
+++ b/src/cli/Generate.cpp
@@ -15,13 +15,10 @@
* along with this program. If not, see .
*/
-#include
-#include
-
#include "Generate.h"
-#include "cli/TextStream.h"
-#include "cli/Utils.h"
+#include "TextStream.h"
+#include "Utils.h"
const QCommandLineOption Generate::PasswordLengthOption =
QCommandLineOption(QStringList() << "L"
diff --git a/src/cli/Help.cpp b/src/cli/Help.cpp
index 07a3f085..6870b62a 100644
--- a/src/cli/Help.cpp
+++ b/src/cli/Help.cpp
@@ -17,8 +17,6 @@
#include "Help.h"
-#include "Command.h"
-#include "TextStream.h"
#include "Utils.h"
Help::Help()
diff --git a/src/cli/Import.cpp b/src/cli/Import.cpp
index 12afb3d2..104a9b53 100644
--- a/src/cli/Import.cpp
+++ b/src/cli/Import.cpp
@@ -15,22 +15,12 @@
* along with this program. If not, see .
*/
-#include
-#include
-
-#include
-#include
-#include
-
-#include "Create.h"
#include "Import.h"
-#include "cli/TextStream.h"
-#include "cli/Utils.h"
-#include "core/Database.h"
-#include "keys/CompositeKey.h"
-#include "keys/FileKey.h"
-#include "keys/Key.h"
+#include "Create.h"
+#include "Utils.h"
+
+#include
/**
* Create a database file from an XML export of another database.
diff --git a/src/cli/Info.cpp b/src/cli/Info.cpp
index 800996d6..5412dd0e 100644
--- a/src/cli/Info.cpp
+++ b/src/cli/Info.cpp
@@ -14,16 +14,12 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-#include
-#include
#include "Info.h"
-#include "Utils.h"
-#include "core/Database.h"
+#include "Utils.h"
#include "core/Global.h"
#include "core/Metadata.h"
-#include "format/KeePass2.h"
Info::Info()
{
diff --git a/src/cli/List.cpp b/src/cli/List.cpp
index ba00a716..8959e5f1 100644
--- a/src/cli/List.cpp
+++ b/src/cli/List.cpp
@@ -15,15 +15,9 @@
* along with this program. If not, see .
*/
-#include
-#include
-
#include "List.h"
-#include "cli/Utils.h"
-#include "cli/TextStream.h"
-#include "core/Database.h"
-#include "core/Entry.h"
+#include "Utils.h"
#include "core/Group.h"
const QCommandLineOption List::RecursiveOption =
diff --git a/src/cli/Locate.cpp b/src/cli/Locate.cpp
index a7a1e06f..ed1a39b7 100644
--- a/src/cli/Locate.cpp
+++ b/src/cli/Locate.cpp
@@ -15,18 +15,12 @@
* along with this program. If not, see .
*/
-#include
-#include
-
#include "Locate.h"
#include
-#include "cli/TextStream.h"
-#include "cli/Utils.h"
-#include "core/Database.h"
-#include "core/Entry.h"
-#include "core/Global.h"
+#include "TextStream.h"
+#include "Utils.h"
#include "core/Group.h"
Locate::Locate()
diff --git a/src/cli/Merge.cpp b/src/cli/Merge.cpp
index ce7ecc55..50f58f4c 100644
--- a/src/cli/Merge.cpp
+++ b/src/cli/Merge.cpp
@@ -15,13 +15,10 @@
* along with this program. If not, see .
*/
-#include
-
#include "Merge.h"
-#include "cli/TextStream.h"
-#include "cli/Utils.h"
-#include "core/Database.h"
+#include "TextStream.h"
+#include "Utils.h"
#include "core/Merger.h"
const QCommandLineOption Merge::SameCredentialsOption =
diff --git a/src/cli/Move.cpp b/src/cli/Move.cpp
index 74070372..960f9aae 100644
--- a/src/cli/Move.cpp
+++ b/src/cli/Move.cpp
@@ -15,14 +15,10 @@
* along with this program. If not, see .
*/
-#include
-#include
-
#include "Move.h"
-#include "cli/TextStream.h"
-#include "cli/Utils.h"
-#include "core/Database.h"
+#include "TextStream.h"
+#include "Utils.h"
#include "core/Entry.h"
#include "core/Group.h"
diff --git a/src/cli/Open.cpp b/src/cli/Open.cpp
index c4e9a79a..2f7492fc 100644
--- a/src/cli/Open.cpp
+++ b/src/cli/Open.cpp
@@ -17,12 +17,6 @@
#include "Open.h"
-#include
-
-#include "DatabaseCommand.h"
-#include "TextStream.h"
-#include "Utils.h"
-
Open::Open()
{
name = QString("open");
diff --git a/src/cli/Remove.cpp b/src/cli/Remove.cpp
index 6a3a87b0..2f5ed2e9 100644
--- a/src/cli/Remove.cpp
+++ b/src/cli/Remove.cpp
@@ -15,18 +15,12 @@
* along with this program. If not, see .
*/
-#include
-#include
-
#include "Remove.h"
-#include "cli/TextStream.h"
-#include "cli/Utils.h"
-#include "core/Database.h"
-#include "core/Entry.h"
+#include "TextStream.h"
+#include "Utils.h"
#include "core/Group.h"
#include "core/Metadata.h"
-#include "core/Tools.h"
Remove::Remove()
{
diff --git a/src/cli/RemoveGroup.cpp b/src/cli/RemoveGroup.cpp
index 5ebac16f..b11b759a 100644
--- a/src/cli/RemoveGroup.cpp
+++ b/src/cli/RemoveGroup.cpp
@@ -15,18 +15,12 @@
* along with this program. If not, see .
*/
-#include
-#include
-
#include "RemoveGroup.h"
-#include "cli/TextStream.h"
-#include "cli/Utils.h"
-#include "core/Database.h"
-#include "core/Entry.h"
+#include "TextStream.h"
+#include "Utils.h"
#include "core/Group.h"
#include "core/Metadata.h"
-#include "core/Tools.h"
RemoveGroup::RemoveGroup()
{
diff --git a/src/cli/Show.cpp b/src/cli/Show.cpp
index 02ec4677..97987716 100644
--- a/src/cli/Show.cpp
+++ b/src/cli/Show.cpp
@@ -17,18 +17,9 @@
#include "Show.h"
-#include
-#include
-
#include "Utils.h"
-#include "cli/TextStream.h"
-#include "core/Database.h"
-#include "core/Entry.h"
-#include "core/Global.h"
#include "core/Group.h"
-#include
-
const QCommandLineOption Show::TotpOption = QCommandLineOption(QStringList() << "t"
<< "totp",
QObject::tr("Show the entry's current TOTP."));
diff --git a/src/cli/Utils.cpp b/src/cli/Utils.cpp
index a4164987..b1c6ca64 100644
--- a/src/cli/Utils.cpp
+++ b/src/cli/Utils.cpp
@@ -17,6 +17,11 @@
#include "Utils.h"
+#include "core/Database.h"
+#include "core/EntryAttributes.h"
+#include "keys/CompositeKey.h"
+#include "keys/FileKey.h"
+#include "keys/PasswordKey.h"
#ifdef WITH_XC_YUBIKEY
#include "keys/YkChallengeResponseKey.h"
#endif
@@ -30,7 +35,7 @@
#include
#include
-#include
+#include
namespace Utils
{
@@ -91,7 +96,7 @@ namespace Utils
}
QSharedPointer unlockDatabase(const QString& databaseFilename,
- const bool isPasswordProtected,
+ bool isPasswordProtected,
const QString& keyFilename,
const QString& yubiKeySlot,
bool quiet)
@@ -289,7 +294,7 @@ namespace Utils
QStringList failedProgramNames;
- for (auto prog : clipPrograms) {
+ for (const auto& prog : clipPrograms) {
QScopedPointer clipProcess(new QProcess(nullptr));
// Skip empty parts, otherwise the program may clip the empty string
diff --git a/src/cli/Utils.h b/src/cli/Utils.h
index 5b3d5ad2..dedc818f 100644
--- a/src/cli/Utils.h
+++ b/src/cli/Utils.h
@@ -18,13 +18,13 @@
#ifndef KEEPASSXC_UTILS_H
#define KEEPASSXC_UTILS_H
-#include "cli/TextStream.h"
-#include "core/Database.h"
-#include "core/EntryAttributes.h"
-#include "keys/CompositeKey.h"
-#include "keys/FileKey.h"
-#include "keys/PasswordKey.h"
-#include
+#include
+
+class CompositeKey;
+class Database;
+class EntryAttributes;
+class FileKey;
+class PasswordKey;
namespace Utils
{
@@ -41,7 +41,7 @@ namespace Utils
QSharedPointer getConfirmedPassword();
int clipText(const QString& text);
QSharedPointer unlockDatabase(const QString& databaseFilename,
- const bool isPasswordProtected = true,
+ bool isPasswordProtected = true,
const QString& keyFilename = {},
const QString& yubiKeySlot = {},
bool quiet = false);
diff --git a/src/cli/keepassxc-cli.cpp b/src/cli/keepassxc-cli.cpp
index e55766ea..fb134161 100644
--- a/src/cli/keepassxc-cli.cpp
+++ b/src/cli/keepassxc-cli.cpp
@@ -15,20 +15,14 @@
* along with this program. If not, see .
*/
-#include
-#include
-
#include
-#include
-#include
-#include
+#include
#include
-#include "cli/TextStream.h"
-#include
-
+#include "Command.h"
#include "DatabaseCommand.h"
#include "Open.h"
+#include "TextStream.h"
#include "Utils.h"
#include "config-keepassx.h"
#include "core/Bootstrap.h"
@@ -165,10 +159,9 @@ void enterInteractiveMode(const QStringList& arguments)
break;
}
- cmd->currentDatabase = currentDatabase;
+ cmd->currentDatabase.swap(currentDatabase);
cmd->execute(args);
- currentDatabase = cmd->currentDatabase;
- cmd->currentDatabase.reset();
+ currentDatabase.swap(cmd->currentDatabase);
}
if (currentDatabase) {
@@ -179,7 +172,7 @@ void enterInteractiveMode(const QStringList& arguments)
int main(int argc, char** argv)
{
if (!Crypto::init()) {
- qFatal("Fatal error while testing the cryptographic functions:\n%s", qPrintable(Crypto::errorString()));
+ qWarning("Fatal error while testing the cryptographic functions:\n%s", qPrintable(Crypto::errorString()));
return EXIT_FAILURE;
}
diff --git a/tests/TestCli.cpp b/tests/TestCli.cpp
index fad5b98a..b01e9576 100644
--- a/tests/TestCli.cpp
+++ b/tests/TestCli.cpp
@@ -21,18 +21,17 @@
#include "core/Bootstrap.h"
#include "core/Config.h"
#include "core/Entry.h"
-#include "core/Global.h"
#include "core/Group.h"
#include "core/Metadata.h"
#include "core/Tools.h"
#include "crypto/Crypto.h"
+#include "keys/FileKey.h"
#include "keys/drivers/YubiKey.h"
#include "cli/Add.h"
#include "cli/AddGroup.h"
#include "cli/Analyze.h"
#include "cli/Clip.h"
-#include "cli/Command.h"
#include "cli/Create.h"
#include "cli/Diceware.h"
#include "cli/Edit.h"
@@ -53,16 +52,11 @@
#include "cli/Utils.h"
#include
-#include
-#include
#include
-#include
#include
QTEST_MAIN(TestCli)
-QSharedPointer globalCurrentDatabase;
-
void TestCli::initTestCase()
{
QVERIFY(Crypto::init());