diff --git a/src/core/Config.cpp b/src/core/Config.cpp index 871c264195..a5ab700e0f 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -230,6 +230,9 @@ QVariant Config::get(ConfigKey key) { auto cfg = configStrings[key]; auto defaultValue = configStrings[key].defaultValue; + if (this->isManaged(key)) { + return m_managedSettings->value(cfg.name, defaultValue); + } if (m_localSettings && cfg.type == Local) { return m_localSettings->value(cfg.name, defaultValue); } @@ -241,6 +244,16 @@ QVariant Config::getDefault(Config::ConfigKey key) return configStrings[key].defaultValue; } +bool Config::isManaged(ConfigKey key) +{ +#if defined(Q_OS_WIN) + auto cfg = configStrings[key]; + return m_managedSettings && m_managedSettings->contains(cfg.name); +#else + return false; +#endif +} + bool Config::hasAccessError() { return m_settings->status() & QSettings::AccessError; @@ -503,6 +516,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); } diff --git a/src/core/Config.h b/src/core/Config.h index af24427a0e..e88133575e 100644 --- a/src/core/Config.h +++ b/src/core/Config.h @@ -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); @@ -240,6 +241,9 @@ class Config : public QObject QScopedPointer m_settings; QScopedPointer m_localSettings; +#if defined(Q_OS_WIN) + QScopedPointer m_managedSettings; +#endif QHash m_defaults; };