class GitRoom::Server

Public Class Methods

serve(user) click to toggle source
# 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