Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct opening files from command line #2919

Merged
merged 5 commits into from
Apr 3, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/core/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,11 +388,31 @@ const Metadata* Database::metadata() const
return m_metadata;
}

/**
* Returns the original file path that was provided for
* this database. This path may not exist, may contain
* unresolved symlinks, or have malformed slashes.
*
* @return original file path
*/
QString Database::filePath() const
{
return m_data.filePath;
}

/**
* Returns the canonical file path of this databases'
* set file path. This returns an empty string if the
* file does not exist or cannot be resolved.
*
* @return canonical file path
*/
QString Database::canonicalFilePath() const
{
QFileInfo fileInfo(m_data.filePath);
return fileInfo.canonicalFilePath();
}

void Database::setFilePath(const QString& filePath)
{
if (filePath == m_data.filePath) {
Expand Down
1 change: 1 addition & 0 deletions src/core/Database.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class Database : public QObject

QUuid uuid() const;
QString filePath() const;
QString canonicalFilePath() const;
void setFilePath(const QString& filePath);

Metadata* metadata();
Expand Down
4 changes: 1 addition & 3 deletions src/format/KdbxXmlReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1028,10 +1028,8 @@ bool KdbxXmlReader::readBool()

QDateTime KdbxXmlReader::readDateTime()
{
static QRegularExpression b64regex("^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$");
QString str = readString();

if (b64regex.match(str).hasMatch()) {
if (Tools::isBase64(str.toLatin1())) {
QByteArray secsBytes = QByteArray::fromBase64(str.toUtf8()).leftJustified(8, '\0', true).left(8);
qint64 secs = Endian::bytesToSizedInt<quint64>(secsBytes, KeePass2::BYTEORDER);
return QDateTime(QDate(1, 1, 1), QTime(0, 0, 0, 0), Qt::UTC).addSecs(secs);
Expand Down
23 changes: 11 additions & 12 deletions src/gui/DatabaseOpenWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ DatabaseOpenWidget::DatabaseOpenWidget(QWidget* parent)
m_ui->setupUi(this);

m_ui->messageWidget->setHidden(true);
m_ui->checkPassword->setChecked(true);

QFont font = m_ui->labelHeadline->font();
font.setBold(true);
Expand Down Expand Up @@ -159,7 +158,7 @@ void DatabaseOpenWidget::clearForms()
m_ui->editPassword->setText("");
m_ui->comboKeyFile->clear();
m_ui->comboKeyFile->setEditText("");
m_ui->checkPassword->setChecked(true);
m_ui->checkPassword->setChecked(false);
m_ui->checkKeyFile->setChecked(false);
m_ui->checkChallengeResponse->setChecked(false);
m_ui->checkTouchID->setChecked(false);
Expand All @@ -174,13 +173,8 @@ QSharedPointer<Database> DatabaseOpenWidget::database()

void DatabaseOpenWidget::enterKey(const QString& pw, const QString& keyFile)
{
if (!pw.isEmpty()) {
m_ui->editPassword->setText(pw);
}
if (!keyFile.isEmpty()) {
m_ui->comboKeyFile->setEditText(keyFile);
}

m_ui->editPassword->setText(pw);
m_ui->comboKeyFile->setEditText(keyFile);
phoerious marked this conversation as resolved.
Show resolved Hide resolved
openDatabase();
}

Expand Down Expand Up @@ -339,17 +333,20 @@ void DatabaseOpenWidget::reject()

void DatabaseOpenWidget::activatePassword()
{
m_ui->checkPassword->setChecked(true);
bool hasPassword = !m_ui->editPassword->text().isEmpty();
m_ui->checkPassword->setChecked(hasPassword);
}

void DatabaseOpenWidget::activateKeyFile()
{
m_ui->checkKeyFile->setChecked(true);
bool hasKeyFile = !m_ui->comboKeyFile->lineEdit()->text().isEmpty();
m_ui->checkKeyFile->setChecked(hasKeyFile);
}

void DatabaseOpenWidget::activateChallengeResponse()
{
m_ui->checkChallengeResponse->setChecked(true);
bool hasCR = m_ui->comboChallengeResponse->currentData().toInt() != -1;
m_ui->checkChallengeResponse->setChecked(hasCR);
}

void DatabaseOpenWidget::browseKeyFile()
Expand All @@ -372,6 +369,7 @@ void DatabaseOpenWidget::pollYubikey()
m_ui->checkChallengeResponse->setChecked(false);
m_ui->comboChallengeResponse->setEnabled(false);
m_ui->comboChallengeResponse->clear();
m_ui->comboChallengeResponse->addItem(tr("-- SELECT --"), -1);
phoerious marked this conversation as resolved.
Show resolved Hide resolved
m_ui->yubikeyProgress->setVisible(true);

// YubiKey init is slow, detect asynchronously to not block the UI
Expand All @@ -388,6 +386,7 @@ void DatabaseOpenWidget::yubikeyDetected(int slot, bool blocking)
QHash<QString, QVariant> lastChallengeResponse = config()->get("LastChallengeResponse").toHash();
if (lastChallengeResponse.contains(m_filename)) {
m_ui->checkChallengeResponse->setChecked(true);
m_ui->comboChallengeResponse->setCurrentIndex(1);
}
}
}
Expand Down
10 changes: 3 additions & 7 deletions src/gui/DatabaseTabWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,8 @@ void DatabaseTabWidget::addDatabaseTab(const QString& filePath,
for (int i = 0, c = count(); i < c; ++i) {
auto* dbWidget = databaseWidgetFromIndex(i);
Q_ASSERT(dbWidget);
if (dbWidget && dbWidget->database()->filePath() == canonicalFilePath) {
if (!password.isEmpty()) {
dbWidget->performUnlockDatabase(password, keyfile);
}
if (dbWidget && dbWidget->database()->canonicalFilePath() == canonicalFilePath) {
dbWidget->performUnlockDatabase(password, keyfile);
if (!inBackground) {
// switch to existing tab if file is already open
setCurrentIndex(indexOf(dbWidget));
Expand All @@ -171,9 +169,7 @@ void DatabaseTabWidget::addDatabaseTab(const QString& filePath,

auto* dbWidget = new DatabaseWidget(QSharedPointer<Database>::create(filePath), this);
addDatabaseTab(dbWidget, inBackground);
if (!password.isEmpty()) {
dbWidget->performUnlockDatabase(password, keyfile);
}
dbWidget->performUnlockDatabase(password, keyfile);
updateLastDatabases(filePath);
}

Expand Down
7 changes: 3 additions & 4 deletions src/gui/dbsettings/DatabaseSettingsWidgetMasterKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,8 @@ void DatabaseSettingsWidgetMasterKey::load(QSharedPointer<Database> db)
// database has no key, we are about to add a new one
m_passwordEditWidget->changeVisiblePage(KeyComponentWidget::Page::Edit);
m_passwordEditWidget->setPasswordVisible(true);
m_isDirty = true;
return;
}

bool isDirty = false;
bool hasAdditionalKeys = false;
for (const auto& key : m_db->key()->keys()) {
if (key->uuid() == PasswordKey::UUID) {
Expand All @@ -103,7 +100,9 @@ void DatabaseSettingsWidgetMasterKey::load(QSharedPointer<Database> db)

setAdditionalKeyOptionsVisible(hasAdditionalKeys);

m_isDirty = isDirty;
connect(m_passwordEditWidget->findChild<QPushButton*>("removeButton"), SIGNAL(clicked()), SLOT(markDirty()));
connect(m_keyFileEditWidget->findChild<QPushButton*>("removeButton"), SIGNAL(clicked()), SLOT(markDirty()));
connect(m_yubiKeyEditWidget->findChild<QPushButton*>("removeButton"), SIGNAL(clicked()), SLOT(markDirty()));
phoerious marked this conversation as resolved.
Show resolved Hide resolved
}

void DatabaseSettingsWidgetMasterKey::initialize()
Expand Down
7 changes: 7 additions & 0 deletions src/gui/entry/EditEntryWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,13 @@ void EditEntryWidget::clear()
{
m_entry = nullptr;
m_db.reset();

m_mainUi->titleEdit->setText("");
m_mainUi->passwordEdit->setText("");
m_mainUi->passwordRepeatEdit->setText("");
m_mainUi->urlEdit->setText("");
m_mainUi->notesEdit->clear();

m_entryAttributes->clear();
m_advancedUi->attachmentsWidget->clearAttachments();
m_autoTypeAssoc->clear();
Expand Down
9 changes: 9 additions & 0 deletions src/gui/masterkey/PasswordEditWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ void PasswordEditWidget::initComponentEditWidget(QWidget* widget)
m_compUi->enterPasswordEdit->setFocus();
}

void PasswordEditWidget::hideEvent(QHideEvent* event)
{
if (!isVisible() && m_compUi->enterPasswordEdit) {
m_compUi->enterPasswordEdit->setText("");
phoerious marked this conversation as resolved.
Show resolved Hide resolved
}

QWidget::hideEvent(event);
}

bool PasswordEditWidget::validate(QString& errorMessage) const
{
if (m_compUi->enterPasswordEdit->text() != m_compUi->repeatPasswordEdit->text()) {
Expand Down
1 change: 1 addition & 0 deletions src/gui/masterkey/PasswordEditWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class PasswordEditWidget : public KeyComponentWidget
protected:
QWidget* componentEditWidget() override;
void initComponentEditWidget(QWidget* widget) override;
void hideEvent(QHideEvent* event) override;

private slots:
void showPasswordGenerator();
Expand Down