From: Ludwig Nussel Date: Wed, 7 Dec 2022 10:43:56 +0000 (+0100) Subject: bootctl: print entry token as well X-Git-Tag: v253-rc1~182 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8109b2908def1b8038e0a6d3474eeca7cd143d4f;p=thirdparty%2Fsystemd.git bootctl: print entry token as well --- diff --git a/src/boot/bootctl-install.c b/src/boot/bootctl-install.c index d6c2feaeafb..31c2050a4af 100644 --- a/src/boot/bootctl-install.c +++ b/src/boot/bootctl-install.c @@ -95,98 +95,6 @@ static int load_etc_kernel_install_conf(void) { return 0; } -static int settle_entry_token(void) { - int r; - - switch (arg_entry_token_type) { - - case ARG_ENTRY_TOKEN_AUTO: { - _cleanup_free_ char *buf = NULL; - r = read_one_line_file("/etc/kernel/entry-token", &buf); - if (r < 0 && r != -ENOENT) - return log_error_errno(r, "Failed to read /etc/kernel/entry-token: %m"); - - if (!isempty(buf)) { - free_and_replace(arg_entry_token, buf); - arg_entry_token_type = ARG_ENTRY_TOKEN_LITERAL; - } else if (sd_id128_is_null(arg_machine_id)) { - _cleanup_free_ char *id = NULL, *image_id = NULL; - - r = parse_os_release(NULL, - "IMAGE_ID", &image_id, - "ID", &id); - if (r < 0) - return log_error_errno(r, "Failed to load /etc/os-release: %m"); - - if (!isempty(image_id)) { - free_and_replace(arg_entry_token, image_id); - arg_entry_token_type = ARG_ENTRY_TOKEN_OS_IMAGE_ID; - } else if (!isempty(id)) { - free_and_replace(arg_entry_token, id); - arg_entry_token_type = ARG_ENTRY_TOKEN_OS_ID; - } else - return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "No machine ID set, and /etc/os-release carries no ID=/IMAGE_ID= fields."); - } else { - r = free_and_strdup_warn(&arg_entry_token, SD_ID128_TO_STRING(arg_machine_id)); - if (r < 0) - return r; - - arg_entry_token_type = ARG_ENTRY_TOKEN_MACHINE_ID; - } - - break; - } - - case ARG_ENTRY_TOKEN_MACHINE_ID: - if (sd_id128_is_null(arg_machine_id)) - return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "No machine ID set."); - - r = free_and_strdup_warn(&arg_entry_token, SD_ID128_TO_STRING(arg_machine_id)); - if (r < 0) - return r; - - break; - - case ARG_ENTRY_TOKEN_OS_IMAGE_ID: { - _cleanup_free_ char *buf = NULL; - - r = parse_os_release(NULL, "IMAGE_ID", &buf); - if (r < 0) - return log_error_errno(r, "Failed to load /etc/os-release: %m"); - - if (isempty(buf)) - return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "IMAGE_ID= field not set in /etc/os-release."); - - free_and_replace(arg_entry_token, buf); - break; - } - - case ARG_ENTRY_TOKEN_OS_ID: { - _cleanup_free_ char *buf = NULL; - - r = parse_os_release(NULL, "ID", &buf); - if (r < 0) - return log_error_errno(r, "Failed to load /etc/os-release: %m"); - - if (isempty(buf)) - return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "ID= field not set in /etc/os-release."); - - free_and_replace(arg_entry_token, buf); - break; - } - - case ARG_ENTRY_TOKEN_LITERAL: - assert(!isempty(arg_entry_token)); /* already filled in by command line parser */ - break; - } - - if (isempty(arg_entry_token) || !(utf8_is_valid(arg_entry_token) && string_is_safe(arg_entry_token))) - return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Selected entry token not valid: %s", arg_entry_token); - - log_debug("Using entry token: %s", arg_entry_token); - return 0; -} - static bool use_boot_loader_spec_type1(void) { /* If the layout is not specified, or if it is set explicitly to "bls" we assume Boot Loader * Specification Type #1 is the chosen format for our boot loader entries */ diff --git a/src/boot/bootctl-status.c b/src/boot/bootctl-status.c index a0fee7d3c73..0adb354bdb8 100644 --- a/src/boot/bootctl-status.c +++ b/src/boot/bootctl-status.c @@ -80,6 +80,8 @@ static int status_entries( if (!sd_id128_is_null(dollar_boot_partition_uuid)) printf(" (/dev/disk/by-partuuid/" SD_ID128_UUID_FORMAT_STR ")", SD_ID128_FORMAT_VAL(dollar_boot_partition_uuid)); + if (settle_entry_token() >= 0) + printf("\n token: %s", arg_entry_token); printf("\n\n"); if (config->default_entry < 0) diff --git a/src/boot/bootctl-util.c b/src/boot/bootctl-util.c index c994f5f9524..b11742a7aef 100644 --- a/src/boot/bootctl-util.c +++ b/src/boot/bootctl-util.c @@ -5,8 +5,10 @@ #include "bootctl.h" #include "bootctl-util.h" #include "fileio.h" +#include "os-util.h" #include "stat-util.h" #include "sync-util.h" +#include "utf8.h" int sync_everything(void) { int ret = 0, k; @@ -109,3 +111,95 @@ finish: return r; } + +int settle_entry_token(void) { + int r; + + switch (arg_entry_token_type) { + + case ARG_ENTRY_TOKEN_AUTO: { + _cleanup_free_ char *buf = NULL; + r = read_one_line_file("/etc/kernel/entry-token", &buf); + if (r < 0 && r != -ENOENT) + return log_error_errno(r, "Failed to read /etc/kernel/entry-token: %m"); + + if (!isempty(buf)) { + free_and_replace(arg_entry_token, buf); + arg_entry_token_type = ARG_ENTRY_TOKEN_LITERAL; + } else if (sd_id128_is_null(arg_machine_id)) { + _cleanup_free_ char *id = NULL, *image_id = NULL; + + r = parse_os_release(NULL, + "IMAGE_ID", &image_id, + "ID", &id); + if (r < 0) + return log_error_errno(r, "Failed to load /etc/os-release: %m"); + + if (!isempty(image_id)) { + free_and_replace(arg_entry_token, image_id); + arg_entry_token_type = ARG_ENTRY_TOKEN_OS_IMAGE_ID; + } else if (!isempty(id)) { + free_and_replace(arg_entry_token, id); + arg_entry_token_type = ARG_ENTRY_TOKEN_OS_ID; + } else + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "No machine ID set, and /etc/os-release carries no ID=/IMAGE_ID= fields."); + } else { + r = free_and_strdup_warn(&arg_entry_token, SD_ID128_TO_STRING(arg_machine_id)); + if (r < 0) + return r; + + arg_entry_token_type = ARG_ENTRY_TOKEN_MACHINE_ID; + } + + break; + } + + case ARG_ENTRY_TOKEN_MACHINE_ID: + if (sd_id128_is_null(arg_machine_id)) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "No machine ID set."); + + r = free_and_strdup_warn(&arg_entry_token, SD_ID128_TO_STRING(arg_machine_id)); + if (r < 0) + return r; + + break; + + case ARG_ENTRY_TOKEN_OS_IMAGE_ID: { + _cleanup_free_ char *buf = NULL; + + r = parse_os_release(NULL, "IMAGE_ID", &buf); + if (r < 0) + return log_error_errno(r, "Failed to load /etc/os-release: %m"); + + if (isempty(buf)) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "IMAGE_ID= field not set in /etc/os-release."); + + free_and_replace(arg_entry_token, buf); + break; + } + + case ARG_ENTRY_TOKEN_OS_ID: { + _cleanup_free_ char *buf = NULL; + + r = parse_os_release(NULL, "ID", &buf); + if (r < 0) + return log_error_errno(r, "Failed to load /etc/os-release: %m"); + + if (isempty(buf)) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "ID= field not set in /etc/os-release."); + + free_and_replace(arg_entry_token, buf); + break; + } + + case ARG_ENTRY_TOKEN_LITERAL: + assert(!isempty(arg_entry_token)); /* already filled in by command line parser */ + break; + } + + if (isempty(arg_entry_token) || !(utf8_is_valid(arg_entry_token) && string_is_safe(arg_entry_token))) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Selected entry token not valid: %s", arg_entry_token); + + log_debug("Using entry token: %s", arg_entry_token); + return 0; +} diff --git a/src/boot/bootctl-util.h b/src/boot/bootctl-util.h index baa9c5711af..6f2c1630de2 100644 --- a/src/boot/bootctl-util.h +++ b/src/boot/bootctl-util.h @@ -6,3 +6,5 @@ int sync_everything(void); const char *get_efi_arch(void); int get_file_version(int fd, char **ret); + +int settle_entry_token(void);