misc: Ensure editor is not accessible from console if disabled

This commit is contained in:
mintsuki 2022-03-02 13:31:09 +01:00
parent 77e90fa95f
commit 23ff2b0d2b
4 changed files with 12 additions and 8 deletions

View File

@ -15,10 +15,11 @@ static void console_help(void) {
"Available commands:\n"
"exit -- Exit Limine console.\n"
"clear -- Clears the console.\n"
"editor -- Open an empty boot entry editor.\n"
"%s"
"version -- Print version.\n"
"copyright -- Print copyright.\n"
"help -- Print this help message.\n"
"help -- Print this help message.\n",
editor_enabled ? "editor -- Open an empty boot entry editor.\n" : ""
);
}
@ -37,7 +38,7 @@ void console(void) {
break;
} else if (strcmp(prompt, "clear") == 0) {
print("\e[2J\e[H");
} else if (strcmp(prompt, "editor") == 0) {
} else if (editor_enabled && strcmp(prompt, "editor") == 0) {
char *new_entry = config_entry_editor("New Entry", "");
if (new_entry != NULL) {
boot(new_entry);

View File

@ -19,6 +19,8 @@ UINTN efi_mmap_size = 0, efi_desc_size = 0;
UINT32 efi_desc_ver = 0;
#endif
bool editor_enabled = true;
bool parse_resolution(size_t *width, size_t *height, size_t *bpp, const char *buf) {
size_t res[3] = {0};

View File

@ -33,7 +33,7 @@ extern struct volume *boot_volume;
extern bool stage3_loaded;
#endif
extern bool verbose, quiet, serial;
extern bool verbose, quiet, serial, editor_enabled;
bool parse_resolution(size_t *width, size_t *height, size_t *bpp, const char *buf);

View File

@ -665,6 +665,11 @@ static noreturn void _menu(bool timeout_enabled) {
char *serial_str = config_get_value(NULL, 0, "SERIAL");
serial = serial_str != NULL && strcmp(serial_str, "yes") == 0;
char *editor_enabled_str = config_get_value(NULL, 0, "EDITOR_ENABLED");
if (editor_enabled_str != NULL) {
editor_enabled = strcmp(editor_enabled_str, "yes") == 0;
}
menu_branding = config_get_value(NULL, 0, "MENU_BRANDING");
if (menu_branding == NULL)
menu_branding = "Limine " LIMINE_VERSION;
@ -699,10 +704,6 @@ static noreturn void _menu(bool timeout_enabled) {
skip_timeout = true;
}
bool editor_enabled = true;
char *editor_enabled_config = config_get_value(NULL, 0, "EDITOR_ENABLED");
if (!strcmp(editor_enabled_config, "no")) editor_enabled = false;
if (!skip_timeout && !timeout) {
// Use print tree to load up selected_menu_entry and determine if the
// default entry is valid.