X-Git-Url: https://git.distorted.org.uk/~mdw/chopwood/blobdiff_plain/e3295bed428adbf5e1863f2d9395adac33dbb071..HEAD:/chpwd diff --git a/chpwd b/chpwd index 07fe830..2d6c75c 100755 --- a/chpwd +++ b/chpwd @@ -76,6 +76,9 @@ for short, long, props in [ 'default': ENV.get('CHPWD_CONFIG', OS.path.join(HOME, 'chpwd.conf')), 'help': 'read configuration from FILE.' }), + ('-i', '--ignore-policy', { + 'dest': 'ignpol', 'default': False, 'action': 'store_true', + 'help': 'ignore the operation policy (for administrators)' }), ('-s', '--ssl', { 'dest': 'sslp', 'action': 'store_true', 'help': 'pretend CGI connection is carried over SSL/TLS' }), @@ -91,6 +94,7 @@ def parse_options(): global OPTS OPTS, args = OPTPARSE.parse_args() OPTPARSE.show_global_opts = False + CFG.OPTS = OPTS ## It's tempting to load the configuration here. Don't do that. Some ## contexts will want to check that the command line was handled properly ## upstream before believing it for anything, such as executing arbitrary @@ -229,13 +233,13 @@ if __name__ == '__main__': ## `USERV_USER' environment variable. with cli_errors(): - args = parse_options() - if not args or args[0] != 'userv': - raise U.ExpectedError, (500, 'missing userv token') - CONF.loadconfig(OPTS.config) - try: CU.set_user(ENV['USERV_USER']) - except KeyError: raise ExpectedError, (500, 'USERV_USER unset') with OUT.redirect_to(O.FileOutput()): + args = parse_options() + if not args or args[0] != 'userv': + raise U.ExpectedError, (500, 'missing userv token') + CONF.loadconfig(OPTS.config) + try: CU.set_user(ENV['USERV_USER']) + except KeyError: raise ExpectedError, (500, 'USERV_USER unset') OPTPARSE.dispatch('userv', [ENV['USERV_SERVICE']] + args[1:]) elif 'SSH_ORIGINAL_COMMAND' in ENV: @@ -256,9 +260,9 @@ if __name__ == '__main__': ## of telling us that this is a user request, so treat it like Userv. with cli_errors(): - cmd = ssh_setup() - CU.set_user(ENV['CHPWD_SSH_USER']) with OUT.redirect_to(O.FileOutput()): + cmd = ssh_setup() + CU.set_user(ENV['CHPWD_SSH_USER']) OPTPARSE.dispatch('userv', cmd) elif 'CHPWD_SSH_MASTER' in ENV: @@ -268,8 +272,8 @@ if __name__ == '__main__': ## a user. try: - cmd = ssh_setup() with OUT.redirect_to(O.RemoteOutput()): + cmd = ssh_setup() OPTPARSE.dispatch('remote', map(CGI.urldecode, cmd)) except U.ExpectedError, e: print 'ERR', e.code, e.msg @@ -290,20 +294,20 @@ if __name__ == '__main__': ## as we are. with cli_errors(): - args = parse_options() - CONF.loadconfig(OPTS.config) - CGI.SSLP = OPTS.sslp - 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 = 'admin' - OPTPARSE.show_global_opts = True with OUT.redirect_to(O.FileOutput()): + args = parse_options() + CONF.loadconfig(OPTS.config) + CGI.SSLP = OPTS.sslp + 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 = 'admin' + OPTPARSE.show_global_opts = True OPTPARSE.dispatch(ctx, args) ###----- That's all, folks --------------------------------------------------