Add option to disable database lock when switching user on macOS (#9707)

This commit is contained in:
Sami Vänttinen 2024-08-12 01:32:10 +03:00 committed by GitHub
parent 42ce2a49fa
commit b3bec8b2b4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 42 additions and 12 deletions

View File

@ -596,6 +596,10 @@
<source>Hide TOTP in the entry preview panel</source> <source>Hide TOTP in the entry preview panel</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Lock databases when switching user</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>AutoType</name> <name>AutoType</name>

View File

@ -135,6 +135,7 @@ static const QHash<Config::ConfigKey, ConfigDirective> configStrings = {
{Config::Security_LockDatabaseIdleSeconds, {QS("Security/LockDatabaseIdleSeconds"), Roaming, 240}}, {Config::Security_LockDatabaseIdleSeconds, {QS("Security/LockDatabaseIdleSeconds"), Roaming, 240}},
{Config::Security_LockDatabaseMinimize, {QS("Security/LockDatabaseMinimize"), Roaming, false}}, {Config::Security_LockDatabaseMinimize, {QS("Security/LockDatabaseMinimize"), Roaming, false}},
{Config::Security_LockDatabaseScreenLock, {QS("Security/LockDatabaseScreenLock"), Roaming, true}}, {Config::Security_LockDatabaseScreenLock, {QS("Security/LockDatabaseScreenLock"), Roaming, true}},
{Config::Security_LockDatabaseOnUserSwitch, {QS("Security/LockDatabaseOnUserSwitch"), Roaming, true}},
{Config::Security_RelockAutoType, {QS("Security/RelockAutoType"), Roaming, false}}, {Config::Security_RelockAutoType, {QS("Security/RelockAutoType"), Roaming, false}},
{Config::Security_PasswordsHidden, {QS("Security/PasswordsHidden"), Roaming, true}}, {Config::Security_PasswordsHidden, {QS("Security/PasswordsHidden"), Roaming, true}},
{Config::Security_PasswordEmptyPlaceholder, {QS("Security/PasswordEmptyPlaceholder"), Roaming, false}}, {Config::Security_PasswordEmptyPlaceholder, {QS("Security/PasswordEmptyPlaceholder"), Roaming, false}},

View File

@ -116,6 +116,7 @@ public:
Security_LockDatabaseIdleSeconds, Security_LockDatabaseIdleSeconds,
Security_LockDatabaseMinimize, Security_LockDatabaseMinimize,
Security_LockDatabaseScreenLock, Security_LockDatabaseScreenLock,
Security_LockDatabaseOnUserSwitch,
Security_RelockAutoType, Security_RelockAutoType,
Security_PasswordsHidden, Security_PasswordsHidden,
Security_PasswordEmptyPlaceholder, Security_PasswordEmptyPlaceholder,

View File

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2023 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2012 Felix Geyer <debfx@fobos.de> * Copyright (C) 2012 Felix Geyer <debfx@fobos.de>
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -317,6 +317,13 @@ void ApplicationSettingsWidget::loadSettings()
&& config()->get(Config::Security_LockDatabaseMinimize).toBool()); && config()->get(Config::Security_LockDatabaseMinimize).toBool());
m_secUi->lockDatabaseOnScreenLockCheckBox->setChecked( m_secUi->lockDatabaseOnScreenLockCheckBox->setChecked(
config()->get(Config::Security_LockDatabaseScreenLock).toBool()); config()->get(Config::Security_LockDatabaseScreenLock).toBool());
#if defined(Q_OS_MACOS)
m_secUi->lockDatabasesOnUserSwitchCheckBox->setVisible(true);
#else
m_secUi->lockDatabasesOnUserSwitchCheckBox->setVisible(false);
#endif
m_secUi->lockDatabasesOnUserSwitchCheckBox->setChecked(
config()->get(Config::Security_LockDatabaseOnUserSwitch).toBool());
m_secUi->fallbackToSearch->setChecked(config()->get(Config::Security_IconDownloadFallback).toBool()); m_secUi->fallbackToSearch->setChecked(config()->get(Config::Security_IconDownloadFallback).toBool());
m_secUi->passwordsHiddenCheckBox->setChecked(config()->get(Config::Security_PasswordsHidden).toBool()); m_secUi->passwordsHiddenCheckBox->setChecked(config()->get(Config::Security_PasswordsHidden).toBool());
@ -430,6 +437,7 @@ void ApplicationSettingsWidget::saveSettings()
config()->set(Config::Security_LockDatabaseIdleSeconds, m_secUi->lockDatabaseIdleSpinBox->value()); config()->set(Config::Security_LockDatabaseIdleSeconds, m_secUi->lockDatabaseIdleSpinBox->value());
config()->set(Config::Security_LockDatabaseMinimize, m_secUi->lockDatabaseMinimizeCheckBox->isChecked()); config()->set(Config::Security_LockDatabaseMinimize, m_secUi->lockDatabaseMinimizeCheckBox->isChecked());
config()->set(Config::Security_LockDatabaseScreenLock, m_secUi->lockDatabaseOnScreenLockCheckBox->isChecked()); config()->set(Config::Security_LockDatabaseScreenLock, m_secUi->lockDatabaseOnScreenLockCheckBox->isChecked());
config()->set(Config::Security_LockDatabaseOnUserSwitch, m_secUi->lockDatabasesOnUserSwitchCheckBox->isChecked());
config()->set(Config::Security_IconDownloadFallback, m_secUi->fallbackToSearch->isChecked()); config()->set(Config::Security_IconDownloadFallback, m_secUi->fallbackToSearch->isChecked());
config()->set(Config::Security_PasswordsHidden, m_secUi->passwordsHiddenCheckBox->isChecked()); config()->set(Config::Security_PasswordsHidden, m_secUi->passwordsHiddenCheckBox->isChecked());

