Bart Blanquart wrote: > On 02/19/09 18:25, Glenn Faden wrote: >> This looks good to me. It probably could have been coded differently >> using getopt, but since that wasn't used in the original code, I think >> your changes are acceptable. > > I originally coded it using getopt, but that fails to handle "auths -ab > username" correctly, as it can't tell if the "b" is the argument to "-a" > or a (non-existant) option.
This is a significant issue. Whether or not you use getopt() in the implementation, the command syntax should be getopt-compliant. In other words, the example above should check if the user has the authorization called "b". The easiest way to achieve getopt-compliance, of course, is to use getopt(). > > This also meant it becomes tricky to handle "auths -asolaris.something > username" correctly: the switch(argc) would fall to the wrong case (as > argc==3 but it should fall to case 4). That's why you want to use optind to decrement argc and increment argv *after* you call getopt(). That way you get correct results with or without the space between the option and argument. > > If there's an easy way to handle this I can swap out lines 82-92 for a > getopt based command line parser (and update 93-99 to match). > > Bart I didn't review your code; my comments are based on the email thread. But I'm 99% sure you should be using getopt(). Scott -- Scott Rotondo Principal Engineer, Solaris Security Technologies President, Trusted Computing Group Phone/FAX: +1 408 850 3655 (Internal x68278)