hg-ssh
changeset 21 59540181a4bb
parent 20 f4daa224dc7e
child 23 9fa62cfd2821
equal deleted inserted replaced
20:f4daa224dc7e 21:59540181a4bb
    46         path = path[:-1]
    46         path = path[:-1]
    47     if not rules.goodpath(path):
    47     if not rules.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, cmd):
    52     if cmd.startswith('hg -R ') and cmd.endswith(' serve --stdio'):
    52     if cmd.startswith('hg -R ') and cmd.endswith(' serve --stdio'):
    53         repo = getpath(cmd[6:-14])
    53         repo = getpath(cmd[6:-14])
    54         if rules.allow("read", user=remoteuser, repo=repo, branch=None, file=None):
    54         if rules.allow("read", repo=repo):
    55             os.environ["HG_REPO_PATH"] = repo
    55             os.environ["HG_REPO_PATH"] = repo
    56             return ['-R', repo, 'serve', '--stdio']
    56             return ['-R', repo, 'serve', '--stdio']
    57     elif cmd.startswith('hg init '):
    57     elif cmd.startswith('hg init '):
    58         repo = getpath(cmd[8:])
    58         repo = getpath(cmd[8:])
    59         if rules.allow("init", user=remoteuser, repo=repo, branch=None, file=None):
    59         if rules.allow("init", repo=repo):
    60             os.environ["HG_REPO_PATH"] = repo
    60             os.environ["HG_REPO_PATH"] = repo
    61             return ['init', repo]
    61             return ['init', repo]
    62     fail("Illegal command %r" % cmd)
    62     fail("Illegal command %r" % cmd)
    63 
    63 
    64 #logfile = open("/tmp/hg-ssh.%d.txt" % os.getpid(), "w")
    64 #logfile = open("/tmp/hg-ssh.%d.txt" % os.getpid(), "w")
    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 = rules.Ruleset.readfile(os.environ['HG_ACCESS_RULES_FILE'])
    72 remoteuser = getpath(os.environ['REMOTE_USER'])
    72 rules.set(remoteuser = getpath(os.environ['REMOTE_USER']))
    73 todispatch = get_cmd(rules, remoteuser, 
    73 rules.set(branch = None, file = None)
       
    74 todispatch = get_cmd(rules, 
    74     os.environ.get('SSH_ORIGINAL_COMMAND', '?'))
    75     os.environ.get('SSH_ORIGINAL_COMMAND', '?'))
    75 dispatch.dispatch(todispatch)
    76 dispatch.dispatch(todispatch)
    76 
    77