threads / patch / 22398

patch, 2 partsSupport addresses with ':' in git-daemon

Subject: [PATCH 1/2] Support addresses with ':' in git-daemon

## tl;dr

5 messages between Jan 26, 2010 and Jan 26, 2010. Diffs are folded; open one to read it.

replies: 4people: 3as markdown or json

Ilari Liusvaara· Jan 26, 2010, 18:24 UTC · lore

[PATCH 0/2] Allow using ':' in git:// hostname.

This series fixes two problems with using addresses containing ':' (e.g. IPv6 numeric addresses) with git://:

1) ':' in hostname makes vhost headers impossible to parse

If there is ':' in address, the vhost headers become impossible to parse because ':' is also splits host and port and port is optional. Change git-daemon to be able to perform address unwrapping so there is uniquely parseable syntax for hostnames containg ':' (this is compatible to how git-remote-gits encodes such vhost headers and how git-daemon2[1] decodes them).

2) Client double-unwraps addresses

With git://, the addresses are unwrapped twice, which breaks address parsing for addresses enclosed by [], which in turn is required for hostnames containing ':'. This is changed to unwarp the addresses only once. This also changes wrapped addresses to be sent as wrapped for vhost headers (the first patch adds ability to parse this).

[1] The reference implementation of gits:// server daemon.
Ilari Liusvaara (2):
  Support addresses with ':' in git-daemon
  Allow use of []-wrapped addresses in git://
 connect.c |   10 ++++++++--
 daemon.c  |   34 ++++++++++++++++++++++++++++++----
 2 files changed, 38 insertions(+), 6 deletions(-)
Ilari Liusvaara· Jan 26, 2010, 18:24 UTC · re: Ilari Liusvaara · lore

If host address could have ':' in it (e.g. numeric IPv6 address), then host and port could not be uniquely parsed. Fix this by parsing the "["<host>"]":<port> and "["<host>"]" notations. Currently the built-in git:// client would send <host>:<port> or <host> for such thing, but it doesn't matter as due to bugs, resolving address fails if <host> contains ':'.

Signed-off-by: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>
---
 daemon.c |   34 ++++++++++++++++++++++++++++++----
 1 files changed, 30 insertions(+), 4 deletions(-)
Show changes to daemon.c +30 −4
diff --git a/daemon.c b/daemon.c
index 360635e..6c2bd97 100644
--- a/daemon.c
+++ b/daemon.c
@@ -399,6 +399,33 @@ static char *xstrdup_tolower(const char *str)
 	return dup;
 }
 
+static void parse_host_and_port(char *hostport, char **host,
+	char **port)
+{
+	if (*hostport == '[') {
+		char *end;
+
+		end = strchr(hostport, ']');
+		if (!end)
+			die("Invalid reqeuest ('[' without ']')");
+		*end = '\0';
+		*host = hostport + 1;
+		if (!end[1])
+			*port = NULL;
+		else if (end[1] == ':')
+			*port = end + 2;
+		else
+			die("Garbage after end of host part");
+	} else {
+		*host = hostport;
+		*port = strrchr(hostport, ':');
+		if (*port) {
+			*port = '\0';
+			++*port;
+		}
+	}
+}
+
 /*
  * Read the host as supplied by the client connection.
  */
@@ -415,11 +442,10 @@ static void parse_host_arg(char *extra_args, int buflen)
 			vallen = strlen(val) + 1;
 			if (*val) {
 				/* Split <host>:<port> at colon. */
-				char *host = val;
-				char *port = strrchr(host, ':');
+				char *host;
+				char *port;
+				parse_host_and_port(val, &host, &port);
 				if (port) {
-					*port = 0;
-					port++;
 					free(tcp_port);
 					tcp_port = xstrdup(port);
 				}
-- 
1.6.6.1.439.gf06b6
Tay Ray Chuan· Jan 26, 2010, 22:53 UTC · re: Ilari Liusvaara · lore

Re: [PATCH 1/2] Support addresses with ':' in git-daemon

Hi,

On Wed, Jan 27, 2010 at 2:24 AM, Ilari Liusvaara <ilari.liusvaara@elisanet.fi> wrote:

Show 17 quoted lines
> diff --git a/daemon.c b/daemon.c
> index 360635e..6c2bd97 100644
> --- a/daemon.c
> +++ b/daemon.c
> @@ -399,6 +399,33 @@ static char *xstrdup_tolower(const char *str)
>        return dup;
>  }
>
> +static void parse_host_and_port(char *hostport, char **host,
> +       char **port)
> +{
> +       if (*hostport == '[') {
> +               char *end;
> +
> +               end = strchr(hostport, ']');
> +               if (!end)
> +                       die("Invalid reqeuest ('[' without ']')");
s/reqeuest/request/.
-- 
Cheers,
Ray Chuan
Ilari Liusvaara· Jan 26, 2010, 18:24 UTC · re: Ilari Liusvaara · lore

[PATCH 2/2] Allow use of []-wrapped addresses in git://

Allow using "["<host>"]":<port> and "["<host>"]" notations in git:// host addresses. This is needed to be able to connect to addresses that contain ':' (e.g. numeric IPv6 addresses). Also send the host header []-wrapped so it can actually be parsed by remote end.

Signed-off-by: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>
---
 connect.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
Show changes to connect.c +8 −2
diff --git a/connect.c b/connect.c
index 3a12562..20054e4 100644
--- a/connect.c
+++ b/connect.c
@@ -502,12 +502,18 @@ struct child_process *git_connect(int fd[2], const char *url_orig,
 		c = ':';
 	}
 
+	/*
+	 * Don't do destructive transforms with git:// as that
+	 * protocol code does '[]' dewrapping of its own.
+	 */
 	if (host[0] == '[') {
 		end = strchr(host + 1, ']');
 		if (end) {
-			*end = 0;
+			if (protocol != PROTO_GIT) {
+				*end = 0;
+				host++;
+			}
 			end++;
-			host++;
 		} else
 			end = host;
 	} else
-- 
1.6.6.1.439.gf06b6

← back to recent threads