nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0300-Prepend-prefix-when-HTTP-path-is-relative.patch

5d780f
From 2370f3f3db0f6887d6be36880be9dc6237cb4f3f Mon Sep 17 00:00:00 2001
5d780f
From: Stephen Benjamin <stephen@redhat.com>
5d780f
Date: Thu, 16 Aug 2018 16:58:51 -0400
5d780f
Subject: [PATCH 1/3] Prepend prefix when HTTP path is relative
5d780f
5d780f
This sets a couple of variables.  With the url http://www.example.com/foo/bar :
5d780f
http_path: /foo/bar
5d780f
http_url: http://www.example.com/foo/bar
5d780f
5d780f
Signed-off-by: Peter Jones <pjones@redhat.com>
5d780f
---
5d780f
 grub-core/kern/main.c    | 10 ++++-
5d780f
 grub-core/net/efi/http.c | 84 ++++++++++++++++++++++++++++++----------
5d780f
 2 files changed, 72 insertions(+), 22 deletions(-)
5d780f
5d780f
diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c
5d780f
index da47b18b50e..dcf48726d54 100644
5d780f
--- a/grub-core/kern/main.c
5d780f
+++ b/grub-core/kern/main.c
5d780f
@@ -130,11 +130,19 @@ grub_set_prefix_and_root (void)
5d780f
   if (fwdevice && fwpath)
5d780f
     {
5d780f
       char *fw_path;
5d780f
+      char separator[3] = ")";
5d780f
 
5d780f
-      fw_path = grub_xasprintf ("(%s)/%s", fwdevice, fwpath);
5d780f
+      grub_dprintf ("fw_path", "\n");
5d780f
+      grub_dprintf ("fw_path", "fwdevice:\"%s\" fwpath:\"%s\"\n", fwdevice, fwpath);
5d780f
+
5d780f
+      if (!grub_strncmp(fwdevice, "http", 4) && fwpath[0] != '/')
5d780f
+	grub_strcpy(separator, ")/");
5d780f
+
5d780f
+      fw_path = grub_xasprintf ("(%s%s%s", fwdevice, separator, fwpath);
5d780f
       if (fw_path)
5d780f
 	{
5d780f
 	  grub_env_set ("fw_path", fw_path);
5d780f
+	  grub_dprintf ("fw_path", "fw_path:\"%s\"\n", fw_path);
5d780f
 	  grub_free (fw_path);
5d780f
 	}
5d780f
     }
5d780f
diff --git a/grub-core/net/efi/http.c b/grub-core/net/efi/http.c
5d780f
index 243acbaa35b..de351b2cd03 100644
5d780f
--- a/grub-core/net/efi/http.c
5d780f
+++ b/grub-core/net/efi/http.c
5d780f
@@ -9,10 +9,52 @@
5d780f
 static void
5d780f
 http_configure (struct grub_efi_net_device *dev, int prefer_ip6)
