diff --git a/script_screens_doc.md b/script_screens_doc.md index 7ebf14caf..0be028952 100644 --- a/script_screens_doc.md +++ b/script_screens_doc.md @@ -264,7 +264,8 @@ again: |---------------------|---------|------------------------------------------------------------------------------------------| | `lua.fulllibraries` | no | yes: the scenery scripts get all of LuaJIT's libraries (`io`, `os`, `ffi`, `require`...), and with them the files and programs of the computer. The Lua screens stay sandboxed | -Only `eu07.ini` sets it: a `config` block of a scenery doesn't (the log says the key was ignored). Nor does it set +Only `eu07.ini` turns it on: a `config` block of a scenery doesn't (the log says the key was ignored). Nor does it set the other keys that would take a scenery out of its sandbox or reach the computer: `execonexit`, `extcam.cmd`, `extcam.rec`, `screenshotsdir`, `network.server`, `network.client`, `zmq.address`, `motiontelemetry`, `uart`, -`feedbackmode`, `feedbackport`, `python.enabled`, `luascreens.enabled` and `wasm.enabled`. +`feedbackmode`, `feedbackport`, nor does it switch on `python.enabled`, `luascreens.enabled` or `wasm.enabled` when +`eu07.ini` has them off. A scenery may still switch those three off, or `lua.fulllibraries` off, as it always could. diff --git a/tests/unit/test_ini_only_settings.cpp b/tests/unit/test_ini_only_settings.cpp index 8ae73fe43..f90e9b2f9 100644 --- a/tests/unit/test_ini_only_settings.cpp +++ b/tests/unit/test_ini_only_settings.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include namespace { @@ -32,17 +33,43 @@ TEST_CASE("ini only settings: a scenery's config block doesn't give its scripts CHECK(changed == std::vector{"lua.fulllibraries"}); } -TEST_CASE("ini only settings: what eu07.ini turned on stays on") { - auto const settings{std::make_unique()}; - settings->lua_fulllibraries = true; - settings->python_enabled = false; - ini_only_settings const ini{*settings}; - settings->lua_fulllibraries = false; - settings->python_enabled = true; - auto const changed{ini.restore(*settings)}; - CHECK(settings->lua_fulllibraries); - CHECK_FALSE(settings->python_enabled); - CHECK(changed.size() == 2); +TEST_CASE("ini only settings: a scenery switches a runtime off, but not on") { + auto const python{[](global_settings &Settings) -> bool & { return Settings.python_enabled; }}; + auto const luascreens{[](global_settings &Settings) -> bool & { return Settings.luascreens_enabled; }}; + auto const wasm{[](global_settings &Settings) -> bool & { return Settings.wasm_enabled; }}; + auto const fulllibraries{[](global_settings &Settings) -> bool & { return Settings.lua_fulllibraries; }}; + using setting = bool &(*)(global_settings &); + for (auto const &[key, switched] : {std::pair{"python.enabled", python}, {"luascreens.enabled", luascreens}, + {"wasm.enabled", wasm}, {"lua.fulllibraries", fulllibraries}}) { + CAPTURE(key); + { + // on in eu07.ini, off in the scenery: off, and nothing in the log + auto const settings{std::make_unique()}; + switched(*settings) = true; + ini_only_settings const ini{*settings}; + // "config python.enabled no endconfig" in the .scn, as the release honoured it + switched(*settings) = false; + CHECK(ini.restore(*settings).empty()); + CHECK_FALSE(switched(*settings)); + } + { + // off in eu07.ini, on in the scenery: back off, and told + auto const settings{std::make_unique()}; + switched(*settings) = false; + ini_only_settings const ini{*settings}; + switched(*settings) = true; + CHECK(ini.restore(*settings) == std::vector{key}); + CHECK_FALSE(switched(*settings)); + } + // as eu07.ini set it: kept, nothing told + for (auto const value : {false, true}) { + auto const settings{std::make_unique()}; + switched(*settings) = value; + ini_only_settings const ini{*settings}; + CHECK(ini.restore(*settings).empty()); + CHECK(switched(*settings) == value); + } + } } TEST_CASE("ini only settings: a scenery runs no program, opens no connection and switches no runtime back on") { diff --git a/utilities/inionlysettings.cpp b/utilities/inionlysettings.cpp index 836954bf1..9d6c587c2 100644 --- a/utilities/inionlysettings.cpp +++ b/utilities/inionlysettings.cpp @@ -23,6 +23,17 @@ template void keep(Type_ &Current, Type_ const &Kept, std::stri } } +// a switch a scenery may turn off but not on: puts Kept back into Current, and adds Key to Changed, only when the +// scenery turned it on. turned off it stays so, as before these keys were kept +void keep_off(bool &Current, bool const Kept, std::string_view const Key, std::vector &Changed) +{ + if (Current && false == Kept) + { + Current = false; + Changed.push_back(Key); + } +} + } // namespace ini_only_settings::ini_only_settings(global_settings const &Settings) @@ -74,9 +85,10 @@ std::vector ini_only_settings::restore(global_settings &Settin #endif keep(Settings.iFeedbackMode, m_feedback_mode, "feedbackmode", changed); keep(Settings.iFeedbackPort, m_feedback_port, "feedbackport", changed); - keep(Settings.python_enabled, m_python_enabled, "python.enabled", changed); - keep(Settings.luascreens_enabled, m_luascreens_enabled, "luascreens.enabled", changed); - keep(Settings.lua_fulllibraries, m_lua_fulllibraries, "lua.fulllibraries", changed); - keep(Settings.wasm_enabled, m_wasm_enabled, "wasm.enabled", changed); + // a scenery may switch a runtime off, and keep its scripts in the sandbox + keep_off(Settings.python_enabled, m_python_enabled, "python.enabled", changed); + keep_off(Settings.luascreens_enabled, m_luascreens_enabled, "luascreens.enabled", changed); + keep_off(Settings.lua_fulllibraries, m_lua_fulllibraries, "lua.fulllibraries", changed); + keep_off(Settings.wasm_enabled, m_wasm_enabled, "wasm.enabled", changed); return changed; } diff --git a/utilities/inionlysettings.h b/utilities/inionlysettings.h index eff5c067f..667703b94 100644 --- a/utilities/inionlysettings.h +++ b/utilities/inionlysettings.h @@ -22,7 +22,8 @@ http://mozilla.org/MPL/2.0/. // (execonexit, extcam.cmd, extcam.rec), write the screenshots elsewhere (screenshotsdir), open connections and ports // (network.server, network.client, zmq.address, motiontelemetry, uart, feedbackmode, feedbackport), switch back on a // script runtime the player switched off (python.enabled, luascreens.enabled, wasm.enabled) or take its own scripts -// out of the sandbox (lua.fulllibraries). they keep what eu07.ini set +// out of the sandbox (lua.fulllibraries). they keep what eu07.ini set; a scenery may still switch a runtime off, or +// keep its scripts in the sandbox when eu07.ini didn't, as it always could class ini_only_settings { public: