src/hg-ssh
branchdebian
changeset 248 107d28ce67f5
parent 244 48fab30c38e1
child 275 2e781d52f76e
equal deleted inserted replaced
240:97a8fe72a35e 248:107d28ce67f5
     1 #!/usr/bin/env python
     1 #!/usr/bin/env python
     2 #
       
     3 # Copyright 2008-2009 LShift Ltd
       
     4 # Copyright 2005-2007 by Intevation GmbH <intevation@intevation.de>
       
     5 # Authors:
       
     6 # Paul Crowley <paul@lshift.net>
       
     7 # Thomas Arendsen Hein <thomas@intevation.de>
       
     8 # with ideas from  Mathieu PASQUET <kiorky@cryptelium.net>
       
     9 #
       
    10 # This software may be used and distributed according to the terms
       
    11 # of the GNU General Public License, incorporated herein by reference.
       
    12 
     2 
    13 """
     3 """
    14 hg-ssh - limit access to hg repositories reached via ssh.  Part of
     4 hg-ssh - limit access to hg repositories reached via ssh.  Part of
    15 mercurial-server.
     5 mercurial-server.
    16 
     6 
    53     checkParents(path)
    43     checkParents(path)
    54 
    44 
    55 def getrepo(op, repo):
    45 def getrepo(op, repo):
    56     # First canonicalise, then check the string, then the rules
    46     # First canonicalise, then check the string, then the rules
    57     # and finally the filesystem.
    47     # and finally the filesystem.
    58     repo = repo.rstrip("/")
    48     repo = repo.strip().rstrip("/")
    59     if len(repo) == 0:
    49     if len(repo) == 0:
    60         fail("path to repository seems to be empty")
    50         fail("path to repository seems to be empty")
    61     if repo.startswith("/"):
    51     if repo.startswith("/"):
    62         fail("absolute paths are not supported")
    52         fail("absolute paths are not supported")
    63     checkDots(repo)
    53     checkDots(repo)
    67     checkParents(repo)
    57     checkParents(repo)
    68     return repo
    58     return repo
    69 
    59 
    70 config.initExe()
    60 config.initExe()
    71 
    61 
       
    62 for k,v in config.getEnv():
       
    63     os.environ[k.upper()] = v
       
    64 
    72 if len(sys.argv) == 3 and sys.argv[1] == "--base64":
    65 if len(sys.argv) == 3 and sys.argv[1] == "--base64":
    73     ruleset.rules.set(user = base64.b64decode(sys.argv[2]))
    66     ruleset.rules.set(user = base64.b64decode(sys.argv[2]))
    74 elif len(sys.argv) == 2:
    67 elif len(sys.argv) == 2:
    75     ruleset.rules.set(user = sys.argv[1])
    68     ruleset.rules.set(user = sys.argv[1])
    76 else:
    69 else:
    77     fail("hg-ssh wrongly called, is authorized_keys corrupt? (%s)" 
    70     fail("hg-ssh wrongly called, is authorized_keys corrupt? (%s)" 
    78         % sys.argv)
    71         % sys.argv)
    79 
       
    80 for k,v in config.getEnv():
       
    81     os.environ[k] = v
       
    82 
    72 
    83 os.chdir(config.getReposPath())
    73 os.chdir(config.getReposPath())
    84 
    74 
    85 for f in config.getAccessPaths():
    75 for f in config.getAccessPaths():
    86     if os.path.isfile(f):
    76     if os.path.isfile(f):