dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

Blame SOURCES/0215-efi-http-Make-root_url-reflect-the-protocol-hostname.patch

d9d99f
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
d9d99f
From: Peter Jones <pjones@redhat.com>
d9d99f
Date: Mon, 30 Jul 2018 16:39:57 -0400
d9d99f
Subject: [PATCH] efi/http: Make root_url reflect the protocol+hostname of our
d9d99f
 boot url.
d9d99f
d9d99f
This lets you write config files that don't know urls.
d9d99f
d9d99f
Signed-off-by: Peter Jones <pjones@redhat.com>
d9d99f
---
d9d99f
 grub-core/net/efi/http.c | 19 +++++++++++++++++++
d9d99f
 1 file changed, 19 insertions(+)
d9d99f
d9d99f
diff --git a/grub-core/net/efi/http.c b/grub-core/net/efi/http.c
d9d99f
index 3f61fd2fa5b..243acbaa35b 100644
d9d99f
--- a/grub-core/net/efi/http.c
d9d99f
+++ b/grub-core/net/efi/http.c
d9d99f
@@ -4,6 +4,7 @@
d9d99f
 #include <grub/misc.h>
d9d99f
 #include <grub/net/efi.h>
d9d99f
 #include <grub/charset.h>
d9d99f
+#include <grub/env.h>
d9d99f
 
d9d99f
 static void
d9d99f
 http_configure (struct grub_efi_net_device *dev, int prefer_ip6)
d9d99f
@@ -351,6 +352,24 @@ grub_efihttp_open (struct grub_efi_net_device *dev,
d9d99f
   grub_err_t err;
d9d99f
   grub_off_t size;
d9d99f
   char *buf;
d9d99f
+  char *root_url;
d9d99f
+  grub_efi_ipv6_address_t address;
d9d99f
+  const char *rest;
d9d99f
+
d9d99f
+  if (grub_efi_string_to_ip6_address (file->device->net->server, &address, &rest) && *rest == 0)
d9d99f
+    root_url = grub_xasprintf ("%s://[%s]", type ? "https" : "http", file->device->net->server);
d9d99f
+  else
d9d99f
+    root_url = grub_xasprintf ("%s://%s", type ? "https" : "http", file->device->net->server);
d9d99f
+  if (root_url)
d9d99f
+    {
d9d99f
+      grub_env_unset ("root_url");
d9d99f
+      grub_env_set ("root_url", root_url);
d9d99f
+      grub_free (root_url);
d9d99f
+    }
d9d99f
+  else
d9d99f
+    {
d9d99f
+      return grub_errno;
d9d99f
+    }
d9d99f
 
d9d99f
   err = efihttp_request (dev->http, file->device->net->server, file->device->net->name, type, 1, 0);
d9d99f
   if (err != GRUB_ERR_NONE)