chiark / gitweb /
Makefile: Add `dist' target.
[chopwood] / chpwd
diff --git a/chpwd b/chpwd
index 5925dddce89e6f52cb7fe10964c52a8cd53df689..9f483deb6877e3a77b3fcc7fae3c93f49736852e 100755 (executable)
--- a/chpwd
+++ b/chpwd
@@ -30,6 +30,7 @@ import optparse as OP
 import os as OS; ENV = OS.environ
 import shlex as SL
 import sys as SYS
+import syslog as L
 
 from auto import HOME, VERSION
 import cgi as CGI
@@ -38,6 +39,7 @@ import config as CONF; CFG = CONF.CFG
 import dbmaint as D
 import httpauth as HA
 import output as O; OUT = O.OUT
+import service as S
 import subcommand as SC
 import util as U
 
@@ -71,7 +73,8 @@ for short, long, props in [
     'help': 'run commands with the given CONTEXT' }),
   ('-f', '--config-file', {
     'metavar': 'FILE', 'dest': 'config',
-    'default': OS.path.join(HOME, 'chpwd.conf'),
+    'default': ENV.get('CHPWD_CONFIG',
+                       OS.path.join(HOME, 'chpwd.conf')),
     'help': 'read configuration from FILE.' }),
   ('-s', '--ssl', {
     'dest': 'sslp', 'action': 'store_true',
@@ -198,12 +201,16 @@ def cli_errors():
 
 if __name__ == '__main__':
 
+  L.openlog(OS.path.basename(SYS.argv[0]), 0, L.LOG_AUTH)
+
   if 'REQUEST_METHOD' in ENV:
     ## This looks like a CGI request.  The heavy lifting for authentication
     ## over HTTP is done in `dispatch_cgi'.
 
     with OUT.redirect_to(CGI.HTTPOutput()):
-      with CGI.cgi_errors(cgi_setup): dispatch_cgi()
+      with U.Escape() as CGI.HEADER_DONE:
+        with CGI.cgi_errors(cgi_setup):
+          dispatch_cgi()
 
   elif 'USERV_SERVICE' in ENV:
     ## This is a Userv request.  The caller's user name is helpfully in the
@@ -228,7 +235,7 @@ if __name__ == '__main__':
       OPTS, args = OPTPARSE.parse_args()
       CONF.loadconfig(OPTS.config)
       cmd = SL.split(ENV['SSH_ORIGINAL_COMMAND'])
-      if args: raise ExpectedError, (500, 'Unexpected arguments via SSH')
+      if args: raise U.ExpectedError, (500, 'Unexpected arguments via SSH')
       return cmd
 
     if 'CHPWD_SSH_USER' in ENV:
@@ -238,7 +245,6 @@ if __name__ == '__main__':
       with cli_errors():
         cmd = ssh_setup()
         CU.set_user(ENV['CHPWD_SSH_USER'])
-        SERVICES['master'].find(USER)
         with OUT.redirect_to(O.FileOutput()):
           OPTPARSE.dispatch('userv', cmd)
 
@@ -251,8 +257,8 @@ if __name__ == '__main__':
       try:
         cmd = ssh_setup()
         with OUT.redirect_to(O.RemoteOutput()):
-          OPTPARSE.dispatch('remote', map(urldecode, cmd))
-      except ExpectedError, e:
+          OPTPARSE.dispatch('remote', map(CGI.urldecode, cmd))
+      except U.ExpectedError, e:
         print 'ERR', e.code, e.msg
       else:
         print 'OK'
@@ -262,7 +268,7 @@ if __name__ == '__main__':
       ## file, but we can't do much about it from here.
 
       with cli_errors():
-        raise ExpectedError, (400, "Unabled to determine SSH context")
+        raise U.ExpectedError, (400, "Unabled to determine SSH context")
 
   else:
     ## Plain old command line, apparently.  We default to administration
@@ -277,6 +283,7 @@ if __name__ == '__main__':
       ctx = OPTS.context
       if OPTS.user:
         CU.set_user(OPTS.user)
+        CGI.STATE.kw['user'] = OPTS.user
         if ctx is None: ctx = 'userv'
       else:
         D.opendb()