9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/gitroom/server.rb', line 9
def self.serve(user)
permissions = 'rw'
command = ENV['SSH_ORIGINAL_COMMAND']
abort unless user && permissions && command
STDERR.write ENV.to_hash.to_yaml
valid_actions = ['git-receive-pack', 'git-upload-pack']
action = command.split[0]
repo = command.split[1]
commands = command.split
commands[1] = "repos/#{repo}"
command = commands.join ' '
abort unless valid_actions.include? action
abort "read denied for #{user}" unless permissions =~ /r/
abort "write denied for #{user}" if action == 'git-receive-pack' && permissions !~ /w/
STDERR.write "user #{user} authorized\n"
Kernel.exec 'git', 'shell', '-c', command
end
|