diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c index 652a6d5c89..76af4e4ed5 100644 --- a/src/firstboot/firstboot.c +++ b/src/firstboot/firstboot.c @@ -458,6 +458,20 @@ static int process_locale(int rfd) { return 1; } +static bool keymap_exists_bool(const char *name) { + return keymap_exists(name) > 0; +} + +static typeof(&keymap_is_valid) determine_keymap_validity_func(int rfd) { + int r; + + r = dir_fd_is_root(rfd); + if (r < 0) + log_debug_errno(r, "Unable to determine if operating on host root directory, assuming we are: %m"); + + return r != 0 ? keymap_exists_bool : keymap_is_valid; +} + static int prompt_keymap(int rfd) { _cleanup_strv_free_ char **kmaps = NULL; int r; @@ -489,7 +503,7 @@ static int prompt_keymap(int rfd) { print_welcome(rfd); return prompt_loop("Please enter system keymap name or number", - kmaps, 60, keymap_is_valid, &arg_keymap); + kmaps, 60, determine_keymap_validity_func(rfd), &arg_keymap); } static int process_keymap(int rfd) { @@ -1695,6 +1709,8 @@ static int run(int argc, char *argv[]) { /* We check these conditions here instead of in parse_argv() so that we can take the root directory * into account. */ + if (arg_keymap && !determine_keymap_validity_func(rfd)(arg_keymap)) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Keymap %s is not installed.", arg_keymap); if (arg_locale && !locale_is_ok(rfd, arg_locale)) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Locale %s is not installed.", arg_locale); if (arg_locale_messages && !locale_is_ok(rfd, arg_locale_messages))