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 support for configuration overrides via GPOs in Windows #11223

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ QVariant Config::get(ConfigKey key)
{
auto cfg = configStrings[key];
auto defaultValue = configStrings[key].defaultValue;
#if defined(Q_OS_WIN)
if (isManaged(key)) {
return m_managedSettings->value(cfg.name, defaultValue);
}
#endif
if (m_localSettings && cfg.type == Local) {
return m_localSettings->value(cfg.name, defaultValue);
}
Expand All @@ -241,6 +246,16 @@ QVariant Config::getDefault(Config::ConfigKey key)
return configStrings[key].defaultValue;
}

bool Config::isManaged(ConfigKey key)
{
auto cfg = configStrings[key];
#if defined(Q_OS_WIN)
return m_managedSettings && m_managedSettings->contains(cfg.name);
#else
return false;
#endif
}

bool Config::hasAccessError()
{
return m_settings->status() & QSettings::AccessError;
Expand Down Expand Up @@ -503,6 +518,11 @@ void Config::init(const QString& configFileName, const QString& localConfigFileN
m_localSettings.reset(new QSettings(localConfigFileName, QSettings::IniFormat));
}

#if defined(Q_OS_WIN)
m_managedSettings.reset(
new QSettings("HKEY_LOCAL_MACHINE\\SOFTWARE\\Policies\\KeePassXC", QSettings::NativeFormat));
#endif

migrate();
connect(qApp, &QCoreApplication::aboutToQuit, this, &Config::sync);
}
Expand Down
4 changes: 4 additions & 0 deletions src/core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ class Config : public QObject
~Config() override;
QVariant get(ConfigKey key);
QVariant getDefault(ConfigKey key);
bool isManaged(ConfigKey key);
QString getFileName();
void set(ConfigKey key, const QVariant& value);
void remove(ConfigKey key);
Expand Down Expand Up @@ -240,6 +241,9 @@ class Config : public QObject

QScopedPointer<QSettings> m_settings;
QScopedPointer<QSettings> m_localSettings;
#if defined(Q_OS_WIN)
QScopedPointer<QSettings> m_managedSettings;
#endif
QHash<QString, QVariant> m_defaults;
};

Expand Down
Loading