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