summaryrefslogtreecommitdiff
path: root/git-daemon
diff options
context:
space:
mode:
authorTony Finch <dot@dotat.at>2010-03-31 00:52:01 +0100
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>2010-05-22 15:54:41 +0100
commit9ad7f5edd331027061b3d41bff050fe97d19b866 (patch)
treea4bd2734fad149f2024cb6d30b09187c762ffb56 /git-daemon
parentcb5c438e93240f2a63835b24fdd66edf9e9b31dc (diff)
downloaduserv-utils-9ad7f5edd331027061b3d41bff050fe97d19b866.tar.gz
git-daemon: tidy up a bit
Diffstat (limited to 'git-daemon')
-rwxr-xr-xgit-daemon/git-daemon-service.pl29
-rwxr-xr-xgit-daemon/git-daemon.pl52
2 files changed, 36 insertions, 45 deletions
diff --git a/git-daemon/git-daemon-service.pl b/git-daemon/git-daemon-service.pl
index 19b6327..f848db8 100755
--- a/git-daemon/git-daemon-service.pl
+++ b/git-daemon/git-daemon-service.pl
@@ -11,35 +11,30 @@ use warnings;
use Sys::Syslog;
-our $check_repo = 1;
-our $check_export = 0;
-our ($service,$client,$dir,$repo);
+${$::{$_}} = $ENV{"USERV_U_$_"}
+ for grep s|^USERV_U_([a-z_]+)$|$1|, keys %ENV;
-${$main::{$_}} = $ENV{"USERV_U_$_"}
- for grep s/^USERV_U_//, keys %ENV;
+our ($client,$service,$path,$host);
openlog "userv-$service", 'pid', 'daemon';
sub fail { syslog 'err', "$client @_"; exit }
-$_ = our $uri;
+our ($check_repo,$check_export,$dir,$repo) = (1,0);
+our $uri = $_ = "git://$host/$path";
for my $cf (@ARGV) { do $cf }
-fail "no repository configured for $uri" unless defined $repo;
-fail "no directory configured for $uri" unless defined $dir;
-
my $home = (getpwuid $<)[7];
$dir = "$home/$dir" if $dir =~ m|^[^/]|
or $dir =~ s|^~/||;
-$dir = "$dir/$repo";
-
-fail "bad repository in $uri"
- if $check_repo and $repo !~ /^[0-9A-Za-z._-]+[.]git$/;
-fail "repository not exported for $uri"
- if $check_export and not -e "$dir/git-daemon-export-ok";
-syslog 'info', "$client $dir";
+fail "Bad filename $repo" if $check_repo
+ and $repo !~ m|^\w[\w.=+-]*\.git$|;
+$dir = "$dir/$repo" if defined $repo;
+$path = $check_export ? "$dir/git-daemon-export-ok" : $dir;
+fail "$! $path" unless -e $path;
+syslog 'notice', "$client $dir";
my @cmd = ($service, '--strict', '--timeout=30', $dir);
no warnings; # suppress errors to stderr
-exec @cmd or fail "exec @cmd: $!";
+exec @cmd or fail "exec $service: $!";
# end
diff --git a/git-daemon/git-daemon.pl b/git-daemon/git-daemon.pl
index 68d8162..91dd727 100755
--- a/git-daemon/git-daemon.pl
+++ b/git-daemon/git-daemon.pl
@@ -15,53 +15,49 @@ use Sys::Syslog;
sub ntoa {
my $sockaddr = shift;
- return ('[?.?.?.?]:?') unless defined $sockaddr;
+ 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,$uri,$user);
+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 = "";
- local $SIG{ALRM} = sub { fail "timeout" };
- alarm 30;
- while ($length > length $buffer) {
- my $ret = sysread STDIN, $buffer, $length, length $buffer;
- fail "short read: expected $length bytes, got " . length $buffer
+ my $length = shift; $_ = "";
+ while ($length > length) {
+ my $ret = sysread STDIN, $_, $length, length;
+ fail "Expected $length bytes, got ".length
if defined $ret and $ret == 0;
fail "read: $!" if not defined $ret and $! != EINTR and $! != EAGAIN;
}
- alarm 0;
- return $buffer;
}
-
-my $len_hex = xread 4;
-fail "non-hex packet length" unless $len_hex =~ m{^[0-9a-fA-F]{4}$};
-my $line = xread hex $len_hex;
-if ($line !~ m{^(git-[a-z-]+) /*([!-~]+)\0host=([!-~]+)\0$}) {
- $line =~ s|[^ -~]+| |g;
- fail "could not parse \"$line\""
+xread 4;
+fail "Bad hex in packet length" unless m|^[0-9a-fA-F]{4}$|;
+xread hex;
+unless (($service,$path,$host) =
+ m|^(git-[a-z-]+) /*([!-~]+)\0host=([!-~]+)\0$|) {
+ s|[^ -~]+| |g;
+ fail "Could not parse \"$_\""
}
-($service,$path,$host) = ($1,$2,$3);
-$_ = $uri = "git://$host/$path";
+our $uri = $_ = "git://$host/$path";
for my $cf (@ARGV) { do $cf }
-fail "no user configured for $uri" unless defined $user;
-syslog 'info', "$client $service $uri";
+fail "No user for $uri" unless defined $user;
+syslog 'notice', "$client $service $uri";
-my @opts = map "-D$_=${$main::{$_}}",
- grep defined ${$main::{$_}} && /^[a-z]+$/,
- sort keys %main::;
+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 @cmd: $!";
+exec @cmd or fail "exec userv: $!";
# end