Skip to content

Commit 68c6c29

Browse files
author
root
committed
Patch GRack class instead of reopening them
1 parent 8201f4f commit 68c6c29

File tree

3 files changed

+18
-57
lines changed

3 files changed

+18
-57
lines changed

Diff for: lib/grack/auth.rb renamed to lib/grack/auth_patch.rb

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
module Grack
2-
class Auth < Rack::Auth::Basic
3-
4-
attr_accessor :user, :env
2+
module AuthPatch
53

64
def call(env)
75
@env = env
86
@request = Rack::Request.new(env)
9-
@auth = Request.new(env)
7+
@auth = Rack::Auth::Basic::Request.new(env)
108

119
# Need this patch due to the rails mount
1210

@@ -41,7 +39,7 @@ def auth!
4139
end
4240

4341
if authorized_request?
44-
@app.call(env)
42+
@app.call(@env)
4543
else
4644
unauthorized
4745
end
@@ -57,8 +55,8 @@ def authenticate_user(login, password)
5755
def authorized_request?
5856
case git_cmd
5957
when *RedmineGitHosting::GitAccess::DOWNLOAD_COMMANDS
60-
if user
61-
RedmineGitHosting::GitAccess.new.download_access_check(user, repository, is_ssl?).allowed?
58+
if @user
59+
RedmineGitHosting::GitAccess.new.download_access_check(@user, repository, is_ssl?).allowed?
6260
elsif repository.public_project? || repository.public_repo?
6361
# Allow clone/fetch for public projects
6462
true
@@ -70,8 +68,8 @@ def authorized_request?
7068
if !is_ssl?
7169
logger.error('SmartHttp : your are trying to push data without SSL!, exiting !')
7270
false
73-
elsif user
74-
RedmineGitHosting::GitAccess.new.upload_access_check(user, repository).allowed?
71+
elsif @user
72+
RedmineGitHosting::GitAccess.new.upload_access_check(@user, repository).allowed?
7573
else
7674
false
7775
end
@@ -136,3 +134,7 @@ def logger
136134

137135
end
138136
end
137+
138+
unless Grack::Auth.included_modules.include?(Grack::AuthPatch)
139+
Grack::Auth.send(:prepend, Grack::AuthPatch)
140+
end

Diff for: lib/grack/server.rb renamed to lib/grack/server_patch.rb

+5-46
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,5 @@
11
module Grack
2-
class Server
3-
4-
# Override original *service_rpc* method to fix compatibility with Ruby 1.9.3 IO.popen.
5-
#
6-
# Between Ruby 1.9 and Ruby 2.0 the method signature has changed :
7-
# Ruby 1.9.x : popen(cmd, mode="r" [, opt])
8-
# Ruby 2.x : popen([env,] cmd, mode="r" [, opt])
9-
#
10-
# Hence we need to remove the *popen_env* hash from IO.popen args.
11-
#
12-
# See :
13-
# - https://github.com/jbox-web/redmine_git_hosting/issues/345
14-
# - http://ruby-doc.org//core-1.9.3/IO.html#method-c-popen
15-
# - http://ruby-doc.org//core-2.1.0/IO.html#method-c-popen
16-
#
17-
# Notes :
18-
# Given that some people use the Debian package to install Redmine which depends on Ruby 1.9.3
19-
# this patch will stay until the release of Debian Jessie which will provide Ruby 2.1 .
20-
# You're still strongly encouraged to move to Ruby 2.x .
21-
#
22-
if RUBY_VERSION.split('.')[0] == '1'
23-
def service_rpc
24-
return render_no_access if !has_access(@rpc, true)
25-
input = read_body
26-
27-
@res = Rack::Response.new
28-
@res.status = 200
29-
@res['Content-Type'] = "application/x-git-#{@rpc}-result"
30-
@res['Transfer-Encoding'] = 'chunked'
31-
@res['Cache-Control'] = 'no-cache'
32-
33-
@res.finish do
34-
command = git_command(%W(#{@rpc} --stateless-rpc #{@dir}))
35-
IO.popen(command, File::RDWR, popen_options) do |pipe|
36-
pipe.write(input)
37-
pipe.close_write
38-
while !pipe.eof?
39-
block = pipe.read(8192) # 8KB at a time
40-
@res.write encode_chunk(block) # stream it to the client
41-
end
42-
@res.write terminating_chunk
43-
end
44-
end
45-
end
46-
end
47-
2+
module ServerPatch
483

494
# Override original *get_git_dir* method because the path is relative
505
# and accessed via Sudo.
@@ -172,3 +127,7 @@ def repository_object
172127

173128
end
174129
end
130+
131+
unless Grack::Server.included_modules.include?(Grack::ServerPatch)
132+
Grack::Server.send(:prepend, Grack::ServerPatch)
133+
end

Diff for: lib/redmine_git_hosting.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ def loglevel
8080
require_dependency 'redmine/scm/adapters/xitolite_adapter'
8181

8282
## Gitlab Grack for Git SmartHTTP
83-
require_dependency 'grack/auth'
84-
require_dependency 'grack/server'
83+
require_dependency 'grack/auth_patch'
84+
require_dependency 'grack/server_patch'
8585

8686
## Hrack for Git Hooks
8787
require 'hrack/init'

0 commit comments

Comments
 (0)