X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/chopwood/blobdiff_plain/a2916c0635fec5b45ad742904db9f5769b48f53d..2a875c57bf6b595d9efc776d698b348e8befdd8d:/chpwd diff --git a/chpwd b/chpwd index 5517274..4d70fa8 100755 --- a/chpwd +++ b/chpwd @@ -71,8 +71,12 @@ 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', + 'help': 'pretend CGI connection is carried over SSL/TLS' }), ('-u', '--user', { 'metavar': 'USER', 'dest': 'user', 'default': None, 'help': "impersonate USER, and default context to `userv'." })]: @@ -84,6 +88,7 @@ for short, long, props in [ ## The special variables, to be picked out by `cgiparse'. CGI.SPECIAL['%act'] = None CGI.SPECIAL['%nonce'] = None +CGI.SPECIAL['%user'] = None ## We don't want to parse arguments until we've settled on a context; but ## issuing redirects in the early setup phase fails because we don't know @@ -140,6 +145,14 @@ def dispatch_cgi(): ## `cgi-noauth'. if ctx != 'cgi-noauth': + ## The next part of the URL should be the user name, so that caches don't + ## cross things over. + expuser = CGI.SPECIAL['%user'] + if expuser is None: + if i >= np: raise U.ExpectedError, (404, 'Missing user name') + expuser = CGI.PATH[i] + i += 1 + ## If there's no token cookie, then we have to bail. try: token = CGI.COOKIE['chpwd-token'] except KeyError: @@ -163,6 +176,8 @@ def dispatch_cgi(): except HA.AuthenticationFailed, e: CGI.redirect(CGI.action('login', why = e.why)) return + if CU.USER != expuser: raise U.ExpectedError, (401, 'User mismatch') + CGI.STATE.kw['user'] = CU.USER ## Invoke the subcommand handler. c.cgi(CGI.PARAM, CGI.PATH[i:]) @@ -259,6 +274,7 @@ if __name__ == '__main__': with cli_errors(): OPTS, args = OPTPARSE.parse_args() CONF.loadconfig(OPTS.config) + CGI.SSLP = OPTS.sslp ctx = OPTS.context if OPTS.user: CU.set_user(OPTS.user)