git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/3] git-daemon: vhost support

From
JEJan Engelhardt <jengelh@medozas.de>
Date
Jan 14, 2009, 10:49 UTC
Message-ID
<alpine.LSU.2.00.0901141148390.16109@fbirervta.pbzchgretzou.qr>
In-Reply-To
<alpine.LSU.2.00.0901141148130.16109@fbirervta.pbzchgretzou.qr>
parent v1.6.1
git-daemon: support vhosts

Since git clients usually send the target hostname in the request similar to the "Host:" HTTP header, one can do virtual hosting.

Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
---
 daemon.c |   22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)
Index: git-1.6.1/daemon.c
===================================================================
--- git-1.6.1.orig/daemon.c
+++ git-1.6.1/daemon.c
@@ -2,6 +2,7 @@
 #include "pkt-line.h"
 #include "exec_cmd.h"
 
+#include <stdbool.h>
 #include <syslog.h>
 
 #ifndef HOST_NAME_MAX
@@ -21,7 +22,7 @@ static const char daemon_usage[] =
 "           [--timeout=n] [--init-timeout=n] [--max-connections=n]\n"
 "           [--strict-paths] [--base-path=path] [--base-path-relaxed]\n"
 "           [--user-path | --user-path=path]\n"
-"           [--interpolated-path=path]\n"
+"           [--interpolated-path=path] [--vhost]\n"
 "           [--reuseaddr] [--detach] [--pid-file=file]\n"
 "           [--[enable|disable|allow-override|forbid-override]=service]\n"
 "           [--inetd | [--listen=host_or_ipaddr] [--port=n]\n"
@@ -36,6 +37,7 @@ static int strict_paths;
 static int export_all_trees;
 
 /* Take all paths relative to this one if non-NULL */
+static bool enable_vhosting;
 static char *base_path;
 static char *interpolated_path;
 static int base_path_relaxed;
@@ -309,8 +311,18 @@ static int run_service(char *dir, struct
 		return -1;
 	}
 
-	if (!(path = path_ok(dir)))
-		return -1;
+	if (enable_vhosting) {
+		char vdir[256];
+
+		if (avoid_alias(dir) != 0)
+			return -1;
+		snprintf(vdir, sizeof(vdir), "/%s%s", hostname, dir);
+		if ((path = path_ok(vdir)) == NULL)
+			return -1;
+	} else {
+		if ((path = path_ok(dir)) == NULL)
+			return -1;
+	}
 
 	/*
 	 * Security on the cheap.
@@ -1046,6 +1058,10 @@ int main(int argc, char **argv)
 			make_service_overridable(arg + 18, 0);
 			continue;
 		}
+		if (strcmp(arg, "--vhost") == 0) {
+			enable_vhosting = true;
+			continue;
+		}
 		if (!strcmp(arg, "--")) {
 			ok_paths = &argv[i+1];
 			break;
Previous: Jan EngelhardtNext: Junio C Hamano
Message 3 of 13 in “git-daemon: single-line logs”
  1. 1/3 git-daemon: single-line logsJan Engelhardt, Jan 14, 2009
  2. 2/3 git-daemon: use getnameinfo to resolve hostnameJan Engelhardt, Jan 14, 2009
  3. 3/3 git-daemon: vhost supportJan Engelhardt, Jan 14, 2009
  4. Junio C HamanoJan 14, 2009
  5. Jan EngelhardtJan 14, 2009
  6. Junio C HamanoJan 14, 2009
  7. Jan EngelhardtJan 14, 2009
  8. Jeff KingJan 14, 2009
  9. Adeodato SimóJan 14, 2009
  10. Jay SoffianJan 14, 2009
  11. Jan EngelhardtJan 14, 2009
  12. Junio C HamanoJan 14, 2009
  13. Jan EngelhardtJan 14, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.