From acc5ace6e58db2f3dceb1f7a27d0fc1fb29c4a27 Mon Sep 17 00:00:00 2001 From: Samuel Mendoza-Jonas Date: Wed, 6 May 2015 17:03:30 +1000 Subject: Make read-only guarantee user-settable Create a new Petitboot option 'petitboot,write?' that specifies whether the system is allowed to mount devices read-write. The option can be toggled by the user in the nc-config screen. Signed-off-by: Samuel Mendoza-Jonas --- discover/device-handler.c | 5 +++++ discover/platform-powerpc.c | 11 +++++++++++ discover/platform.c | 1 + 3 files changed, 17 insertions(+) (limited to 'discover') diff --git a/discover/device-handler.c b/discover/device-handler.c index 31cbcc2..4f7a7b7 100644 --- a/discover/device-handler.c +++ b/discover/device-handler.c @@ -1391,10 +1391,15 @@ static int umount_device(struct discover_device *dev) int device_request_write(struct discover_device *dev, bool *release) { const char *fstype, *device_path; + const struct config *config; int rc; *release = false; + config = config_get(); + if (!config->allow_writes) + return -1; + if (!dev->mounted) return -1; diff --git a/discover/platform-powerpc.c b/discover/platform-powerpc.c index 2b3b043..fc96305 100644 --- a/discover/platform-powerpc.c +++ b/discover/platform-powerpc.c @@ -53,6 +53,7 @@ static const char *known_params[] = { "petitboot,bootdevs", "petitboot,language", "petitboot,debug?", + "petitboot,write?", NULL, }; @@ -548,6 +549,10 @@ static void populate_config(struct platform_powerpc *platform, val = get_param(platform, "petitboot,debug?"); config->debug = val && !strcmp(val, "true"); } + + val = get_param(platform, "petitboot,write?"); + if (val) + config->allow_writes = !strcmp(val, "true"); } static char *iface_config_str(void *ctx, struct interface_config *config) @@ -707,6 +712,12 @@ static int update_config(struct platform_powerpc *platform, val = config->lang ?: ""; update_string_config(platform, "petitboot,language", val); + if (config->allow_writes == defaults->allow_writes) + val = ""; + else + val = config->allow_writes ? "true" : "false"; + update_string_config(platform, "petitboot,write?", val); + update_network_config(platform, config); update_bootdev_config(platform, config); diff --git a/discover/platform.c b/discover/platform.c index 74e2a82..b1d0f19 100644 --- a/discover/platform.c +++ b/discover/platform.c @@ -108,6 +108,7 @@ void config_set_defaults(struct config *config) config->network.n_dns_servers = 0; config->safe_mode = false; config->lang = NULL; + config->allow_writes = true; config->n_autoboot_opts = 2; config->autoboot_opts = talloc_array(config, struct autoboot_option, -- cgit v1.2.1