src/mercurialserver/refreshauth.py
changeset 86 78777f509303
parent 85 80fa761c7f5d
child 106 0519745e7a57
--- a/src/mercurialserver/refreshauth.py	Sat Mar 07 09:48:10 2009 +0000
+++ b/src/mercurialserver/refreshauth.py	Sat Mar 07 09:55:01 2009 +0000
@@ -12,16 +12,10 @@
 import subprocess
 from mercurialserver import ruleset, paths
 
-def refreshAuth():
-    pentry = pwd.getpwuid(os.geteuid())
-    if pentry.pw_name != "hg":
-        # FIXME: re-execute
-        print >>sys.stderr, "Must be run as the 'hg' user"
-        sys.exit(-1)
-
-    akeyfile = pentry.pw_dir + "/.ssh/authorized_keys"
+def refreshAuth(pw_dir):
+    akeyfile = pw_dir + "/.ssh/authorized_keys"
     wrappercommand = paths.getExePath() + "/hg-ssh"
-    keydirs = [paths.getEtcPath() + "/keys", pentry.pw_dir + "/repos/hgadmin/keys"]
+    keydirs = [paths.getEtcPath() + "/keys", pw_dir + "/repos/hgadmin/keys"]
     prefix='no-pty,no-port-forwarding,no-X11-forwarding,no-agent-forwarding,command='
 
     if os.path.exists(akeyfile):
@@ -63,11 +57,10 @@
                 for l in klines:
                     if len(l):
                         akeys.write('%s"%s %s" %s\n' % (prefix, wrappercommand, keyname, l))
-
     akeys.close()
-
     os.rename(akeyfile + "_new", akeyfile)
     
 def hook(ui, repo, hooktype, node=None, source=None, **kwargs):
-    refreshAuth()
+    pentry = pwd.getpwuid(os.geteuid())
+    refreshAuth(pentry.pw_dir)