hg-ssh
changeset 19 62ee928ac9b3
parent 18 538d6b198f4a
child 23 9fa62cfd2821
equal deleted inserted replaced
18:538d6b198f4a 19:62ee928ac9b3
    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
    36 import sys, os
    37 import rules
    37 import ruleset
    38 
    38 
    39 def fail(message):
    39 def fail(message):
    40     #logfile.write("Fail: %s\n" % message)
    40     #logfile.write("Fail: %s\n" % message)
    41     sys.stderr.write(message + "\n")
    41     sys.stderr.write(message + "\n")
    42     sys.exit(-1)
    42     sys.exit(-1)
    43 
    43 
    44 def getpath(path):
    44 def getpath(path):
    45     if path.endswith("/"):
    45     if path.endswith("/"):
    46         path = path[:-1]
    46         path = path[:-1]
    47     if not rules.goodpath(path):
    47     if not ruleset.goodpath(path):
    48         fail("Disallowing path: %s" % path)
    48         fail("Disallowing path: %s" % path)
    49     return path
    49     return path
    50 
    50 
    51 def get_cmd(rules, remoteuser, cmd):
    51 def get_cmd(rules, remoteuser, cmd):
    52     if cmd.startswith('hg -R ') and cmd.endswith(' serve --stdio'):
    52     if cmd.startswith('hg -R ') and cmd.endswith(' serve --stdio'):
    66 
    66 
    67 if len(sys.argv) != 1:
    67 if len(sys.argv) != 1:
    68     fail("hg-ssh must have no arguments (%s)" 
    68     fail("hg-ssh must have no arguments (%s)" 
    69         % sys.argv)
    69         % sys.argv)
    70 
    70 
    71 rules = rules.Ruleset.readfile(os.environ['HG_ACCESS_RULES_FILE'])
    71 rules = ruleset.Ruleset.readfile(os.environ['HG_ACCESS_RULES_FILE'])
    72 remoteuser = getpath(os.environ['REMOTE_USER'])
    72 remoteuser = getpath(os.environ['REMOTE_USER'])
    73 todispatch = get_cmd(rules, remoteuser, 
    73 todispatch = get_cmd(rules, remoteuser, 
    74     os.environ.get('SSH_ORIGINAL_COMMAND', '?'))
    74     os.environ.get('SSH_ORIGINAL_COMMAND', '?'))
    75 dispatch.dispatch(todispatch)
    75 dispatch.dispatch(todispatch)
    76 
    76