2010-08-07 09:10:44 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
|
2017-06-09 17:40:36 -04:00
|
|
|
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
|
2010-08-07 09:10:44 -04:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 or (at your option)
|
|
|
|
* version 3 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2018-10-31 23:27:38 -04:00
|
|
|
#include <QCommandLineParser>
|
2013-10-03 09:18:16 -04:00
|
|
|
#include <QFile>
|
2016-10-24 14:22:02 -04:00
|
|
|
#include <QTextStream>
|
2010-08-15 06:31:48 -04:00
|
|
|
|
2018-10-31 23:27:38 -04:00
|
|
|
#include "cli/Utils.h"
|
2014-01-18 09:31:24 -05:00
|
|
|
#include "config-keepassx.h"
|
2018-09-29 13:00:47 -04:00
|
|
|
#include "core/Bootstrap.h"
|
|
|
|
#include "core/Config.h"
|
2018-10-31 23:27:38 -04:00
|
|
|
#include "core/Tools.h"
|
2010-09-13 17:25:48 -04:00
|
|
|
#include "crypto/Crypto.h"
|
2012-05-17 18:35:24 -04:00
|
|
|
#include "gui/Application.h"
|
2010-09-19 10:59:32 -04:00
|
|
|
#include "gui/MainWindow.h"
|
2014-06-15 05:17:40 -04:00
|
|
|
#include "gui/MessageBox.h"
|
2018-03-08 10:24:11 -05:00
|
|
|
|
2017-03-14 09:53:29 -04:00
|
|
|
#if defined(WITH_ASAN) && defined(WITH_LSAN)
|
2017-03-14 10:32:48 -04:00
|
|
|
#include <sanitizer/lsan_interface.h>
|
|
|
|
#endif
|
|
|
|
|
2017-01-25 19:15:12 -05:00
|
|
|
#ifdef QT_STATIC
|
|
|
|
#include <QtPlugin>
|
|
|
|
|
2017-12-27 14:31:15 -05:00
|
|
|
#if defined(Q_OS_WIN)
|
2017-01-25 19:15:12 -05:00
|
|
|
Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
|
2018-10-26 09:19:04 -04:00
|
|
|
#elif defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
|
2017-01-25 19:15:12 -05:00
|
|
|
Q_IMPORT_PLUGIN(QXcbIntegrationPlugin)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2012-05-02 11:04:03 -04:00
|
|
|
int main(int argc, char** argv)
|
2010-08-07 09:10:44 -04:00
|
|
|
{
|
2019-01-24 22:45:05 -05:00
|
|
|
QT_REQUIRE_VERSION(argc, argv, QT_VERSION_STR)
|
|
|
|
|
2018-10-20 06:18:33 -04:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
|
|
|
|
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
2019-06-30 11:06:58 -04:00
|
|
|
QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
|
|
|
#endif
|
2018-10-20 06:18:33 -04:00
|
|
|
|
2012-05-17 18:35:24 -04:00
|
|
|
Application app(argc, argv);
|
2019-11-08 17:54:56 -05:00
|
|
|
Application::setApplicationName("KeePassXC");
|
2018-10-19 15:41:42 -04:00
|
|
|
Application::setApplicationVersion(KEEPASSXC_VERSION);
|
2020-04-29 11:47:25 -04:00
|
|
|
app.setProperty("KPXC_QUALIFIED_APPNAME", "org.keepassxc.KeePassXC");
|
2020-06-04 08:10:43 -04:00
|
|
|
app.applyTheme();
|
2020-04-29 11:47:25 -04:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
|
|
|
|
QGuiApplication::setDesktopFileName(app.property("KPXC_QUALIFIED_APPNAME").toString() + QStringLiteral(".desktop"));
|
|
|
|
#endif
|
2020-01-05 21:00:25 -05:00
|
|
|
|
2014-01-18 09:31:24 -05:00
|
|
|
// don't set organizationName as that changes the return value of
|
2015-09-12 12:41:48 -04:00
|
|
|
// QStandardPaths::writableLocation(QDesktopServices::DataLocation)
|
2018-09-29 13:00:47 -04:00
|
|
|
Bootstrap::bootstrapApplication();
|
2010-08-15 06:31:48 -04:00
|
|
|
|
2014-01-18 09:23:55 -05:00
|
|
|
QCommandLineParser parser;
|
2019-03-19 14:48:33 -04:00
|
|
|
parser.setApplicationDescription(QObject::tr("KeePassXC - cross-platform password manager"));
|
2018-10-31 23:27:38 -04:00
|
|
|
parser.addPositionalArgument(
|
2019-03-19 14:48:33 -04:00
|
|
|
"filename", QObject::tr("filenames of the password databases to open (*.kdbx)"), "[filename(s)]");
|
2018-03-31 16:01:30 -04:00
|
|
|
|
2019-03-19 14:48:33 -04:00
|
|
|
QCommandLineOption configOption("config", QObject::tr("path to a custom config file"), "config");
|
|
|
|
QCommandLineOption keyfileOption("keyfile", QObject::tr("key file of the database"), "keyfile");
|
|
|
|
QCommandLineOption pwstdinOption("pw-stdin", QObject::tr("read password of the database from stdin"));
|
2017-12-12 03:15:23 -05:00
|
|
|
// This is needed under Windows where clients send --parent-window parameter with Native Messaging connect method
|
2018-10-31 23:27:38 -04:00
|
|
|
QCommandLineOption parentWindowOption(QStringList() << "pw"
|
|
|
|
<< "parent-window",
|
2019-01-30 20:54:35 -05:00
|
|
|
QObject::tr("Parent window handle"),
|
2018-10-31 23:27:38 -04:00
|
|
|
"handle");
|
2014-01-18 09:23:55 -05:00
|
|
|
|
2018-10-08 12:29:08 -04:00
|
|
|
QCommandLineOption helpOption = parser.addHelpOption();
|
2018-06-29 20:46:33 -04:00
|
|
|
QCommandLineOption versionOption = parser.addVersionOption();
|
2019-05-12 17:42:55 -04:00
|
|
|
QCommandLineOption debugInfoOption(QStringList() << "debug-info", QObject::tr("Displays debugging information."));
|
2014-01-18 09:23:55 -05:00
|
|
|
parser.addOption(configOption);
|
|
|
|
parser.addOption(keyfileOption);
|
2016-10-24 14:22:02 -04:00
|
|
|
parser.addOption(pwstdinOption);
|
2017-12-12 03:15:23 -05:00
|
|
|
parser.addOption(parentWindowOption);
|
2019-02-18 20:17:28 -05:00
|
|
|
parser.addOption(debugInfoOption);
|
2014-01-18 09:23:55 -05:00
|
|
|
|
|
|
|
parser.process(app);
|
2018-10-31 23:27:38 -04:00
|
|
|
|
2018-10-08 12:29:08 -04:00
|
|
|
// Don't try and do anything with the application if we're only showing the help / version
|
|
|
|
if (parser.isSet(versionOption) || parser.isSet(helpOption)) {
|
2019-02-18 20:17:28 -05:00
|
|
|
return EXIT_SUCCESS;
|
2018-10-08 12:29:08 -04:00
|
|
|
}
|
2018-10-31 23:27:38 -04:00
|
|
|
|
2017-12-05 10:25:08 -05:00
|
|
|
const QStringList fileNames = parser.positionalArguments();
|
|
|
|
|
2018-10-27 09:58:50 -04:00
|
|
|
if (app.isAlreadyRunning()) {
|
2017-12-05 10:25:08 -05:00
|
|
|
if (!fileNames.isEmpty()) {
|
|
|
|
app.sendFileNamesToRunningInstance(fileNames);
|
|
|
|
}
|
2019-03-19 14:48:33 -04:00
|
|
|
qWarning() << QObject::tr("Another instance of KeePassXC is already running.").toUtf8().constData();
|
2019-02-18 20:17:28 -05:00
|
|
|
return EXIT_SUCCESS;
|
2017-12-05 10:25:08 -05:00
|
|
|
}
|
2017-12-12 03:15:23 -05:00
|
|
|
|
2017-12-05 10:25:08 -05:00
|
|
|
QApplication::setQuitOnLastWindowClosed(false);
|
|
|
|
|
|
|
|
if (!Crypto::init()) {
|
2019-01-30 20:54:35 -05:00
|
|
|
QString error = QObject::tr("Fatal error while testing the cryptographic functions.");
|
2017-12-05 10:25:08 -05:00
|
|
|
error.append("\n");
|
|
|
|
error.append(Crypto::errorString());
|
2019-01-30 20:54:35 -05:00
|
|
|
MessageBox::critical(nullptr, QObject::tr("KeePassXC - Error"), error);
|
2019-02-18 20:17:28 -05:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Displaying the debugging informations must be done after Crypto::init,
|
|
|
|
// to make sure we know which libgcrypt version is used.
|
|
|
|
if (parser.isSet(debugInfoOption)) {
|
|
|
|
QTextStream out(stdout, QIODevice::WriteOnly);
|
|
|
|
QString debugInfo = Tools::debugInfo().append("\n").append(Crypto::debugInfo());
|
|
|
|
out << debugInfo << endl;
|
|
|
|
return EXIT_SUCCESS;
|
2017-12-05 10:25:08 -05:00
|
|
|
}
|
2014-01-18 09:23:55 -05:00
|
|
|
|
|
|
|
if (parser.isSet(configOption)) {
|
|
|
|
Config::createConfigFromFile(parser.value(configOption));
|
2012-04-24 05:47:16 -04:00
|
|
|
}
|
|
|
|
|
2010-09-19 10:59:32 -04:00
|
|
|
MainWindow mainWindow;
|
2017-12-05 10:25:08 -05:00
|
|
|
QObject::connect(&app, SIGNAL(anotherInstanceStarted()), &mainWindow, SLOT(bringToFront()));
|
|
|
|
QObject::connect(&app, SIGNAL(applicationActivated()), &mainWindow, SLOT(bringToFront()));
|
2012-05-21 16:11:26 -04:00
|
|
|
QObject::connect(&app, SIGNAL(openFile(QString)), &mainWindow, SLOT(openDatabase(QString)));
|
2017-12-05 10:25:08 -05:00
|
|
|
QObject::connect(&app, SIGNAL(quitSignalReceived()), &mainWindow, SLOT(appExit()), Qt::DirectConnection);
|
2017-12-12 03:15:23 -05:00
|
|
|
|
2018-09-29 13:00:47 -04:00
|
|
|
Bootstrap::restoreMainWindowState(mainWindow);
|
2017-04-05 09:00:40 -04:00
|
|
|
|
2017-12-05 10:25:08 -05:00
|
|
|
const bool pwstdin = parser.isSet(pwstdinOption);
|
2018-03-31 16:01:30 -04:00
|
|
|
for (const QString& filename : fileNames) {
|
2018-03-04 17:56:06 -05:00
|
|
|
QString password;
|
|
|
|
if (pwstdin) {
|
|
|
|
// we always need consume a line of STDIN if --pw-stdin is set to clear out the
|
|
|
|
// buffer for native messaging, even if the specified file does not exist
|
2019-04-25 10:37:13 -04:00
|
|
|
QTextStream out(stdout, QIODevice::WriteOnly);
|
2019-01-30 20:54:35 -05:00
|
|
|
out << QObject::tr("Database password: ") << flush;
|
2018-03-08 10:24:11 -05:00
|
|
|
password = Utils::getPassword();
|
2018-03-04 17:56:06 -05:00
|
|
|
}
|
|
|
|
|
2017-12-12 03:15:23 -05:00
|
|
|
if (!filename.isEmpty() && QFile::exists(filename) && !filename.endsWith(".json", Qt::CaseInsensitive)) {
|
2018-03-02 19:19:30 -05:00
|
|
|
mainWindow.openDatabase(filename, password, parser.value(keyfileOption));
|
2014-01-18 09:23:55 -05:00
|
|
|
}
|
2012-04-24 05:47:16 -04:00
|
|
|
}
|
|
|
|
|
2018-09-29 13:00:47 -04:00
|
|
|
int exitCode = Application::exec();
|
2017-03-14 10:32:48 -04:00
|
|
|
|
2017-03-14 09:53:29 -04:00
|
|
|
#if defined(WITH_ASAN) && defined(WITH_LSAN)
|
2017-03-14 10:32:48 -04:00
|
|
|
// do leak check here to prevent massive tail of end-of-process leak errors from third-party libraries
|
|
|
|
__lsan_do_leak_check();
|
|
|
|
__lsan_disable();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return exitCode;
|
2010-08-07 09:10:44 -04:00
|
|
|
}
|