]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: move check if secure boot enrollment applies to a single place
authorLennart Poettering <lennart@poettering.net>
Tue, 25 Feb 2025 11:36:17 +0000 (12:36 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 25 Feb 2025 20:15:10 +0000 (21:15 +0100)
Let's check if sb enrollment applies at a single place: inside the
discovery function, and let's not bother with additional checks later.

src/boot/boot.c

index ec32f14e977a455ef316e1dce9d7a3dcb35719cf..090f7237cdcb78333a7f397a94cbcbc6aefbac0e 100644 (file)
@@ -2711,6 +2711,9 @@ static EFI_STATUS secure_boot_discover_keys(Config *config, EFI_FILE *root_dir)
         EFI_STATUS err;
         _cleanup_file_close_ EFI_FILE *keys_basedir = NULL;
 
+        if (config->secure_boot_enroll == ENROLL_OFF)
+                return EFI_SUCCESS;
+
         if (!IN_SET(secure_boot_mode(), SECURE_BOOT_SETUP, SECURE_BOOT_AUDIT))
                 return EFI_SUCCESS;
 
@@ -2874,12 +2877,10 @@ static void config_load_all_entries(
                 config_add_entry(config, entry);
         }
 
-        /* Find secure boot signing keys and autoload them if configured.
-         * Otherwise, create menu entries so that the user can load them manually.
-         * If the secure-boot-enroll variable is set to no (the default), we do not
-         * even search for keys on the ESP */
-        if (config->secure_boot_enroll != ENROLL_OFF)
-                secure_boot_discover_keys(config, root_dir);
+        /* Find secure boot signing keys and autoload them if configured.  Otherwise, create menu entries so
+         * that the user can load them manually.  If the secure-boot-enroll variable is set to no (the
+         * default), we do not even search for keys on the ESP */
+        (void) secure_boot_discover_keys(config, root_dir);
 
         if (config->n_entries == 0)
                 return;
@@ -2977,7 +2978,7 @@ static EFI_STATUS run(EFI_HANDLE image) {
                 }
 
                 /* if auto enrollment is activated, we try to load keys for the given entry. */
-                if (entry->type == LOADER_SECURE_BOOT_KEYS && config.secure_boot_enroll != ENROLL_OFF) {
+                if (entry->type == LOADER_SECURE_BOOT_KEYS) {
                         err = secure_boot_enroll_at(root_dir, entry->path, /*force=*/ true);
                         if (err != EFI_SUCCESS)
                                 return err;