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

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

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/core/Config.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2023 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2011 Felix Geyer <debfx@fobos.de>
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -133,6 +133,7 @@ static const QHash<Config::ConfigKey, ConfigDirective> configStrings = {
{Config::Security_LockDatabaseIdleSeconds, {QS("Security/LockDatabaseIdleSeconds"), Roaming, 240}},
{Config::Security_LockDatabaseMinimize, {QS("Security/LockDatabaseMinimize"), Roaming, false}},
{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_PasswordsRepeatVisible, {QS("Security/PasswordsRepeatVisible"), Roaming, true}},
{Config::Security_PasswordsHidden, {QS("Security/PasswordsHidden"), Roaming, true}},
Expand Down
3 changes: 2 additions & 1 deletion src/core/Config.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2023 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2011 Felix Geyer <debfx@fobos.de>
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -113,6 +113,7 @@ class Config : public QObject
Security_LockDatabaseIdleSeconds,
Security_LockDatabaseMinimize,
Security_LockDatabaseScreenLock,
Security_LockDatabaseOnUserSwitch,
Security_RelockAutoType,
Security_PasswordsRepeatVisible,
Security_PasswordsHidden,
Expand Down
10 changes: 9 additions & 1 deletion src/gui/ApplicationSettingsWidget.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2023 KeePassXC Team <team@keepassxc.org>
* 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
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -308,6 +308,13 @@ void ApplicationSettingsWidget::loadSettings()
&& config()->get(Config::Security_LockDatabaseMinimize).toBool());
m_secUi->lockDatabaseOnScreenLockCheckBox->setChecked(
config()->get(Config::Security_LockDatabaseScreenLock).toBool());
#if defined(Q_OS_MACOS)
m_secUi->lockDatabasesOnUserSwitchCheckBox->setEnabled(true);
#else
m_secUi->lockDatabasesOnUserSwitchCheckBox->setEnabled(false);
#endif
varjolintu marked this conversation as resolved.
Show resolved Hide resolved
m_secUi->lockDatabasesOnUserSwitchCheckBox->setChecked(
config()->get(Config::Security_LockDatabaseOnUserSwitch).toBool());
m_secUi->fallbackToSearch->setChecked(config()->get(Config::Security_IconDownloadFallback).toBool());

m_secUi->passwordsHiddenCheckBox->setChecked(config()->get(Config::Security_PasswordsHidden).toBool());
Expand Down Expand Up @@ -422,6 +429,7 @@ void ApplicationSettingsWidget::saveSettings()
config()->set(Config::Security_LockDatabaseIdleSeconds, m_secUi->lockDatabaseIdleSpinBox->value());
config()->set(Config::Security_LockDatabaseMinimize, m_secUi->lockDatabaseMinimizeCheckBox->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_PasswordsHidden, m_secUi->passwordsHiddenCheckBox->isChecked());
Expand Down
8 changes: 8 additions & 0 deletions src/gui/ApplicationSettingsWidgetSecurity.ui
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="lockDatabasesOnUserSwitchCheckBox">
<property name="text">
<string>Lock databases when switching user</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="passwordsRepeatVisibleCheckBox">
<property name="text">
Expand Down Expand Up @@ -281,6 +288,7 @@
<tabstop>clearClipboardSpinBox</tabstop>
<tabstop>lockDatabaseIdleCheckBox</tabstop>
<tabstop>lockDatabaseIdleSpinBox</tabstop>
<tabstop>lockDatabasesOnUserSwitchCheckBox</tabstop>
<tabstop>clearSearchCheckBox</tabstop>
<tabstop>clearSearchSpinBox</tabstop>
<tabstop>lockDatabaseOnScreenLockCheckBox</tabstop>
Expand Down
9 changes: 8 additions & 1 deletion src/gui/DatabaseTabWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ DatabaseTabWidget::DatabaseTabWidget(QWidget* parent)
// clang-format on

#ifdef Q_OS_MACOS
connect(macUtils(), SIGNAL(lockDatabases()), SLOT(lockDatabases()));
connect(macUtils(), SIGNAL(lockDatabasesOnUserSwitch()), SLOT(lockDatabasesOnUserSwitch()));
#endif

