Merge 7a1d6b228af6 default tip
authorMahlon E. Smith <mahlon@martini.nu>
Wed, 31 Oct 2018 13:22:13 -0700
changeset 378 a788cfad4cfa
parent 377 18869fcfbc92 (current diff)
parent 374 7a1d6b228af6 (diff)
Merge 7a1d6b228af6
--- a/doc/manual.docbook	Wed Oct 31 13:21:37 2018 -0700
+++ b/doc/manual.docbook	Wed Oct 31 13:22:13 2018 -0700
@@ -591,6 +591,15 @@
 </itemizedlist>
 </listitem>
 <listitem>
+<para><literal>[users]</literal></para>
+<itemizedlist>
+<listitem>
+<para><literal>index</literal>: the index of the key path that contains the
+user login.  If <literal>-1</literal>, the full path is used.</para>
+</listitem>
+</itemizedlist>
+</listitem>
+<listitem>
 <para><literal>[env]</literal>: all entries in here are added to the Unix environment
 when users connect.  The keys are converted to all-upper-case. </para>
 <itemizedlist>
--- a/src/hg-ssh	Wed Oct 31 13:21:37 2018 -0700
+++ b/src/hg-ssh	Wed Oct 31 13:22:13 2018 -0700
@@ -38,13 +38,26 @@
     os.environ[k.upper()] = v
 
 if len(sys.argv) == 3 and sys.argv[1] == "--base64":
-    ruleset.rules.set(user = base64.b64decode(sys.argv[2]))
+    user = base64.b64decode(sys.argv[2])
+    ruleset.rules.set(user = user)
 elif len(sys.argv) == 2:
-    ruleset.rules.set(user = sys.argv[1])
+    user = sys.argv[1]
+    ruleset.rules.set(user = user)
 else:
     fail("hg-ssh wrongly called, is authorized_keys corrupt? (%s)"
         % sys.argv)
 
+paths = []
+path = user
+while path:
+    path, tail = os.path.split(path)
+    paths.append(tail)
+paths.reverse()
+i = config.getUserPathIndex()
+if i >= 0 and i < len(paths):
+    user = paths[i]
+os.environ['LOGNAME'] = user
+
 os.chdir(config.getReposPath())
 
 for f in config.getAccessPaths():
--- a/src/mercurialserver/config.py	Wed Oct 31 13:21:37 2018 -0700
+++ b/src/mercurialserver/config.py	Wed Oct 31 13:22:13 2018 -0700
@@ -51,6 +51,9 @@
     return _getdefault("exceptions", "allowdots", [],
         lambda s: s.split(":"))
 
+def getUserPathIndex():
+    return _getdefault("users", "index", -1, int)
+
 # Work out where we are, don't use config.
 def initExe():
     global _exePath