Project

General

Profile

Patch #4905 » 0001-Redmine.pm-add-Git-smart-HTTP-support.patch

Antonio García-Domínguez, 2010-02-23 13:36

View differences:

extra/svn/Redmine.pm
And you need to upgrade at least reposman.rb (after r860).
=head1 GIT SMART HTTP SUPPORT
Git's smart HTTP protocol will not work with the above settings. Redmine
normally does access control depending on the HTTP method used: read-only
methods are OK for public repositories but not for private ones, and the
rest require member access.
However, this scheme doesn't work for Git's smart HTTP protocol: it will use
POST even for a simple clone! Instead, read-only requests must be detected
using the full URL (including the query string): anything that doesn't belong
to the git-receive-pack service is read-only.
To activate this mode of operation, add this line inside your <Location /git>
block:
RedmineGitSmartHttp yes
Once you have activated this option, you have two options when cloning a
repository. Cloning using "http://user@host/git/repo" works, but will ask for
the password all the time. To avoid being pestered by password requests, it's
best to create a ~/.netrc file with your username and password, and clone using
"http://host/git/repo" instead.
IMPORTANT NOTE: It is *very important* that the file cannot be read by other
users, as it will contain your password in cleartext. To create the file, you
can use the following commands, replacing yourhost, youruser and yourpassword
with the right values:
touch ~/.netrc
chmod 600 .netrc
echo -e "machine yourhost\nlogin youruser\npassword yourpassword"
=cut
use strict;
......
args_how => TAKE1,
errmsg => 'RedmineCacheCredsMax must be decimal number',
},
{
name => 'RedmineGitSmartHttp',
req_override => OR_AUTHCFG,
args_how => TAKE1,
},
);
sub RedmineDSN {
......
}
}
sub RedmineGitSmartHttp {
my ($self, $parms, $arg) = @_;
$arg = lc $arg;
if ($arg eq "yes" || $arg eq "true") {
$self->{RedmineGitSmartHttp} = 1;
} else {
$self->{RedmineGitSmartHttp} = 0;
}
}
sub trim {
my $string = shift;
$string =~ s/\s{2,}/ /g;
......
Apache2::Module::add(__PACKAGE__, \@directives);
my %read_only_methods = map { $_ => 1 } qw/GET PROPFIND REPORT OPTIONS/;
sub request_is_read_only {
my ($r) = @_;
my $cfg = Apache2::Module::get_config(__PACKAGE__, $r->server, $r->per_dir_config);
# Do we use Git's smart HTTP protocol, or not?
if (defined $cfg->{RedmineGitSmartHttp} and $cfg->{RedmineGitSmartHttp}) {
my $uri = $r->unparsed_uri;
my $is_read_only = $uri !~ /^\/git\/.*\/[^\/]*git\-receive\-pack$/o;
return $is_read_only;
} else {
# Old behaviour: check the HTTP method
my $method = $r->method;
return defined $read_only_methods{$method};
}
}
sub access_handler {
my $r = shift;
......
return FORBIDDEN;
}
my $method = $r->method;
return OK unless defined $read_only_methods{$method};
return OK unless request_is_read_only($r);
my $project_id = get_project_identifier($r);
......
unless ($auth_source_id) {
my $method = $r->method;
if ($hashed_password eq $pass_digest && ((defined $read_only_methods{$method} && $permissions =~ /:browse_repository/) || $permissions =~ /:commit_access/) ) {
if ($hashed_password eq $pass_digest && ((request_is_read_only($r) && $permissions =~ /:browse_repository/) || $permissions =~ /:commit_access/) ) {
$ret = 1;
last;
}
(1-1/24)