chpwd, userv.rc: Change Userv service protocol to parse options properly.
authorMark Wooding <mdw@distorted.org.uk>
Mon, 22 Dec 2014 20:32:58 +0000 (20:32 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Tue, 7 Apr 2015 10:43:30 +0000 (11:43 +0100)
Options passed apparently to the service were actually being handled at
top level, so you got the wrong help text if you said `userv chpwd list
-h', for example.  This is very bad.

To fix this, we require the userv configuration to provide an explicit
non-option token to terminate top-level option handling at the right
time.

chpwd
userv.rc

diff --git a/chpwd b/chpwd
index 9f483de..b4fc8f5 100755 (executable)
--- a/chpwd
+++ b/chpwd
@@ -218,11 +218,13 @@ if __name__ == '__main__':
 
     with cli_errors():
       OPTS, args = OPTPARSE.parse_args()
+      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()):
-        OPTPARSE.dispatch('userv', [ENV['USERV_SERVICE']] + args)
+        OPTPARSE.dispatch('userv', [ENV['USERV_SERVICE']] + args[1:])
 
   elif 'SSH_ORIGINAL_COMMAND' in ENV:
     ## This looks like an SSH request; but we present two different
index 842940e..b062366 100644 (file)
--- a/userv.rc
+++ b/userv.rc
@@ -1,9 +1,7 @@
 ### -*-conf-*-
 
-if ( glob service help list source set reset clear
-   & grep service-user-shell /etc/shells
-   )
+if grep service-user-shell /etc/shells
        no-suppress-args
        no-set-environment
-       execute ./chpwd
+       execute ./chpwd userv
 fi