#
# 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;
}
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 }
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: $!";