mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 22:48:11 +00:00
LibConfig+ConfigServer: Add permissive mode
When in permissive mode, the ConfigServer will not treat reads and writes to non-pledged domains as errors, but instead turns them into no-ops: Reads will act as if the key was not found, and writes will do nothing. Permissive mode must be enabled before pledging any domains. This is needed to make GUI Widgets nicer to work with in GML Playground: a few Widgets include reads and writes to LibConfig in order to load system settings (eg, GUI::Calendar) or to save and restore state (eg, GUI::DynamicWidgetContainer). Without this change, editing a layout that includes one of these Widgets will cause GML Playground to crash when they try to access config domains that are not pledged. The solution used previously is to make Playground pledge more domains, but not only does this mean Playground has to know about these cases, but also that working on a layout file can alter the user's settings in other arbitrary apps, which is not something we want. By simply ignoring these config accesses, we avoid those downsides, and Widgets will simply use the fallback values they already have to provide to Config::read_foo_value().
This commit is contained in:
parent
2c327a67bc
commit
5bcb3e2f16
5 changed files with 44 additions and 6 deletions
|
@ -99,10 +99,20 @@ void ConnectionFromClient::pledge_domains(Vector<ByteString> const& domains)
|
|||
m_pledged_domains.set(domain);
|
||||
}
|
||||
|
||||
void ConnectionFromClient::enable_permissive_mode()
|
||||
{
|
||||
if (m_has_pledged) {
|
||||
did_misbehave("Tried to enable permissive mode after pledging.");
|
||||
return;
|
||||
}
|
||||
m_permissive_mode = true;
|
||||
}
|
||||
|
||||
void ConnectionFromClient::monitor_domain(ByteString const& domain)
|
||||
{
|
||||
if (m_has_pledged && !m_pledged_domains.contains(domain)) {
|
||||
did_misbehave("Attempt to monitor non-pledged domain");
|
||||
if (!m_permissive_mode)
|
||||
did_misbehave("Attempt to monitor non-pledged domain");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -115,7 +125,8 @@ bool ConnectionFromClient::validate_access(ByteString const& domain, ByteString
|
|||
return true;
|
||||
if (m_pledged_domains.contains(domain))
|
||||
return true;
|
||||
did_misbehave(ByteString::formatted("Blocked attempt to access domain '{}', group={}, key={}", domain, group, key).characters());
|
||||
if (!m_permissive_mode)
|
||||
did_misbehave(ByteString::formatted("Blocked attempt to access domain '{}', group={}, key={}", domain, group, key).characters());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -153,8 +164,11 @@ Messages::ConfigServer::ListConfigGroupsResponse ConnectionFromClient::list_conf
|
|||
|
||||
Messages::ConfigServer::ReadStringValueResponse ConnectionFromClient::read_string_value(ByteString const& domain, ByteString const& group, ByteString const& key)
|
||||
{
|
||||
if (!validate_access(domain, group, key))
|
||||
if (!validate_access(domain, group, key)) {
|
||||
if (m_permissive_mode)
|
||||
return Optional<ByteString> {};
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto& config = ensure_domain_config(domain);
|
||||
if (!config.has_key(group, key))
|
||||
|
@ -164,8 +178,11 @@ Messages::ConfigServer::ReadStringValueResponse ConnectionFromClient::read_strin
|
|||
|
||||
Messages::ConfigServer::ReadI32ValueResponse ConnectionFromClient::read_i32_value(ByteString const& domain, ByteString const& group, ByteString const& key)
|
||||
{
|
||||
if (!validate_access(domain, group, key))
|
||||
if (!validate_access(domain, group, key)) {
|
||||
if (m_permissive_mode)
|
||||
return Optional<i32> {};
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto& config = ensure_domain_config(domain);
|
||||
if (!config.has_key(group, key))
|
||||
|
@ -175,8 +192,11 @@ Messages::ConfigServer::ReadI32ValueResponse ConnectionFromClient::read_i32_valu
|
|||
|
||||
Messages::ConfigServer::ReadU32ValueResponse ConnectionFromClient::read_u32_value(ByteString const& domain, ByteString const& group, ByteString const& key)
|
||||
{
|
||||
if (!validate_access(domain, group, key))
|
||||
if (!validate_access(domain, group, key)) {
|
||||
if (m_permissive_mode)
|
||||
return Optional<u32> {};
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto& config = ensure_domain_config(domain);
|
||||
if (!config.has_key(group, key))
|
||||
|
@ -186,8 +206,11 @@ Messages::ConfigServer::ReadU32ValueResponse ConnectionFromClient::read_u32_valu
|
|||
|
||||
Messages::ConfigServer::ReadBoolValueResponse ConnectionFromClient::read_bool_value(ByteString const& domain, ByteString const& group, ByteString const& key)
|
||||
{
|
||||
if (!validate_access(domain, group, key))
|
||||
if (!validate_access(domain, group, key)) {
|
||||
if (m_permissive_mode)
|
||||
return Optional<bool> {};
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto& config = ensure_domain_config(domain);
|
||||
if (!config.has_key(group, key))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue