nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0028-Try-mac-guid-etc-before-grub.cfg-on-tftp-config-file.patch

8e15ce
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
8e15ce
From: Peter Jones <pjones@redhat.com>
8e15ce
Date: Mon, 8 Jul 2019 17:33:22 +0200
8e15ce
Subject: [PATCH] Try mac/guid/etc before grub.cfg on tftp config files.
8e15ce
8e15ce
Signed-off-by: Peter Jones <pjones@redhat.com>
8e15ce
---
8e15ce
 grub-core/normal/main.c | 97 ++++++++++++++++++++++++++-----------------------
8e15ce
 1 file changed, 51 insertions(+), 46 deletions(-)
8e15ce
8e15ce
diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c
b35c50
index bf24e65713..0a99768f75 100644
8e15ce
--- a/grub-core/normal/main.c
8e15ce
+++ b/grub-core/normal/main.c
b35c50
@@ -345,61 +345,66 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)),
8e15ce
       /* Guess the config filename. It is necessary to make CONFIG static,
8e15ce
 	 so that it won't get broken by longjmp.  */
8e15ce
       char *config;
8e15ce
-      const char *prefix, *fw_path;
8e15ce
-
8e15ce
-      prefix = fw_path = grub_env_get ("fw_path");
8e15ce
-      if (fw_path)
8e15ce
-	{
8e15ce
-	  config = grub_xasprintf ("%s/grub.cfg", fw_path);
8e15ce
-	  if (config)
8e15ce
-	    {
8e15ce
-	      grub_file_t file;
8e15ce
-
8e15ce
-	      file = grub_file_open (config, GRUB_FILE_TYPE_CONFIG);
8e15ce
-	      if (file)
8e15ce
-		{
8e15ce
-		  grub_file_close (file);
8e15ce
-		  grub_enter_normal_mode (config);
8e15ce
-		}
8e15ce
-              else
8e15ce
-                {
8e15ce
-                  /*  Ignore all errors.  */
8e15ce
-                  grub_errno = 0;
8e15ce
-                }
8e15ce
-	      grub_free (config);
8e15ce
-	    }
8e15ce
-	}
8e15ce
+      const char *prefix;
8e15ce
+      const char *net_search_cfg;
8e15ce
+      int disable_net_search = 0;
8e15ce
 
8e15ce
+      prefix = grub_env_get ("fw_path");
8e15ce
       if (! prefix)
8e15ce
 	      prefix = grub_env_get ("prefix");
8e15ce
+
8e15ce
+      net_search_cfg = grub_env_get ("feature_net_search_cfg");
8e15ce
+      if (net_search_cfg && net_search_cfg[0] == 'n')
8e15ce
+	      disable_net_search = 1;
8e15ce
+
8e15ce
       if (prefix)
8e15ce
         {
8e15ce
-          grub_size_t config_len;
8e15ce
-          int disable_net_search = 0;
8e15ce
-          const char *net_search_cfg;
8e15ce
-
8e15ce
-          config_len = grub_strlen (prefix) +
8e15ce
-                       sizeof ("/grub.cfg-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
8e15ce
-          config = grub_malloc (config_len);
8e15ce
-
8e15ce
-          if (!config)
8e15ce
-            goto quit;
8e15ce
-
8e15ce
-          grub_snprintf (config, config_len, "%s/grub.cfg", prefix);
8e15ce
-
8e15ce
-          net_search_cfg = grub_env_get ("feature_net_search_cfg");
8e15ce
-          if (net_search_cfg && net_search_cfg[0] == 'n')
8e15ce
-            disable_net_search = 1;
8e15ce
-
8e15ce
           if (grub_strncmp (prefix + 1, "tftp", sizeof ("tftp") - 1) == 0 &&
8e15ce
               !disable_net_search)
8e15ce
-            grub_net_search_config_file (config);
8e15ce
+            {
8e15ce
+              grub_size_t config_len;
8e15ce
+              config_len = grub_strlen (prefix) +
8e15ce
+                sizeof ("/grub.cfg-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
8e15ce
+              config = grub_malloc (config_len);
8e15ce
 
8e15ce
-	  grub_enter_normal_mode (config);
8e15ce
-	  grub_free (config);
8e15ce
-	}
8e15ce
+              if (! config)
8e15ce
+                goto quit;
8e15ce
+
8e15ce
+              grub_snprintf (config, config_len, "%s/grub.cfg", prefix);
8e15ce
+
8e15ce
+              grub_net_search_configfile (config);
8e15ce
+
8e15ce
+              grub_enter_normal_mode (config);
8e15ce
+              grub_free (config);
8e15ce
+              config = NULL;
8e15ce
+            }
8e15ce
+
8e15ce
+          if (!config)
8e15ce
+            {
8e15ce
+              config = grub_xasprintf ("%s/grub.cfg", prefix);
8e15ce
+              if (config)
8e15ce
+                {
8e15ce
+                  grub_file_t file;
8e15ce
+
8e15ce
+                  file = grub_file_open (config, GRUB_FILE_TYPE_CONFIG);
8e15ce
+                  if (file)
8e15ce
+                    {
8e15ce
+                      grub_file_close (file);
8e15ce
+                      grub_enter_normal_mode (config);
8e15ce
+                    }
8e15ce
+                  else
8e15ce
+                    {
8e15ce
+                      /*  Ignore all errors.  */
8e15ce
+                      grub_errno = 0;
8e15ce
+                    }
8e15ce
+                  grub_free (config);
8e15ce
+                }
8e15ce
+            }
8e15ce
+        }
8e15ce
       else
8e15ce
-	grub_enter_normal_mode (0);
8e15ce
+        {
8e15ce
+          grub_enter_normal_mode (0);
8e15ce
+        }
8e15ce
     }
8e15ce
   else
8e15ce
     grub_enter_normal_mode (argv[0]);