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/>.
|
|
|
|
*/
|
|
|
|
|
2015-07-22 11:02:50 -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
|
|
|
|
2014-01-18 09:31:24 -05:00
|
|
|
#include "config-keepassx.h"
|
2013-03-29 15:35:54 -04:00
|
|
|
#include "core/Config.h"
|
2012-10-13 05:05:50 -04:00
|
|
|
#include "core/Tools.h"
|
2014-05-17 19:33:22 -04:00
|
|
|
#include "core/Translator.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"
|
2010-08-15 06:31:48 -04:00
|
|
|
|
2018-03-08 10:24:11 -05:00
|
|
|
#include "cli/Utils.h"
|
|
|
|
|
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)
|
2017-12-27 14:31:15 -05:00
|
|
|
#elif defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
|
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
|
|
|
{
|
2012-10-13 05:05:50 -04:00
|
|
|
#ifdef QT_NO_DEBUG
|
|
|
|
Tools::disableCoreDumps();
|
|
|
|
#endif
|
2015-12-06 08:32:06 -05:00
|
|
|
Tools::setupSearchPaths();
|
2017-02-19 17:42:05 -05:00
|
|
|
|
2012-05-17 18:35:24 -04:00
|
|
|
Application app(argc, argv);
|
2016-11-03 00:05:30 -04:00
|
|
|
Application::setApplicationName("keepassxc");
|
2014-01-18 09:31:24 -05:00
|
|
|
Application::setApplicationVersion(KEEPASSX_VERSION);
|
|
|
|
// don't set organizationName as that changes the return value of
|
2015-09-12 12:41:48 -04:00
|
|
|
// QStandardPaths::writableLocation(QDesktopServices::DataLocation)
|
2010-08-15 06:31:48 -04:00
|
|
|
|
2014-01-18 09:23:55 -05:00
|
|
|
QCommandLineParser parser;
|
2016-11-03 00:05:30 -04:00
|
|
|
parser.setApplicationDescription(QCoreApplication::translate("main", "KeePassXC - cross-platform password manager"));
|
2017-02-18 09:51:01 -05:00
|
|
|
parser.addPositionalArgument("filename", QCoreApplication::translate("main", "filenames of the password databases to open (*.kdbx)"), "[filename(s)]");
|
2013-03-29 15:35:54 -04:00
|
|
|
|
2014-01-18 09:23:55 -05:00
|
|
|
QCommandLineOption configOption("config",
|
|
|
|
QCoreApplication::translate("main", "path to a custom config file"),
|
|
|
|
"config");
|
|
|
|
QCommandLineOption keyfileOption("keyfile",
|
|
|
|
QCoreApplication::translate("main", "key file of the database"),
|
|
|
|
"keyfile");
|
2016-10-24 14:22:02 -04:00
|
|
|
QCommandLineOption pwstdinOption("pw-stdin",
|
|
|
|
QCoreApplication::translate("main", "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
|
|
|
|
QCommandLineOption parentWindowOption(QStringList() << "pw"
|
|
|
|
<< "parent-window",
|
|
|
|
QCoreApplication::translate("main", "Parent window handle"),
|
|
|
|
"handle");
|
2014-01-18 09:23:55 -05:00
|
|
|
|
|
|
|
parser.addHelpOption();
|
2014-01-18 09:31:24 -05:00
|
|
|
parser.addVersionOption();
|
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);
|
2014-01-18 09:23:55 -05:00
|
|
|
|
|
|
|
parser.process(app);
|
2017-12-05 10:25:08 -05:00
|
|
|
const QStringList fileNames = parser.positionalArguments();
|
|
|
|
|
|
|
|
if (app.isAlreadyRunning()) {
|
|
|
|
if (!fileNames.isEmpty()) {
|
|
|
|
app.sendFileNamesToRunningInstance(fileNames);
|
|
|
|
}
|
|
|
|
qWarning() << QCoreApplication::translate("Main", "Another instance of KeePassXC is already running.").toUtf8().constData();
|
|
|
|
return 0;
|
|
|
|
}
|
2017-12-12 03:15:23 -05:00
|
|
|
|
2017-12-05 10:25:08 -05:00
|
|
|
QApplication::setQuitOnLastWindowClosed(false);
|
|
|
|
|
|
|
|
if (!Crypto::init()) {
|
|
|
|
QString error = QCoreApplication::translate("Main",
|
|
|
|
"Fatal error while testing the cryptographic functions.");
|
|
|
|
error.append("\n");
|
|
|
|
error.append(Crypto::errorString());
|
|
|
|
MessageBox::critical(nullptr, QCoreApplication::translate("Main", "KeePassXC - Error"), error);
|
|
|
|
return 1;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2017-12-19 18:18:42 -05:00
|
|
|
Translator::installTranslators();
|
2014-05-17 19:33:22 -04:00
|
|
|
|
2013-03-30 06:16:24 -04:00
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
// Don't show menu icons on OSX
|
|
|
|
QApplication::setAttribute(Qt::AA_DontShowIconsInMenus);
|
|
|
|
#endif
|
|
|
|
|
2010-09-19 10:59:32 -04:00
|
|
|
MainWindow mainWindow;
|
2015-10-10 11:00:50 -04:00
|
|
|
app.setMainWindow(&mainWindow);
|
2016-07-25 00:41:13 -04:00
|
|
|
|
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
|
|
|
|
2016-11-26 09:37:25 -05:00
|
|
|
// start minimized if configured
|
2017-02-14 13:08:14 -05:00
|
|
|
bool minimizeOnStartup = config()->get("GUI/MinimizeOnStartup").toBool();
|
|
|
|
bool minimizeToTray = config()->get("GUI/MinimizeToTray").toBool();
|
2018-03-11 09:03:48 -04:00
|
|
|
if (minimizeOnStartup && !minimizeToTray) {
|
2016-11-26 09:37:25 -05:00
|
|
|
mainWindow.setWindowState(Qt::WindowMinimized);
|
2017-02-14 13:08:14 -05:00
|
|
|
}
|
|
|
|
if (!(minimizeOnStartup && minimizeToTray)) {
|
2017-02-14 09:55:33 -05:00
|
|
|
mainWindow.show();
|
2016-11-26 09:37:25 -05:00
|
|
|
}
|
2017-12-12 03:15:23 -05:00
|
|
|
|
2017-04-05 09:00:40 -04:00
|
|
|
if (config()->get("OpenPreviousDatabasesOnStartup").toBool()) {
|
2017-12-05 10:25:08 -05:00
|
|
|
const QStringList fileNames = config()->get("LastOpenedDatabases").toStringList();
|
|
|
|
for (const QString& filename: fileNames) {
|
2017-04-05 09:00:40 -04:00
|
|
|
if (!filename.isEmpty() && QFile::exists(filename)) {
|
2017-12-05 10:25:08 -05:00
|
|
|
mainWindow.openDatabase(filename);
|
2017-04-05 09:00:40 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-05 10:25:08 -05:00
|
|
|
const bool pwstdin = parser.isSet(pwstdinOption);
|
|
|
|
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
|
|
|
|
static QTextStream in(stdin, QIODevice::ReadOnly);
|
2018-03-08 10:24:11 -05:00
|
|
|
static QTextStream out(stdout, QIODevice::WriteOnly);
|
|
|
|
out << QCoreApplication::translate("Main", "Database password: ") << flush;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-03-14 10:32:48 -04:00
|
|
|
int exitCode = app.exec();
|
|
|
|
|
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
|
|
|
}
|