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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>

---
 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;
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux