chiark / gitweb /
WIP entirely new git approach with config parsers
[userv-utils.git] / git-daemon / git-daemon.in
similarity index 68%
rename from git-daemon/git-daemon
rename to git-daemon/git-daemon.in
index 645cbc5bce9b0f4c7a2cfcc553fd7887d47dbcf2..8fe8ca116ab17762260c521a7adf9a611854bf0b 100755 (executable)
@@ -2,8 +2,8 @@
 #
 # A git daemon with an added userv security boundary.
 #
-# This was written by Tony Finch <dot@dotat.at>
-# You may do anything with it, at your own risk.
+# This was written by Tony Finch <dot@dotat.at> and subsequently
+# heavily modified by Ian Jackson <ijackson@chiark.greenend.org.uk>
 # http://creativecommons.org/publicdomain/zero/1.0/
 
 use strict;
@@ -22,7 +22,7 @@ sub ntoa {
 }
 our ($client,$client_addr,$client_port) = ntoa getpeername STDIN;
 our ($server,$server_addr,$server_port) = ntoa getsockname STDIN;
-our ($service,$path,$host,$user);
+our ($service,$specpath,$spechost);
 
 openlog 'userv-git-daemon', 'pid', 'daemon';
 sub fail { syslog 'err', "$client @_"; exit }
@@ -44,21 +44,28 @@ sub xread {
 my $hex_len = xread 4;
 fail "Bad hex in packet length" unless $hex_len =~ m|^[0-9a-fA-F]{4}$|;
 my $line = xread -4 + hex $hex_len;
-unless (($service,$path,$host) = $line =~
+unless (($service,$specpath,$spechost) = $line =~
         m|^(git-[a-z-]+) /*([!-~]+)\0host=([!-~]+)\0$|) {
     $line =~ s|[^ -~]+| |g;
     fail "Could not parse \"$line\""
 }
-our $uri = $_ = "git://$host/$path";
-for my $cf (@ARGV) { do $cf }
 
-fail "No user for $uri" unless defined $user;
-syslog 'notice', "$client $service $uri";
+@@READ_URLMAP@@
+
+fail "No mapping for $uri" unless defined $serve_user;
+syslog 'notice', "$client $service $serve_user $uri";
+
+my ($hn,$ha,$at,$naddrs,@addrs) = gethostbyname $host;
+die "hostname/address mismatch ($spechost $server_addr)" unless grep {
+    $server_addr eq inet_ntoa $_
+    } @addrs;
 
 my @opts = map "-D$_=${$::{$_}}",
-        grep defined ${$::{$_}} && /^[a-z_]+$/, keys %::;
+    qw(service path host
+       client client_addr client_port
+       server server_addr server_port);
 
-my @cmd = ('userv', @opts, $user, $service);
+my @cmd = ('userv', '-t300', @opts, $user, $service);
 no warnings; # suppress errors to stderr
 exec @cmd or fail "exec userv: $!";