Skip to content

Commit

Permalink
Performed project-wide code formatting
Browse files Browse the repository at this point in the history
* Updated format CMake command to properly
ignore new directories and files
* Added output when command is run
* Resolves keepassxreboot#2623
  • Loading branch information
droidmonkey committed Jan 29, 2019
1 parent c746640 commit 7e1b162
Show file tree
Hide file tree
Showing 68 changed files with 594 additions and 545 deletions.
22 changes: 14 additions & 8 deletions cmake/CLangFormat.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@

set(EXCLUDED_DIRS
# third-party directories
zxcvbn/
streams/QtIOCompressor
src/zxcvbn/
# objective-c directories
autotype/mac)
src/touchid/
src/autotype/mac/
src/gui/macutils/)

set(EXCLUDED_FILES
# third-party files
Expand All @@ -37,7 +38,7 @@ set(EXCLUDED_FILES
core/ScreenLockListenerMac.h
core/ScreenLockListenerMac.cpp)

file(GLOB_RECURSE ALL_SOURCE_FILES *.cpp *.h)
file(GLOB_RECURSE ALL_SOURCE_FILES RELATIVE ${CMAKE_SOURCE_DIR} src/*.cpp src/*.h tests/*.cpp tests/*.h)
foreach(SOURCE_FILE ${ALL_SOURCE_FILES})
foreach(EXCLUDED_DIR ${EXCLUDED_DIRS})
string(FIND ${SOURCE_FILE} ${EXCLUDED_DIR} SOURCE_FILE_EXCLUDED)
Expand All @@ -52,7 +53,12 @@ foreach(SOURCE_FILE ${ALL_SOURCE_FILES})
endforeach()
endforeach()

add_custom_target(
format
COMMAND echo ${ALL_SOURCE_FILES} | xargs clang-format -style=file -i
)
add_custom_target(format)
foreach(SOURCE_FILE ${ALL_SOURCE_FILES})
add_custom_command(
TARGET format
PRE_BUILD
COMMAND echo Formatting ${SOURCE_FILE}
COMMAND clang-format -style=file -i \"${SOURCE_FILE}\"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
endforeach()
50 changes: 27 additions & 23 deletions src/browser/BrowserService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ bool BrowserService::isDatabaseOpened() const
return false;
}

return dbWidget->currentMode() == DatabaseWidget::Mode::ViewMode || dbWidget->currentMode() == DatabaseWidget::Mode::EditMode;
return dbWidget->currentMode() == DatabaseWidget::Mode::ViewMode
|| dbWidget->currentMode() == DatabaseWidget::Mode::EditMode;
}

bool BrowserService::openDatabase(bool triggerUnlock)
Expand All @@ -91,7 +92,8 @@ bool BrowserService::openDatabase(bool triggerUnlock)
return false;
}

if (dbWidget->currentMode() == DatabaseWidget::Mode::ViewMode || dbWidget->currentMode() == DatabaseWidget::Mode::EditMode) {
if (dbWidget->currentMode() == DatabaseWidget::Mode::ViewMode
|| dbWidget->currentMode() == DatabaseWidget::Mode::EditMode) {
return true;
}

Expand All @@ -114,7 +116,8 @@ void BrowserService::lockDatabase()
return;
}

if (dbWidget->currentMode() == DatabaseWidget::Mode::ViewMode || dbWidget->currentMode() == DatabaseWidget::Mode::EditMode) {
if (dbWidget->currentMode() == DatabaseWidget::Mode::ViewMode
|| dbWidget->currentMode() == DatabaseWidget::Mode::EditMode) {
dbWidget->lock();
}
}
Expand Down Expand Up @@ -289,9 +292,12 @@ QJsonArray BrowserService::findMatchingEntries(const QString& id,
return result;
}

void BrowserService::addEntry(const QString& id, const QString& login,
const QString& password, const QString& url,
const QString& submitUrl, const QString& realm,
void BrowserService::addEntry(const QString& id,
const QString& login,
const QString& password,
const QString& url,
const QString& submitUrl,
const QString& realm,
QSharedPointer<Database> selectedDb)
{
if (thread() != QThread::currentThread()) {
Expand Down Expand Up @@ -392,12 +398,13 @@ void BrowserService::updateEntry(const QString& id,
MessageBox::Button dialogResult = MessageBox::No;
if (!browserSettings()->alwaysAllowUpdate()) {
raiseWindow();
dialogResult = MessageBox::question(nullptr,
tr("KeePassXC: Update Entry"),
tr("Do you want to update the information in %1 - %2?")
.arg(QUrl(url).host(), username),
MessageBox::Save | MessageBox::Cancel,
MessageBox::Cancel, MessageBox::Raise);
dialogResult = MessageBox::question(
nullptr,
tr("KeePassXC: Update Entry"),
tr("Do you want to update the information in %1 - %2?").arg(QUrl(url).host(), username),
MessageBox::Save | MessageBox::Cancel,
MessageBox::Cancel,
MessageBox::Raise);
}

if (browserSettings()->alwaysAllowUpdate() || dialogResult == MessageBox::Save) {
Expand Down Expand Up @@ -453,7 +460,7 @@ QList<Entry*> BrowserService::searchEntries(const QString& url, const StringPair
for (int i = 0; i < count; ++i) {
if (auto* dbWidget = qobject_cast<DatabaseWidget*>(m_dbTabWidget->widget(i))) {
if (const auto& db = dbWidget->database()) {
// Check if database is connected with KeePassXC-Browser
// Check if database is connected with KeePassXC-Browser
for (const StringPair& keyPair : keyList) {
QString key =
db->metadata()->customData()->value(QLatin1String(ASSOCIATE_KEY_PREFIX) + keyPair.first);
Expand Down Expand Up @@ -680,10 +687,7 @@ QJsonObject BrowserService::prepareEntry(const Entry* entry)
}

BrowserService::Access
BrowserService::checkAccess(const Entry* entry,
const QString& host,
const QString& submitHost,
const QString& realm)
BrowserService::checkAccess(const Entry* entry, const QString& host, const QString& submitHost, const QString& realm)
{
BrowserEntryConfig config;
if (!config.load(entry)) {
Expand Down Expand Up @@ -841,12 +845,12 @@ QSharedPointer<Database> BrowserService::getDatabase()
QSharedPointer<Database> BrowserService::selectedDatabase()
{
QList<DatabaseWidget*> databaseWidgets;
for (int i = 0; ; ++i) {
for (int i = 0;; ++i) {
auto* dbWidget = m_dbTabWidget->databaseWidgetFromIndex(i);
// Add only open databases
if (dbWidget && dbWidget->database()->hasKey() &&
(dbWidget->currentMode() == DatabaseWidget::Mode::ViewMode ||
dbWidget->currentMode() == DatabaseWidget::Mode::EditMode)) {
if (dbWidget && dbWidget->database()->hasKey()
&& (dbWidget->currentMode() == DatabaseWidget::Mode::ViewMode
|| dbWidget->currentMode() == DatabaseWidget::Mode::EditMode)) {
databaseWidgets.push_back(dbWidget);
continue;
}
Expand Down Expand Up @@ -919,8 +923,8 @@ bool BrowserService::checkLegacySettings()
bool legacySettingsFound = false;
QList<Entry*> entries = db->rootGroup()->entriesRecursive();
for (const auto& e : entries) {
if ((e->attributes()->contains(KEEPASSHTTP_NAME) || e->attributes()->contains(KEEPASSXCBROWSER_NAME)) ||
(e->title() == KEEPASSHTTP_NAME || e->title().contains(KEEPASSXCBROWSER_NAME, Qt::CaseInsensitive))) {
if ((e->attributes()->contains(KEEPASSHTTP_NAME) || e->attributes()->contains(KEEPASSXCBROWSER_NAME))
|| (e->title() == KEEPASSHTTP_NAME || e->title().contains(KEEPASSXCBROWSER_NAME, Qt::CaseInsensitive))) {
legacySettingsFound = true;
break;
}
Expand Down
5 changes: 1 addition & 4 deletions src/browser/BrowserService.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,7 @@ public slots:
const QString& submitHost,
const QString& realm);
QJsonObject prepareEntry(const Entry* entry);
Access checkAccess(const Entry* entry,
const QString& host,
const QString& submitHost,
const QString& realm);
Access checkAccess(const Entry* entry, const QString& host, const QString& submitHost, const QString& realm);
Group* findCreateAddEntryGroup(QSharedPointer<Database> selectedDb = {});
int
sortPriority(const Entry* entry, const QString& host, const QString& submitUrl, const QString& baseSubmitUrl) const;
Expand Down
9 changes: 4 additions & 5 deletions src/cli/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ const QCommandLineOption Command::QuietOption =
<< "quiet",
QObject::tr("Silence password prompt and other secondary outputs."));

const QCommandLineOption Command::KeyFileOption =
QCommandLineOption(QStringList() << "k"
<< "key-file",
QObject::tr("Key file of the database."),
QObject::tr("path"));
const QCommandLineOption Command::KeyFileOption = QCommandLineOption(QStringList() << "k"
<< "key-file",
QObject::tr("Key file of the database."),
QObject::tr("path"));

QMap<QString, Command*> commands;

Expand Down
2 changes: 1 addition & 1 deletion src/cli/Create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ int Create::execute(const QStringList& arguments)
}

QSharedPointer<FileKey> fileKey;
if(parser.isSet(Command::KeyFileOption)) {
if (parser.isSet(Command::KeyFileOption)) {
if (!loadFileKey(parser.value(Command::KeyFileOption), fileKey)) {
err << QObject::tr("Loading the key file failed") << endl;
return EXIT_FAILURE;
Expand Down
6 changes: 3 additions & 3 deletions src/cli/Extract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ int Extract::execute(const QStringList& arguments)

if (fileKey->type() != FileKey::Hashed) {
errorTextStream << QObject::tr("WARNING: You are using a legacy key file format which may become\n"
"unsupported in the future.\n\n"
"Please consider generating a new key file.")
<< endl;
"unsupported in the future.\n\n"
"Please consider generating a new key file.")
<< endl;
}
// LCOV_EXCL_STOP

Expand Down
101 changes: 50 additions & 51 deletions src/cli/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,13 @@ namespace Utils
* DEVNULL file handle for the CLI.
*/
#ifdef Q_OS_WIN
FILE* DEVNULL = fopen("nul", "w");
FILE* DEVNULL = fopen("nul", "w");
#else
FILE* DEVNULL = fopen("/dev/null", "w");
FILE* DEVNULL = fopen("/dev/null", "w");
#endif


void setStdinEcho(bool enable = true)
{
void setStdinEcho(bool enable = true)
{
#ifdef Q_OS_WIN
HANDLE hIn = GetStdHandle(STD_INPUT_HANDLE);
DWORD mode;
Expand Down Expand Up @@ -98,61 +97,61 @@ void setStdinEcho(bool enable = true)
}
} // namespace Test

QSharedPointer<Database> unlockDatabase(const QString& databaseFilename,
const QString& keyFilename,
FILE* outputDescriptor,
FILE* errorDescriptor)
{
auto compositeKey = QSharedPointer<CompositeKey>::create();
TextStream out(outputDescriptor);
TextStream err(errorDescriptor);

out << QObject::tr("Insert password to unlock %1: ").arg(databaseFilename) << flush;

QString line = Utils::getPassword(outputDescriptor);
auto passwordKey = QSharedPointer<PasswordKey>::create();
passwordKey->setPassword(line);
compositeKey->addKey(passwordKey);

if (!keyFilename.isEmpty()) {
auto fileKey = QSharedPointer<FileKey>::create();
QString errorMessage;
// LCOV_EXCL_START
if (!fileKey->load(keyFilename, &errorMessage)) {
err << QObject::tr("Failed to load key file %1: %2").arg(keyFilename, errorMessage) << endl;
return {};
}

if (fileKey->type() != FileKey::Hashed) {
err << QObject::tr("WARNING: You are using a legacy key file format which may become\n"
"unsupported in the future.\n\n"
"Please consider generating a new key file.")
<< endl;
QSharedPointer<Database> unlockDatabase(const QString& databaseFilename,
const QString& keyFilename,
FILE* outputDescriptor,
FILE* errorDescriptor)
{
auto compositeKey = QSharedPointer<CompositeKey>::create();
TextStream out(outputDescriptor);
TextStream err(errorDescriptor);

out << QObject::tr("Insert password to unlock %1: ").arg(databaseFilename) << flush;

QString line = Utils::getPassword(outputDescriptor);
auto passwordKey = QSharedPointer<PasswordKey>::create();
passwordKey->setPassword(line);
compositeKey->addKey(passwordKey);

if (!keyFilename.isEmpty()) {
auto fileKey = QSharedPointer<FileKey>::create();
QString errorMessage;
// LCOV_EXCL_START
if (!fileKey->load(keyFilename, &errorMessage)) {
err << QObject::tr("Failed to load key file %1: %2").arg(keyFilename, errorMessage) << endl;
return {};
}

if (fileKey->type() != FileKey::Hashed) {
err << QObject::tr("WARNING: You are using a legacy key file format which may become\n"
"unsupported in the future.\n\n"
"Please consider generating a new key file.")
<< endl;
}
// LCOV_EXCL_STOP

compositeKey->addKey(fileKey);
}
// LCOV_EXCL_STOP

compositeKey->addKey(fileKey);
}

auto db = QSharedPointer<Database>::create();
QString error;
auto db = QSharedPointer<Database>::create();
QString error;
if (db->open(databaseFilename, compositeKey, &error, false)) {
return db;
} else {
}else {
err << error << endl;
return {};
}
}

/**
* Read a user password from STDIN or return a password previously
* set by \link setNextPassword().
*
* @return the password
*/
QString getPassword(FILE* outputDescriptor)
{
TextStream out(outputDescriptor, QIODevice::WriteOnly);
/**
* Read a user password from STDIN or return a password previously
* set by \link setNextPassword().
*
* @return the password
*/
QString getPassword(FILE* outputDescriptor)
{
TextStream out(outputDescriptor, QIODevice::WriteOnly);

// return preset password if one is set
if (!Test::nextPasswords.isEmpty()) {
Expand Down
6 changes: 3 additions & 3 deletions src/cli/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ namespace Utils
QString getPassword(FILE* outputDescriptor = STDOUT);
int clipText(const QString& text);
QSharedPointer<Database> unlockDatabase(const QString& databaseFilename,
const QString& keyFilename = {},
FILE* outputDescriptor = STDOUT,
FILE* errorDescriptor = STDERR);
const QString& keyFilename = {},
FILE* outputDescriptor = STDOUT,
FILE* errorDescriptor = STDERR);

namespace Test
{
Expand Down
11 changes: 5 additions & 6 deletions src/core/Bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,11 @@ namespace Bootstrap

#ifdef WITH_XC_SSHAGENT
// OpenSSH for Windows ssh-agent service is running as LocalSystem
if (!AddAccessAllowedAce(
pACL,
ACL_REVISION,
PROCESS_QUERY_INFORMATION | PROCESS_DUP_HANDLE, // just enough for ssh-agent
pLocalSystemSid // known LocalSystem sid
)) {
if (!AddAccessAllowedAce(pACL,
ACL_REVISION,
PROCESS_QUERY_INFORMATION | PROCESS_DUP_HANDLE, // just enough for ssh-agent
pLocalSystemSid // known LocalSystem sid
)) {
goto Cleanup;
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/core/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
#include "keys/PasswordKey.h"

#include <QFile>
#include <QFileInfo>
#include <QSaveFile>
#include <QTemporaryFile>
#include <QTimer>
#include <QXmlStreamReader>
#include <QFileInfo>

QHash<QUuid, QPointer<Database>> Database::s_uuidMap;
QHash<QString, QPointer<Database>> Database::s_filePathMap;
Expand Down
Loading

0 comments on commit 7e1b162

Please sign in to comment.