# HG changeset patch # User Paul Crowley # Date 1236419701 0 # Node ID 78777f5093033a58a6e6be3391d52257519def8d # Parent 80fa761c7f5d2ac9bc522465c2b4701c7d182e4d Move check for hg user where it belongs diff -r 80fa761c7f5d -r 78777f509303 src/mercurialserver/refreshauth.py --- 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) diff -r 80fa761c7f5d -r 78777f509303 src/refresh-auth --- a/src/refresh-auth Sat Mar 07 09:48:10 2009 +0000 +++ b/src/refresh-auth Sat Mar 07 09:55:01 2009 +0000 @@ -7,12 +7,20 @@ # WARNING import sys +import os +import pwd from mercurialserver import refreshauth, paths if len(sys.argv) != 1: sys.stderr.write("refresh-auth: must be called with no arguments (%s)\n" % sys.argv) sys.exit(-1) +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) + paths.setExePath() -refreshauth.refreshAuth() +refreshauth.refreshAuth(pentry.pw_dir)