--- a/src/hg-ssh Fri Mar 06 13:06:36 2009 +0000
+++ b/src/hg-ssh Fri Mar 06 13:26:35 2009 +0000
@@ -48,17 +48,17 @@
fail("Disallowing path: %s" % path)
return path
-def try_cmd(rules, cmd):
+def try_cmd(cmd):
if cmd.startswith('hg -R ') and cmd.endswith(' serve --stdio'):
repo = getpath(cmd[6:-14])
- if rules.allow("read", repo=repo):
- os.environ["HG_REPO_PATH"] = repo
+ ruleset.rules.set(repo=repo)
+ if ruleset.rules.allow("read", branch=None, file=None):
dispatch.dispatch(['-R', repo, 'serve', '--stdio'])
return
elif cmd.startswith('hg init '):
repo = getpath(cmd[8:])
- if rules.allow("init", repo=repo):
- os.environ["HG_REPO_PATH"] = repo
+ ruleset.rules.set(repo=repo)
+ if ruleset.rules.allow("init", branch=None, file=None):
dispatch.dispatch(['init', repo])
return
fail("Illegal command %r" % cmd)
@@ -80,11 +80,11 @@
os.chdir('repos')
-os.environ['HG_ACCESS_RULES_PATH'] = (
- paths.getEtcPath() + "/access.conf" + ":" +
- os.getcwd() + "/hgadmin/access.conf")
+for f in [
+ paths.getEtcPath() + "/access.conf",
+ os.getcwd() + "/hgadmin/access.conf"]:
+ if os.path.isfile(f):
+ ruleset.rules.readfile(f)
-rules = ruleset.rules_from_env()
-rules.set(user = getpath(remote_user))
-rules.set(branch = None, file = None)
-try_cmd(rules, os.environ.get('SSH_ORIGINAL_COMMAND', '?'))
+ruleset.rules.set(user = getpath(remote_user))
+try_cmd(os.environ.get('SSH_ORIGINAL_COMMAND', '?'))
--- a/src/mercurialserver/access.py Fri Mar 06 13:06:36 2009 +0000
+++ b/src/mercurialserver/access.py Fri Mar 06 13:26:35 2009 +0000
@@ -23,16 +23,12 @@
self.ui = ui
self.repo = repo
- self.rules = ruleset.rules_from_env()
- self.rules.set(user = os.environ['REMOTE_USER'])
- self.rules.set(repo = os.environ['HG_REPO_PATH'])
-
def allow(self, ctx):
branch = ctx.branch()
- if not self.rules.allow("write", branch=branch, file=None):
+ if not ruleset.rules.allow("write", branch=branch, file=None):
return False
for f in ctx.files():
- if not self.rules.allow("write", branch=branch, file=f):
+ if not ruleset.rules.allow("write", branch=branch, file=f):
return False
return True
--- a/src/mercurialserver/ruleset.py Fri Mar 06 13:06:36 2009 +0000
+++ b/src/mercurialserver/ruleset.py Fri Mar 06 13:26:35 2009 +0000
@@ -88,9 +88,5 @@
except Exception, e:
print >> sys.stderr, "Failure reading rules file:", e
-def rules_from_env():
- res = Ruleset()
- for f in os.environ['HG_ACCESS_RULES_PATH'].split(os.pathsep):
- if os.path.isfile(f):
- res.readfile(f)
- return res
+rules = Ruleset()
+