5d780f
 {
5d780f
+  grub_efi_ipv6_address_t address;
5d780f
   grub_efi_http_config_data_t http_config;
5d780f
   grub_efi_httpv4_access_point_t httpv4_node;
5d780f
   grub_efi_httpv6_access_point_t httpv6_node;
5d780f
   grub_efi_status_t status;
5d780f
+  int https;
5d780f
+  char *http_url;
5d780f
+  const char *rest, *http_server, *http_path = NULL;
5d780f
+
5d780f
+  http_server = grub_env_get ("root");
5d780f
+  https = (grub_strncmp (http_server, "https", 5) == 0) ? 1 : 0;
5d780f
+
5d780f
+  /* extract http server + port */
5d780f
+  if (http_server)
5d780f
+    {
5d780f
+      http_server = grub_strchr (http_server, ',');
5d780f
+      if (http_server)
5d780f
+	http_server++;
5d780f
+    }
5d780f
+
5d780f
+  /* fw_path is like (http,192.168.1.1:8000)/httpboot, extract path part */
5d780f
+  http_path = grub_env_get ("fw_path");
5d780f
+  if (http_path)
5d780f
+    {
5d780f
+      http_path = grub_strchr (http_path, ')');
5d780f
+      if (http_path)
5d780f
+	{
5d780f
+	  http_path++;
5d780f
+	  grub_env_unset ("http_path");
5d780f
+	  grub_env_set ("http_path", http_path);
5d780f
+	}
5d780f
+    }
5d780f
+
5d780f
+  if (http_server && http_path)
5d780f
+    {
5d780f
+      if (grub_efi_string_to_ip6_address (http_server, &address, &rest) && *rest == 0)
5d780f
+	http_url = grub_xasprintf ("%s://[%s]%s", https ? "https" : "http", http_server, http_path);
5d780f
+      else
5d780f
+	http_url = grub_xasprintf ("%s://%s%s", https ? "https" : "http", http_server, http_path);
5d780f
+      if (http_url)
5d780f
+	{
5d780f
+	  grub_env_unset ("http_url");
5d780f
+	  grub_env_set ("http_url", http_url);
5d780f
+	  grub_free (http_url);
5d780f
+	}
5d780f
+    }
5d780f
 
5d780f
   grub_efi_http_t *http = dev->http;
5d780f
 
5d780f
@@ -352,32 +394,32 @@ grub_efihttp_open (struct grub_efi_net_device *dev,
5d780f
   grub_err_t err;
5d780f
   grub_off_t size;
5d780f
   char *buf;
5d780f
-  char *root_url;
5d780f
-  grub_efi_ipv6_address_t address;
5d780f
-  const char *rest;
5d780f
-
5d780f
-  if (grub_efi_string_to_ip6_address (file->device->net->server, &address, &rest) && *rest == 0)
5d780f
-    root_url = grub_xasprintf ("%s://[%s]", type ? "https" : "http", file->device->net->server);
5d780f
-  else
5d780f
-    root_url = grub_xasprintf ("%s://%s", type ? "https" : "http", file->device->net->server);
5d780f
-  if (root_url)
5d780f
-    {
5d780f
-      grub_env_unset ("root_url");
5d780f
-      grub_env_set ("root_url", root_url);
5d780f
-      grub_free (root_url);
5d780f
-    }
5d780f
-  else
5d780f
-    {
5d780f
+  char *file_name = NULL;
5d780f
+  const char *http_path;
5d780f
+
5d780f
+  /* If path is relative, prepend http_path */
5d780f
+  http_path = grub_env_get ("http_path");
5d780f
+  if (http_path && file->device->net->name[0] != '/') {
5d780f
+    file_name = grub_xasprintf ("%s/%s", http_path, file->device->net->name);
5d780f
+    if (!file_name)
5d780f
       return grub_errno;
5d780f
-    }
5d780f
+  }
5d780f
 
5d780f
-  err = efihttp_request (dev->http, file->device->net->server, file->device->net->name, type, 1, 0);
5d780f
+  err = efihttp_request (dev->http, file->device->net->server,
5d780f
+			 file_name ? file_name : file->device->net->name, type, 1, 0);
5d780f
   if (err != GRUB_ERR_NONE)
5d780f
-    return err;
5d780f
+    {
5d780f
+      grub_free (file_name);
5d780f
+      return err;
5d780f
+    }
5d780f
 
5d780f
-  err = efihttp_request (dev->http, file->device->net->server, file->device->net->name, type, 0, &size);
5d780f
+  err = efihttp_request (dev->http, file->device->net->server,
5d780f
+			 file_name ? file_name : file->device->net->name, type, 0, &size);
5d780f
+  grub_free (file_name);
5d780f
   if (err != GRUB_ERR_NONE)
5d780f
-    return err;
5d780f
+    {
5d780f
+      return err;
5d780f
+    }
5d780f
 
5d780f
   buf = grub_malloc (size);
5d780f
   efihttp_read (dev, buf, size);
5d780f
-- 
5d780f
2.24.1
5d780f