Declaring command parameters optional

David Giese dggiese at uswest.net
Wed Oct 11 18:16:11 EDT 2000


I'm having trouble figuring out how to use sudo's wildcards to make
parameters to a command optional.  For example the su command has
parameters:

su [ - ] [ username [arg... ] ]

so it could be something simple like:

su nobody

or it could be something like:

su - nobody -c "/opt/local/apache/bin/apachectl start"

I could write:

Cmnd_Alias SU=/usr/bin/su nobody, \
              /usr/bin/su - nobody, \
              /usr/bin/su - nobody -c [A-z]*

but I would prefer to simplify this by using wildcards.

My understanding from the documentation is the the '?' symbol matches
any set of zero or more characters.  If this is true I would expect
that:

Cmnd_Alias SU=/usr/bin/su ? nobody

would allow both 'sudo su nobody' and 'sudo su - nobody' to work, but
instead 'sudo su - nobody' works but 'sudo su nobody' does not work.  If
'?' can match zero characters why is sudo requiring that at least 1
character be present to execute the command?  

It seems that '*' works similarily.  The documentation says that when
using '*', the preceeding symbol may appear zero or more times, but if I
use something like:

Cmnd_Alias SU=/usr/bin/su [-]* nobody

I get the same results, 'sudo su - nobody' works but 'sudo su nobody'
does not work.  If '*' states that the preceeding symbol may appear zero
or more times why does sudo require there to be a '-' character when
executing the command?

Does anyone know how to structure the Cmnd_Alias so that parameters can
be made optional?

Thanks,
David



More information about the sudo-users mailing list