{"thread":{"id":"4384","subject":"git daemon directory munging?","startedAt":"2006-06-04T00:13:45Z","lastAt":"2006-06-04T23:10:32Z","messageCount":5,"participants":["Jon Loeliger","Linus Torvalds","Junio C Hamano","H. Peter Anvin"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"21175","messageId":"E1FmgFV-0001i6-Kc@jdl.com","threadId":"4384","inReplyTo":null,"subject":"git daemon directory munging?","fromName":"Jon Loeliger","fromEmail":"jdl@jdl.com","sentAt":"2006-06-04T00:13:45Z","receivedAt":"2006-06-04T00:13:45Z","isPatch":false,"sender":{"key":"jdl@jdl.com","avatar":"https://gravatar.com/avatar/75ce9a10b151acd2c28ec4ab2136dba7b2ff1634530bd04b155981a749d08a64?d=mp&s=160"},"body":"Scrapped right off the #git IRC channel...\n\n\n<jdl> I stumbled across some git-daemon quirk for which I'd like opinions on\n      possible solutions.\t\t\t\t\t\t[18:56]\n<jdl> I run a server that houses multiple virtual hosts on one physical\n      machine.\n<jdl> It has multiple Apache based websites on it, and I want to front\n      multiple git repositories with gitweb.  That all works fine.\t[18:57]\n<jdl> But when I set up my repository stores, ie the /pub/scm/repo.git places,\n      it falls apart.\n<jdl> I want to maintain separate sets of git repos for each virtual site.\n\t\t\t\t\t\t\t\t\t[18:58]\n<jdl> That is, www.foo.com can't see the repos of www.bar.com and vice versa.\n<jdl> So I have an Apache directory set up that maps www.foo.com/pub/scm to\n      some place like /pub/foo/scm using an alias for /pub/scm.\t\t[18:59]\n<jdl> Similarly, for www.bar.com I map /pub/scm to /pub/bar/scm\n<jdl> Now, when I clone using http: all is well as it correctly maps the URL\n      using the Apache Alias entry.\t\t\t\t\t[19:00]\n<jdl> However, when cloning via git: it doesn't do the Alias mapping based on\n      the given website prefix part of the URL.\n<jdl> I would have to clone using git://www.foo.com/pub/foo/scm even though I\n      would clone using http://www.foo.com/pub/scm/\t\t\t[19:01]\n<jdl> So my proposed solution is to setup a genarlization of the git-daemon\n      -baser-path=path argument.\n<jdl> Instead of a single --base-path, there are potentially multiple\n      --base-path entries that match multiple a URL prefixes.\t\t[19:02]\n<jdl> Thus, I'd use something like:\n      --map-base=www.foo.com/pub/scm:/pub/foo/scm\n      --map-base=www.bar.com/pub/scm=/pub/bar/scm\t\t\t[19:04]\n<dormando> mod_rewrite for git :|\n<jdl> Quick prefix hack, yeah.\t\t\t\t\t\t[19:05]\n<jdl> Um, stop me before I hack....? :-)\t\t\t\t[19:06]\n<dormando> you're going to end up needing something that supports basic\n\t   regexes before long\n<dormando> I can't think of many cases where you'd want to directly map like\n\t   that, and especially in that specific manner.\t\t[19:07]\n<jdl> I can't hear you.\n<dormando> sorry.\n* dormando was going to have similar problems for his hosting service\n"},{"id":"21176","messageId":"Pine.LNX.4.64.0606031722340.5498@g5.osdl.org","threadId":"4384","inReplyTo":"E1FmgFV-0001i6-Kc@jdl.com","subject":"Re: git daemon directory munging?","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2006-06-04T00:42:35Z","receivedAt":"2006-06-04T00:42:35Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Sat, 3 Jun 2006, Jon Loeliger wrote:\n>\n> <jdl> Thus, I'd use something like:\n>       --map-base=www.foo.com/pub/scm:/pub/foo/scm\n>       --map-base=www.bar.com/pub/scm=/pub/bar/scm\n\nThe bigger problem is that nothing actually passes in the hostname to \ngit-daemon in the first place. By the time the git-daemon is contacted, \nthe hostname is long gone ;(\n\nNow, you can just extend the git protocol to just pass in the host too. \n\nYou can in fact do this in a backwards-compatible manner (old git-daemons \nwill just ignore it, and new git daemons will automatically notice new \nclients) with something evil like the appended.\n\nNot tested (and this actualyl doesn't make the daemon _use_ the data, it \njust adds a comment - the rest \"is left as an exercise for the reader\")\n\n\t\tLinus\n\n---\ndiff --git a/connect.c b/connect.c\nindex 54f7bf7..36c5d04 100644\n--- a/connect.c\n+++ b/connect.c\n@@ -374,7 +374,7 @@ static int git_tcp_connect(int fd[2], co\n \n \tfd[0] = sockfd;\n \tfd[1] = sockfd;\n-\tpacket_write(sockfd, \"%s %s\\n\", prog, path);\n+\tpacket_write(sockfd, \"%s %s%c%s%c%s\\n\", prog, path, 0, host, 0, port);\n \treturn 0;\n }\n \ndiff --git a/daemon.c b/daemon.c\nindex 776749e..61e0af9 100644\n--- a/daemon.c\n+++ b/daemon.c\n@@ -267,7 +267,7 @@ static int upload(char *dir)\n static int execute(void)\n {\n \tstatic char line[1000];\n-\tint len;\n+\tint len, n;\n \n \talarm(init_timeout ? init_timeout : timeout);\n \tlen = packet_read_line(0, line, sizeof(line));\n@@ -276,6 +276,14 @@ static int execute(void)\n \tif (len && line[len-1] == '\\n')\n \t\tline[--len] = 0;\n \n+\tn = strlen(line);\n+\tif (n != len) {\n+\t\t/* Cool, we have hidden info at the end */\n+\t\t/* Parse the hostname and the port, and */\n+\t\t/* leave some room for expansion for\t*/\n+\t\t/* the future ..\t\t\t*/\n+\t}\n+\n \tif (!strncmp(\"git-upload-pack \", line, 16))\n \t\treturn upload(line+16);\n \n"},{"id":"21188","messageId":"7vverhcu5n.fsf@assigned-by-dhcp.cox.net","threadId":"4384","inReplyTo":"Pine.LNX.4.64.0606031722340.5498@g5.osdl.org","subject":"Re: git daemon directory munging?","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-06-04T06:27:32Z","receivedAt":"2006-06-04T06:27:32Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Linus Torvalds <torvalds@osdl.org> writes:\n\n> diff --git a/connect.c b/connect.c\n> index 54f7bf7..36c5d04 100644\n> --- a/connect.c\n> +++ b/connect.c\n> @@ -374,7 +374,7 @@ static int git_tcp_connect(int fd[2], co\n>  \n>  \tfd[0] = sockfd;\n>  \tfd[1] = sockfd;\n> -\tpacket_write(sockfd, \"%s %s\\n\", prog, path);\n> +\tpacket_write(sockfd, \"%s %s%c%s%c%s\\n\", prog, path, 0, host, 0, port);\n>  \treturn 0;\n>  }\n\nAdding host like HTTP does with Host: header makes sense but I\nthink the accept side can usually tell what the port it accepted\nthe connection to is.\n"},{"id":"21233","messageId":"44836803.5070405@zytor.com","threadId":"4384","inReplyTo":"Pine.LNX.4.64.0606031722340.5498@g5.osdl.org","subject":"Re: git daemon directory munging?","fromName":"H. Peter Anvin","fromEmail":"hpa@zytor.com","sentAt":"2006-06-04T23:08:51Z","receivedAt":"2006-06-04T23:08:51Z","isPatch":false,"sender":{"key":"hpa@zytor.com","avatar":null},"body":"Linus Torvalds wrote:\n> \n> On Sat, 3 Jun 2006, Jon Loeliger wrote:\n>> <jdl> Thus, I'd use something like:\n>>       --map-base=www.foo.com/pub/scm:/pub/foo/scm\n>>       --map-base=www.bar.com/pub/scm=/pub/bar/scm\n> \n> The bigger problem is that nothing actually passes in the hostname to \n> git-daemon in the first place. By the time the git-daemon is contacted, \n> the hostname is long gone ;(\n\nWell, you can bind different git daemons to different IP addresses \n(IP-based vhosting) or different ports (with SRV records in DNS.)\n\n> Now, you can just extend the git protocol to just pass in the host too. \n> \n> You can in fact do this in a backwards-compatible manner (old git-daemons \n> will just ignore it, and new git daemons will automatically notice new \n> clients) with something evil like the appended.\n> \n\nThat's actually what was done to HTTP.\n\n> Not tested (and this actualyl doesn't make the daemon _use_ the data, it \n> just adds a comment - the rest \"is left as an exercise for the reader\")\n\n\n\t-hpa\n"},{"id":"21234","messageId":"44836868.1050700@zytor.com","threadId":"4384","inReplyTo":"7vverhcu5n.fsf@assigned-by-dhcp.cox.net","subject":"Re: git daemon directory munging?","fromName":"H. Peter Anvin","fromEmail":"hpa@zytor.com","sentAt":"2006-06-04T23:10:32Z","receivedAt":"2006-06-04T23:10:32Z","isPatch":false,"sender":{"key":"hpa@zytor.com","avatar":null},"body":"Junio C Hamano wrote:\n> \n> Adding host like HTTP does with Host: header makes sense but I\n> think the accept side can usually tell what the port it accepted\n> the connection to is.\n> \n\nYes, but that requires that each hostname has a separate IP address \nand/or port number (and SRV records in DNS, which not all platforms pay \nattention to.)\n\nNow, if the hostname is passed in like this, it needs to be carefully \ncanonicalized, and there needs to be provisions for wildcard matches.\n\n\t-hpa\n"}]}