[tftp] Mangle initial slash on TFTP URIs

TFTP URIs are intrinsically problematic, since:

- TFTP servers may use either normal slashes or backslashes as a
  directory separator,

- TFTP servers allow filenames to be specified using relative paths
  (with no initial directory separator),

- TFTP filenames present in a DHCP filename field may use special
  characters such as "?" or "#" that prevent parsing as a generic URI.

As of commit 7667536 ("[uri] Refactor URI parsing and formatting"), we
have directly constructed TFTP URIs from DHCP next-server and filename
pairs, avoiding the generic URI parser.  This eliminated the problems
related to special characters, but indirectly made it impossible to
parse a "tftp://..." URI string into a TFTP URI with a non-absolute
path.

Re-introduce the convention of requiring an extra slash in a
"tftp://..." URI string in order to specify a TFTP URI with an initial
slash in the filename.  For example:

  tftp://192.168.0.1/boot/pxelinux.0  => RRQ "boot/pxelinux.0"
  tftp://192.168.0.1//boot/pxelinux.0 => RRQ "/boot/pxelinux.0"

This is ugly, but there seems to be no other sensible way to provide
the ability to specify all possible TFTP filenames.

A side-effect of this change is that format_uri() will no longer add a
spurious initial "/" when formatting a relative URI string.  This
improves the console output when fetching an image specified via a
relative URI.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2016-01-21 16:24:16 +00:00
parent 42c2a6aab7
commit f0e9e55442
3 changed files with 60 additions and 28 deletions

View File

@@ -713,9 +713,9 @@ static struct uri_pxe_test uri_pxe_absolute_path = {
{
.scheme = "tftp",
.host = "192.168.0.2",
.path = "/absolute/path",
.path = "//absolute/path",
},
"tftp://192.168.0.2/absolute/path",
"tftp://192.168.0.2//absolute/path",
};
/** PXE URI with relative path */
@@ -731,7 +731,7 @@ static struct uri_pxe_test uri_pxe_relative_path = {
{
.scheme = "tftp",
.host = "192.168.0.3",
.path = "relative/path",
.path = "/relative/path",
},
"tftp://192.168.0.3/relative/path",
};
@@ -749,7 +749,7 @@ static struct uri_pxe_test uri_pxe_icky = {
{
.scheme = "tftp",
.host = "10.0.0.6",
.path = "C:\\tftpboot\\icky#path",
.path = "/C:\\tftpboot\\icky#path",
},
"tftp://10.0.0.6/C%3A\\tftpboot\\icky%23path",
};
@@ -769,9 +769,9 @@ static struct uri_pxe_test uri_pxe_port = {
.scheme = "tftp",
.host = "192.168.0.1",
.port = "4069",
.path = "/another/path",
.path = "//another/path",
},
"tftp://192.168.0.1:4069/another/path",
"tftp://192.168.0.1:4069//another/path",
};
/** Current working URI test */