View File

@ -186,6 +186,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="lockDatabasesOnUserSwitchCheckBox">
<property name="text">
<string>Lock databases when switching user</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QCheckBox" name="passwordsHiddenCheckBox"> <widget class="QCheckBox" name="passwordsHiddenCheckBox">
<property name="text"> <property name="text">
@ -277,6 +284,7 @@
<tabstop>clearClipboardSpinBox</tabstop> <tabstop>clearClipboardSpinBox</tabstop>
<tabstop>lockDatabaseIdleCheckBox</tabstop> <tabstop>lockDatabaseIdleCheckBox</tabstop>
<tabstop>lockDatabaseIdleSpinBox</tabstop> <tabstop>lockDatabaseIdleSpinBox</tabstop>
<tabstop>lockDatabasesOnUserSwitchCheckBox</tabstop>
<tabstop>clearSearchCheckBox</tabstop> <tabstop>clearSearchCheckBox</tabstop>
<tabstop>clearSearchSpinBox</tabstop> <tabstop>clearSearchSpinBox</tabstop>
<tabstop>quickUnlockCheckBox</tabstop> <tabstop>quickUnlockCheckBox</tabstop>

View File

@ -63,7 +63,7 @@ DatabaseTabWidget::DatabaseTabWidget(QWidget* parent)
// clang-format on // clang-format on
#ifdef Q_OS_MACOS #ifdef Q_OS_MACOS
connect(macUtils(), SIGNAL(lockDatabases()), SLOT(lockDatabases())); connect(macUtils(), SIGNAL(userSwitched()), SLOT(lockDatabasesOnUserSwitch()));
#endif #endif
m_lockDelayTimer.setSingleShot(true); m_lockDelayTimer.setSingleShot(true);
@ -700,6 +700,13 @@ void DatabaseTabWidget::lockDatabasesDelayed()
} }
} }
void DatabaseTabWidget::lockDatabasesOnUserSwitch()
{
if (config()->get(Config::Security_LockDatabaseOnUserSwitch).toBool()) {
lockDatabases();
}
}
/** /**
* Unlock a database with an unlock popup dialog. * Unlock a database with an unlock popup dialog.
* *

View File

@ -74,6 +74,7 @@ public slots:
bool lockDatabases(); bool lockDatabases();
void lockDatabasesDelayed(); void lockDatabasesDelayed();
void lockDatabasesOnUserSwitch();
void closeDatabaseFromSender(); void closeDatabaseFromSender();
void unlockDatabaseInDialog(DatabaseWidget* dbWidget, DatabaseOpenDialog::Intent intent); void unlockDatabaseInDialog(DatabaseWidget* dbWidget, DatabaseOpenDialog::Intent intent);
void unlockDatabaseInDialog(DatabaseWidget* dbWidget, DatabaseOpenDialog::Intent intent, const QString& filePath); void unlockDatabaseInDialog(DatabaseWidget* dbWidget, DatabaseOpenDialog::Intent intent, const QString& filePath);

View File

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2023 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2016 Lennart Glauer <mail@lennart-glauer.de> * Copyright (C) 2016 Lennart Glauer <mail@lennart-glauer.de>
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -19,8 +19,8 @@
#ifndef KEEPASSX_APPKIT_H #ifndef KEEPASSX_APPKIT_H
#define KEEPASSX_APPKIT_H #define KEEPASSX_APPKIT_H
#include <QObject>
#include <QColor> #include <QColor>
#include <QObject>
#include <unistd.h> #include <unistd.h>
class QWindow; class QWindow;
@ -47,7 +47,7 @@ public:
void setWindowSecurity(QWindow* window, bool state); void setWindowSecurity(QWindow* window, bool state);
signals: signals:
void lockDatabases(); void userSwitched();
void interfaceThemeChanged(); void interfaceThemeChanged();
private: private:

View File

@ -160,7 +160,7 @@
{ {
if ([[notification name] isEqualToString:NSWorkspaceSessionDidResignActiveNotification] && m_appkit) if ([[notification name] isEqualToString:NSWorkspaceSessionDidResignActiveNotification] && m_appkit)
{ {
emit m_appkit->lockDatabases(); emit m_appkit->userSwitched();
} }
} }

View File

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2023 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2012 Felix Geyer <debfx@fobos.de> * Copyright (C) 2012 Felix Geyer <debfx@fobos.de>
* Copyright (C) 2018 KeePassXC Team <team@keepassxc.org>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -39,7 +39,7 @@ MacUtils::MacUtils(QObject* parent)
: OSUtilsBase(parent) : OSUtilsBase(parent)
, m_appkit(new AppKit()) , m_appkit(new AppKit())
{ {
connect(m_appkit.data(), SIGNAL(lockDatabases()), SIGNAL(lockDatabases())); connect(m_appkit.data(), SIGNAL(userSwitched()), SIGNAL(userSwitched()));
connect(m_appkit.data(), SIGNAL(interfaceThemeChanged()), SIGNAL(interfaceThemeChanged())); connect(m_appkit.data(), SIGNAL(interfaceThemeChanged()), SIGNAL(interfaceThemeChanged()));
connect(m_appkit.data(), &AppKit::interfaceThemeChanged, this, [this]() { connect(m_appkit.data(), &AppKit::interfaceThemeChanged, this, [this]() {
// Emit with delay, since isStatusBarDark() still returns the old value // Emit with delay, since isStatusBarDark() still returns the old value

View File

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2023 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2012 Felix Geyer <debfx@fobos.de> * Copyright (C) 2012 Felix Geyer <debfx@fobos.de>
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -66,7 +66,7 @@ public:
bool setPreventScreenCapture(QWindow* window, bool prevent) const override; bool setPreventScreenCapture(QWindow* window, bool prevent) const override;
signals: signals:
void lockDatabases(); void userSwitched();
protected: protected:
explicit MacUtils(QObject* parent = nullptr); explicit MacUtils(QObject* parent = nullptr);