src/hg-ssh
changeset 43 0a7fc4652793
parent 39 f5055ce263c7
child 46 d2bbab5ffd0e
equal deleted inserted replaced
42:0e77495e91e2 43:0a7fc4652793
    46         path = path[:-1]
    46         path = path[:-1]
    47     if not ruleset.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, cmd):
    51 def try_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", repo=repo):
    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             dispatch.dispatch(['-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", repo=repo):
    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             dispatch.dispatch(['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")
    65 #logfile.write("Started: %s\n" % sys.argv)
    65 #logfile.write("Started: %s\n" % sys.argv)
    66 
    66 
    69         % sys.argv)
    69         % sys.argv)
    70 
    70 
    71 rules = ruleset.rules_from_env()
    71 rules = ruleset.rules_from_env()
    72 rules.set(user = getpath(os.environ['REMOTE_USER']))
    72 rules.set(user = getpath(os.environ['REMOTE_USER']))
    73 rules.set(branch = None, file = None)
    73 rules.set(branch = None, file = None)
    74 todispatch = get_cmd(rules, 
    74 try_cmd(rules, os.environ.get('SSH_ORIGINAL_COMMAND', '?'))
    75     os.environ.get('SSH_ORIGINAL_COMMAND', '?'))
       
    76 dispatch.dispatch(todispatch)
       
    77 
    75