int efi_get_variable_string(const char *variable, char **ret) {
_cleanup_free_ void *s = NULL;
size_t ss = 0;
- int r;
char *x;
+ int r;
+
+ assert(variable);
r = efi_get_variable(variable, NULL, &s, &ss);
if (r < 0)
if (!x)
return -ENOMEM;
- *ret = x;
+ if (ret)
+ *ret = x;
+
return 0;
}
+int efi_get_variable_path(const char *variable, char **ret) {
+ int r;
+
+ assert(variable);
+
+ r = efi_get_variable_string(variable, ret);
+ if (r < 0)
+ return r;
+
+ if (ret)
+ efi_tilt_backslashes(*ret);
+
+ return r;
+}
+
static int efi_verify_variable(const char *variable, uint32_t attr, const void *value, size_t size) {
_cleanup_free_ void *buf = NULL;
size_t n;
#include "sd-id128.h"
#include "efivars-fundamental.h"
+#include "string-util.h"
#include "time-util.h"
#define EFI_VENDOR_LOADER SD_ID128_MAKE(4a,67,b0,82,0a,4c,41,cf,b6,c7,44,0b,29,bb,8c,4f)
int efi_get_variable(const char *variable, uint32_t *attribute, void **ret_value, size_t *ret_size);
int efi_get_variable_string(const char *variable, char **ret);
+int efi_get_variable_path(const char *variable, char **ret);
int efi_set_variable(const char *variable, const void *value, size_t size);
int efi_set_variable_string(const char *variable, const char *p);
return -EOPNOTSUPP;
}
+static inline int efi_get_variable_path(const char *variable, char **ret) {
+ return -EOPNOTSUPP;
+}
+
static inline int efi_set_variable(const char *variable, const void *value, size_t size) {
return -EOPNOTSUPP;
}
return -ENODATA;
}
#endif
+
+static inline char *efi_tilt_backslashes(char *s) {
+ return string_replace_char(s, '\\', '/');
+}
uint64_t left, done;
int r;
- r = efi_get_variable_string(EFI_LOADER_VARIABLE(LoaderBootCountPath), &path);
+ r = efi_get_variable_path(EFI_LOADER_VARIABLE(LoaderBootCountPath), &path);
if (r == -ENOENT)
return -EUNATCH; /* in this case, let the caller print a message */
if (r < 0)
return log_error_errno(r, "Failed to read LoaderBootCountPath EFI variable: %m");
- efi_tilt_backslashes(path);
-
if (!path_is_normalized(path))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Path read from LoaderBootCountPath is not normalized, refusing: %s",
return r;
}
-static void read_efi_var(const char *variable, char **ret) {
+static int efi_get_variable_string_and_warn(const char *variable, char **ret) {
int r;
r = efi_get_variable_string(variable, ret);
if (r < 0 && r != -ENOENT)
- log_warning_errno(r, "Failed to read EFI variable '%s', ignoring: %m", variable);
+ return log_warning_errno(r, "Failed to read EFI variable '%s', ignoring: %m", variable);
+
+ return r;
+}
+
+static int efi_get_variable_path_and_warn(const char *variable, char **ret) {
+ int r;
+
+ r = efi_get_variable_path(variable, ret);
+ if (r < 0 && r != -ENOENT)
+ return log_warning_errno(r, "Failed to read EFI variable '%s', ignoring: %m", variable);
+
+ return r;
}
static void print_yes_no_line(bool first, bool good, const char *name) {
Tpm2Support s;
int have;
- read_efi_var(EFI_LOADER_VARIABLE(LoaderFirmwareType), &fw_type);
- read_efi_var(EFI_LOADER_VARIABLE(LoaderFirmwareInfo), &fw_info);
- read_efi_var(EFI_LOADER_VARIABLE(LoaderInfo), &loader);
- read_efi_var(EFI_LOADER_VARIABLE(StubInfo), &stub);
- read_efi_var(EFI_LOADER_VARIABLE(LoaderImageIdentifier), &loader_path);
- read_efi_var(EFI_LOADER_VARIABLE(StubImageIdentifier), &stub_path);
+ (void) efi_get_variable_string_and_warn(EFI_LOADER_VARIABLE(LoaderFirmwareType), &fw_type);
+ (void) efi_get_variable_string_and_warn(EFI_LOADER_VARIABLE(LoaderFirmwareInfo), &fw_info);
+ (void) efi_get_variable_string_and_warn(EFI_LOADER_VARIABLE(LoaderInfo), &loader);
+ (void) efi_get_variable_string_and_warn(EFI_LOADER_VARIABLE(StubInfo), &stub);
+ (void) efi_get_variable_path_and_warn(EFI_LOADER_VARIABLE(LoaderImageIdentifier), &loader_path);
+ (void) efi_get_variable_path_and_warn(EFI_LOADER_VARIABLE(StubImageIdentifier), &stub_path);
(void) efi_loader_get_features(&loader_features);
(void) efi_stub_get_features(&stub_features);
- if (loader_path)
- efi_tilt_backslashes(loader_path);
- if (stub_path)
- efi_tilt_backslashes(stub_path);
-
SecureBootMode secure = efi_get_secure_boot_mode();
printf("%sSystem:%s\n", ansi_underline(), ansi_normal());
printf(" Firmware: %s%s (%s)%s\n", ansi_highlight(), strna(fw_type), strna(fw_info), ansi_normal());
#endif
-static inline char *efi_tilt_backslashes(char *s) {
- return string_replace_char(s, '\\', '/');
-}
-
sd_id128_t efi_guid_to_id128(const void *guid);
void efi_id128_to_guid(sd_id128_t id, void *ret_guid);