m_lockDelayTimer.setSingleShot(true);
Expand Down Expand Up @@ -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.
*
Expand Down
3 changes: 2 additions & 1 deletion src/gui/DatabaseTabWidget.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2023 KeePassXC Team <team@keepassxc.org>
*
* 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
Expand Down Expand Up @@ -75,6 +75,7 @@ public slots:

bool lockDatabases();
void lockDatabasesDelayed();
void lockDatabasesOnUserSwitch();
void closeDatabaseFromSender();
void unlockDatabaseInDialog(DatabaseWidget* dbWidget, DatabaseOpenDialog::Intent intent);
void unlockDatabaseInDialog(DatabaseWidget* dbWidget, DatabaseOpenDialog::Intent intent, const QString& filePath);
Expand Down
6 changes: 3 additions & 3 deletions src/gui/osutils/macutils/AppKit.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2023 KeePassXC Team <team@keepassxc.org>
* 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
* it under the terms of the GNU General Public License as published by
Expand All @@ -19,8 +19,8 @@
#ifndef KEEPASSX_APPKIT_H
#define KEEPASSX_APPKIT_H

#include <QObject>
#include <QColor>
#include <QObject>
#include <unistd.h>

class QWindow;
Expand All @@ -47,7 +47,7 @@ class AppKit : public QObject
void setWindowSecurity(QWindow* window, bool state);

signals:
void lockDatabases();
void lockDatabasesOnUserSwitch();
varjolintu marked this conversation as resolved.
Show resolved Hide resolved
void interfaceThemeChanged();

private:
Expand Down
8 changes: 4 additions & 4 deletions src/gui/osutils/macutils/AppKitImpl.mm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2023 KeePassXC Team <team@keepassxc.org>
* 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
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -32,7 +32,7 @@ - (id) initWithObject:(AppKit*)appkit
selector:@selector(didDeactivateApplicationObserver:)
name:NSWorkspaceDidDeactivateApplicationNotification
object:nil];

[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self
selector:@selector(userSwitchHandler:)
name:NSWorkspaceSessionDidResignActiveNotification
Expand Down Expand Up @@ -168,7 +168,7 @@ - (void) userSwitchHandler:(NSNotification*) notification
{
if ([[notification name] isEqualToString:NSWorkspaceSessionDidResignActiveNotification] && m_appkit)
{
emit m_appkit->lockDatabases();
emit m_appkit->lockDatabasesOnUserSwitch();
}
}

Expand Down Expand Up @@ -196,7 +196,7 @@ - (bool) enableScreenRecording
// Request screen recording permission on macOS 10.15+
// This is necessary to get the current window title
CGDisplayStreamRef stream = CGDisplayStreamCreate(CGMainDisplayID(), 1, 1, kCVPixelFormatType_32BGRA, nil,
^(CGDisplayStreamFrameStatus status, uint64_t displayTime,
^(CGDisplayStreamFrameStatus status, uint64_t displayTime,
IOSurfaceRef frameSurface, CGDisplayStreamUpdateRef updateRef) {
Q_UNUSED(status);
Q_UNUSED(displayTime);
Expand Down
4 changes: 2 additions & 2 deletions src/gui/osutils/macutils/MacUtils.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2023 KeePassXC Team <team@keepassxc.org>
* 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
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -39,7 +39,7 @@ MacUtils::MacUtils(QObject* parent)
: OSUtilsBase(parent)
, m_appkit(new AppKit())
{
connect(m_appkit.data(), SIGNAL(lockDatabases()), SIGNAL(lockDatabases()));
connect(m_appkit.data(), SIGNAL(lockDatabasesOnUserSwitch()), SIGNAL(lockDatabasesOnUserSwitch()));
connect(m_appkit.data(), SIGNAL(interfaceThemeChanged()), SIGNAL(interfaceThemeChanged()));
connect(m_appkit.data(), &AppKit::interfaceThemeChanged, this, [this]() {
// Emit with delay, since isStatusBarDark() still returns the old value
Expand Down
4 changes: 2 additions & 2 deletions src/gui/osutils/macutils/MacUtils.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2023 KeePassXC Team <team@keepassxc.org>
* 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
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -66,7 +66,7 @@ class MacUtils : public OSUtilsBase
bool setPreventScreenCapture(QWindow* window, bool prevent) const override;

signals:
void lockDatabases();
void lockDatabasesOnUserSwitch();

protected:
explicit MacUtils(QObject* parent = nullptr);
Expand Down