Skip to content

Commit

Permalink
Add support for configuration overrides via GPOs in Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
egglessness committed Sep 2, 2024
1 parent 3c05dd2 commit 4c809e7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
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

0 comments on commit 4c809e7

Please sign in to comment.