chiark
/
gitweb
/
~mdw
/
chopwood
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
cmd-cgi.py: Don't allow caching of the `list' page.
[chopwood]
/
chpwd
diff --git
a/chpwd
b/chpwd
index 1e4248b7f075be7cd295f209cdc583ad18527458..65ae8739ea2ac86fb4635658e68c75602191c6d4 100755
(executable)
--- a/
chpwd
+++ b/
chpwd
@@
-38,6
+38,7
@@
import config as CONF; CFG = CONF.CFG
import dbmaint as D
import httpauth as HA
import output as O; OUT = O.OUT
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
import subcommand as SC
import util as U
@@
-71,7
+72,8
@@
for short, long, props in [
'help': 'run commands with the given CONTEXT' }),
('-f', '--config-file', {
'metavar': 'FILE', 'dest': 'config',
'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': 'read configuration from FILE.' }),
('-s', '--ssl', {
'dest': 'sslp', 'action': 'store_true',
@@
-87,6
+89,7
@@
for short, long, props in [
## The special variables, to be picked out by `cgiparse'.
CGI.SPECIAL['%act'] = None
CGI.SPECIAL['%nonce'] = None
## 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
## 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
@@
-143,6
+146,14
@@
def dispatch_cgi():
## `cgi-noauth'.
if ctx != 'cgi-noauth':
## `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:
## If there's no token cookie, then we have to bail.
try: token = CGI.COOKIE['chpwd-token']
except KeyError:
@@
-166,6
+177,8
@@
def dispatch_cgi():
except HA.AuthenticationFailed, e:
CGI.redirect(CGI.action('login', why = e.why))
return
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:])
## Invoke the subcommand handler.
c.cgi(CGI.PARAM, CGI.PATH[i:])
@@
-217,7
+230,7
@@
if __name__ == '__main__':
OPTS, args = OPTPARSE.parse_args()
CONF.loadconfig(OPTS.config)
cmd = SL.split(ENV['SSH_ORIGINAL_COMMAND'])
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:
return cmd
if 'CHPWD_SSH_USER' in ENV:
@@
-227,7
+240,7
@@
if __name__ == '__main__':
with cli_errors():
cmd = ssh_setup()
CU.set_user(ENV['CHPWD_SSH_USER'])
with cli_errors():
cmd = ssh_setup()
CU.set_user(ENV['CHPWD_SSH_USER'])
- S
ERVICES['master'].find(
USER)
+ S
.SERVICES['master'].find(CU.
USER)
with OUT.redirect_to(O.FileOutput()):
OPTPARSE.dispatch('userv', cmd)
with OUT.redirect_to(O.FileOutput()):
OPTPARSE.dispatch('userv', cmd)
@@
-240,8
+253,8
@@
if __name__ == '__main__':
try:
cmd = ssh_setup()
with OUT.redirect_to(O.RemoteOutput()):
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'
print 'ERR', e.code, e.msg
else:
print 'OK'
@@
-251,7
+264,7
@@
if __name__ == '__main__':
## file, but we can't do much about it from here.
with cli_errors():
## 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
else:
## Plain old command line, apparently. We default to administration
@@
-266,6
+279,7
@@
if __name__ == '__main__':
ctx = OPTS.context
if OPTS.user:
CU.set_user(OPTS.user)
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()
if ctx is None: ctx = 'userv'
else:
D.opendb()