X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=blobdiff_plain;ds=sidebyside;f=git-daemon%2Fgit-daemon.pl;fp=git-daemon%2Fgit-daemon.pl;h=0000000000000000000000000000000000000000;hb=3fc5563cc0f31659d09a6cdfd0fd1c7fdb6ed85d;hp=645cbc5bce9b0f4c7a2cfcc553fd7887d47dbcf2;hpb=5f3e811b5415dcff74f82bdd2f26d3af1f73c555;p=userv-utils.git diff --git a/git-daemon/git-daemon.pl b/git-daemon/git-daemon.pl deleted file mode 100755 index 645cbc5..0000000 --- a/git-daemon/git-daemon.pl +++ /dev/null @@ -1,65 +0,0 @@ -#!/usr/bin/perl -# -# A git daemon with an added userv security boundary. -# -# This was written by Tony Finch -# You may do anything with it, at your own risk. -# http://creativecommons.org/publicdomain/zero/1.0/ - -use strict; -use warnings; - -use POSIX; -use Socket; -use Sys::Syslog; - -sub ntoa { - my $sockaddr = shift; - return ('(local)') unless defined $sockaddr; - my ($port,$addr) = sockaddr_in $sockaddr; - $addr = inet_ntoa $addr; - return ("[$addr]:$port",$addr,$port); -} -our ($client,$client_addr,$client_port) = ntoa getpeername STDIN; -our ($server,$server_addr,$server_port) = ntoa getsockname STDIN; -our ($service,$path,$host,$user); - -openlog 'userv-git-daemon', 'pid', 'daemon'; -sub fail { syslog 'err', "$client @_"; exit } - -$SIG{ALRM} = sub { fail "timeout" }; -alarm 30; - -sub xread { - my $length = shift; - my $buffer = ""; - while ($length > length $buffer) { - my $ret = sysread STDIN, $buffer, $length, length $buffer; - fail "Expected $length bytes, got ".length $buffer - if defined $ret and $ret == 0; - fail "read: $!" if not defined $ret and $! != EINTR and $! != EAGAIN; - } - return $buffer; -} -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 =~ - 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"; - -my @opts = map "-D$_=${$::{$_}}", - grep defined ${$::{$_}} && /^[a-z_]+$/, keys %::; - -my @cmd = ('userv', @opts, $user, $service); -no warnings; # suppress errors to stderr -exec @cmd or fail "exec userv: $!"; - -# end