src/hg-ssh
changeset 107 84e9e33d866b
parent 106 0519745e7a57
child 108 00b48d7bdfa0
equal deleted inserted replaced
106:0519745e7a57 107:84e9e33d866b
    32 from mercurial import demandimport; demandimport.enable()
    32 from mercurial import demandimport; demandimport.enable()
    33 
    33 
    34 from mercurial import dispatch
    34 from mercurial import dispatch
    35 
    35 
    36 import sys, os, os.path
    36 import sys, os, os.path
       
    37 import base64
    37 from mercurialserver import ruleset, paths
    38 from mercurialserver import ruleset, paths
    38 
    39 
    39 def fail(message):
    40 def fail(message):
    40     sys.stderr.write("mercurial-server: %s\n" % message)
    41     sys.stderr.write("mercurial-server: %s\n" % message)
    41     sys.exit(-1)
    42     sys.exit(-1)
    42 
    43 
    43 def checkpath(path)
    44 def checkpath(path):
    44     path = os.path.dirname(path)
    45     path = os.path.dirname(path)
    45     if path == "":
    46     if path == "":
    46         return
    47         return
    47     if os.path.exists(path + "/.hg"):
    48     if os.path.exists(path + "/.hg"):
    48         raise ruleset.AccessException()
    49         raise ruleset.AccessException()
    63     return repo
    64     return repo
    64 
    65 
    65 #logfile = open("/tmp/hg-ssh.%d.txt" % os.getpid(), "w")
    66 #logfile = open("/tmp/hg-ssh.%d.txt" % os.getpid(), "w")
    66 #logfile.write("Started: %s\n" % sys.argv)
    67 #logfile.write("Started: %s\n" % sys.argv)
    67 
    68 
    68 if len(sys.argv) != 2:
    69 paths.setExePath()
       
    70 
       
    71 if len(sys.argv) == 3 and sys.argv[1] == "--base64":
       
    72     ruleset.rules.set(user = base64.b64decode(sys.argv[2]))
       
    73 elif len(sys.argv) == 2:
       
    74     ruleset.rules.set(user = sys.argv[1])
       
    75 else:
    69     fail("hg-ssh wrongly called, is authorized_keys corrupt? (%s)" 
    76     fail("hg-ssh wrongly called, is authorized_keys corrupt? (%s)" 
    70         % sys.argv)
    77         % sys.argv)
    71 
       
    72 paths.setExePath()
       
    73 ruleset.rules.set(user = sys.argv[1])
       
    74 
    78 
    75 # Use a different hgrc for remote pulls - this way you can set
    79 # Use a different hgrc for remote pulls - this way you can set
    76 # up access.py for everything at once without affecting local operations
    80 # up access.py for everything at once without affecting local operations
    77 
    81 
    78 os.environ['HGRCPATH'] = paths.getEtcPath() + "/remote-hgrc"
    82 os.environ['HGRCPATH'] = paths.getEtcPath() + "/remote-hgrc"
    87 
    91 
    88 cmd = os.environ.get('SSH_ORIGINAL_COMMAND', '')
    92 cmd = os.environ.get('SSH_ORIGINAL_COMMAND', '')
    89 try:
    93 try:
    90     if cmd.startswith('hg -R ') and cmd.endswith(' serve --stdio'):
    94     if cmd.startswith('hg -R ') and cmd.endswith(' serve --stdio'):
    91         repo = getrepo("read", cmd[6:-14])
    95         repo = getrepo("read", cmd[6:-14])
    92         if not os.path.isdir(repo + "/.hg")
    96         if not os.path.isdir(repo + "/.hg"):
    93             fail("no such repository %s" % repo)
    97             fail("no such repository %s" % repo)
    94         dispatch.dispatch(['-R', repo, 'serve', '--stdio'])
    98         dispatch.dispatch(['-R', repo, 'serve', '--stdio'])
    95     elif cmd.startswith('hg init '):
    99     elif cmd.startswith('hg init '):
    96         repo = getrepo("init", cmd[8:])
   100         repo = getrepo("init", cmd[8:])
    97         if os.path.exists(repo):
   101         if os.path.exists(repo):