Skip to contentSkip to conversation

Cleaned up git-daemon virtual hosting support.

PATCH In review Jon Loeliger 3 participants 5 messages Jun 15, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Cleaned up git-daemon virtual hosting support.

Standardized on lowercase hostnames from client.

Added interpolation values for the IP address, Port and canoncial hostname of the server as it is contacted and named by the client.

Added --host=host_or_ipaddr option suport.

Documented mutual exclusivity of --inetd option with

    --user, --group, --host and --port options.

Added compat_inet_pton from Paul Vixie as needed.

Small memory leaks need to be cleaned up still.

---

Junio,

This is on top of my previous patch in the next branch. This makes virtual host support way, way less stupid. I'll follow up with another patch to clean up the small leaks.

Thanks,
jdl

 Documentation/git-daemon.txt |   45 +++++++--
 Makefile                     |    3 +
 compat/inet_pton.c           |  220 ++++++++++++++++++++++++++++++++++++++++++
 daemon.c                     |  146 ++++++++++++++++++++++++----
 4 files changed, 387 insertions(+), 27 deletions(-)
Documentation/git-daemon.txt +38 -7
index 87444b4..422cc37 100644
@@ -8,14 +8,15 @@ git-daemon - A really simple server for 
 SYNOPSIS
 --------
 [verse]
-'git-daemon' [--verbose] [--syslog] [--inetd | --port=n] [--export-all]
+'git-daemon' [--verbose] [--syslog] [--export-all]
              [--timeout=n] [--init-timeout=n] [--strict-paths]
              [--base-path=path] [--user-path | --user-path=path]
              [--interpolated-path=pathtemplate]
+             [--reuseaddr] [--detach] [--pid-file=file]
              [--enable=service] [--disable=service]
 	     [--allow-override=service] [--forbid-override=service]
-             [--reuseaddr] [--detach] [--pid-file=file]
-             [--user=user [--group=group]] [directory...]
+	     [--inetd | [--host=host_or_ipaddr] [--port=n] [--user=user [--group=group]]
+	     [directory...]
 
 DESCRIPTION
 -----------
@@ -54,8 +55,12 @@ OPTIONS
 --interpolated-path=pathtemplate::
 	To support virtual hosting, an interpolated path template can be
 	used to dynamically construct alternate paths.  The template
-	supports %H for the target hostname as supplied by the client,
-	and %D for the absolute path of the named repository.	
+	supports %H for the target hostname as supplied by the client but
+	converted to all lowercase, %CH for the canonical hostname,
+	%IP for the server's IP address, %P for the port number,
+	and %D for the absolute path of the named repository.
+	After interpolation, the path is validated against the directory
+	whitelist.
 
 --export-all::
 	Allow pulling from all directories that look like GIT repositories
@@ -64,9 +69,17 @@ OPTIONS
 
 --inetd::
 	Have the server run as an inetd service. Implies --syslog.
+	Incompatible with --port, --host, --user and --group options.
+
+--host=host_or_ipaddr::
+	Listen on an a specific IP address or hostname.  IP addresses can
+	be either an IPv4 address or an IPV6 address if supported.  If IPv6
+	is not supported, then --host=hostname is also not supported and
+	--host must be given an IPv4 address.
+	Incompatible with '--inetd' option.
 
---port::
-	Listen on an alternative port.
+--port=n::
+	Listen on an alternative port.  Incompatible with '--inetd' option.
 
 --init-timeout::
 	Timeout between the moment the connection is established and the
@@ -182,6 +195,24 @@ clients, a symlink from `/software` into
 default repository could be made as well.
 
 
+git-daemon as regular daemon for virtual hosts::
+	To set up `git-daemon` as a regular, non-inetd service that
+	handles repositories for multiple virtual hosts based on
+	their IP addresses, start the daemon like this:
++
+------------------------------------------------
+	git-daemon --verbose --export-all
+		--interpolated-path=/pub/%IP/%D
+		/pub/192.168.1.200/software
+		/pub/10.10.220.23/software
+------------------------------------------------
++
+In this example, the root-level directory `/pub` will contain
+a subdirectory for each virtual host IP address supported.
+Repositories can still be accessed by hostname though, assuming
+they correspond to these IP addresses.
+
+
 Author
 ------
 Written by Linus Torvalds <[email protected]>, YOSHIFUJI Hideaki
Makefile +3 -0
index 673ba2d..bae4822 100644
@@ -520,6 +520,9 @@ endif
 ifdef NO_INET_NTOP
 	LIB_OBJS += compat/inet_ntop.o
 endif
+ifdef NO_INET_PTON
+	LIB_OBJS += compat/inet_pton.o
+endif
 
 ifdef NO_ICONV
 	ALL_CFLAGS += -DNO_ICONV
compat/inet_pton.c new file +220 -0

220 lines not on this page · raw message

daemon.c +126 -20

255 lines not on this page · raw message

Signature · 1 line
1.4.2.1.g85d8-dirty
#1 lore raw
Quoted 1 line

Added --host=host_or_ipaddr option suport.

I wonder if --listen= might be more appropriate name:

        "Listen a.b.c.d:port" (Apache),
        "ListenAddress" (ssh daemon).
        "--listen-host=" (svnserve).

I wanted to find an example or two who uses "bind" but I think listen is more popular.

Quoted 3 lines

This is on top of my previous patch in the next branch. This makes virtual host support way, way less stupid. I'll follow up with another patch to clean up the small leaks.

Thanks.

#2 lore raw
Quoted 11 lines · Junio C Hamano
Quoted 1 line

Added --host=host_or_ipaddr option suport.

I wonder if --listen= might be more appropriate name:

        "Listen a.b.c.d:port" (Apache),
        "ListenAddress" (ssh daemon).
        "--listen-host=" (svnserve).

I wanted to find an example or two who uses "bind" but I think listen is more popular.

Apache has both Bind and Listen (at least 1.3 series). I've never understood the difference between the two, if there is one.

Signature · 3 lines
Andreas Ericsson                   [email protected]
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231
#3 lore raw
In reply to Junio C Hamano

So, like, the other day Junio C Hamano mumbled:

Quoted 4 lines
Quoted 1 line

Added --host=host_or_ipaddr option suport.

I wonder if --listen= might be more appropriate name:

        "Listen a.b.c.d:port" (Apache),

No problem. I'll respin that to use

    --listen=<ip_or_host>

Do you want this?:

    --listen=[<ip_or_host>][:<port>]

And if you do, does --port= just go away, fade away, or remain?

Would you prefer patch-on-patch or respin?

jdl

#4 lore raw
In reply to Junio C Hamano

So, like, the other day Junio C Hamano mumbled:

Quoted 3 lines
Quoted 1 line

Added --host=host_or_ipaddr option suport.

I wonder if --listen= might be more appropriate name:

Hmmm... I had asked it you wanted to incorporate a ":<port>"
notion into the listen address. Turns out that is a bad idea since the <host_or_ipaddr> part can also be a IPv6 address just riddled with colon characters.

I'll just leave it "--listen=<host_or_ipaddr>" and "--port=<n>".

jdl