X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/userv-utils/blobdiff_plain/cb5c438e93240f2a63835b24fdd66edf9e9b31dc..9ad7f5edd331027061b3d41bff050fe97d19b866:/git-daemon/git-daemon-service.pl 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