bin/129963: [newusb] usbconfig(8) fails with misleading error when run as a normal user

Hans Petter Selasky hselasky at c2i.net
Tue Jan 6 11:16:29 PST 2009


On Tuesday 06 January 2009, Garrett Cooper wrote:
> On Tue, Jan 6, 2009 at 10:32 AM, Hans Petter Selasky <hselasky at c2i.net> 
wrote:
> > On Saturday 03 January 2009, Volker wrote:
> >> On 01/03/09 01:35, Hans Petter Selasky wrote:
> >> > On Wednesday 31 December 2008, vwe at freebsd.org wrote:
> >> >> Synopsis: [newusb] usbconfig(8) fails with misleading error when run
> >> >> as a normal user
> >> >>
> >> >> Responsible-Changed-From-To: freebsd-bugs->freebsd-usb
> >> >> Responsible-Changed-By: vwe
> >> >> Responsible-Changed-When: Wed Dec 31 12:55:52 UTC 2008
> >> >> Responsible-Changed-Why:
> >> >> reassign
> >> >>
> >> >> http://www.freebsd.org/cgi/query-pr.cgi?pr=129963
> >> >
> >> > Hi,
> >> >
> >> > "usbconfig" will only show USB devices which the user has access to.
> >> >
> >> > What should be the correct display message when no devices are
> >> > accessible due to innsufficient permissions?
> >> >
> >> > --HPS
> >>
> >> Hans,
> >>
> >> what about "access denied" or "insufficient privileges"?
> >>
> >> Someone might have a better idea but everything should be better than
> >> silently refusing to do anything.
> >>
> >> Volker
> >
> > Is this Ok:
> >
> > http://perforce.freebsd.org/chv.cgi?CH=155731
> >
> > --HPS
>
> Eh? I still think that strerror or something along those lines would
> be more helpful.

Hi,

If errno != 0, I could print out the current value like a string.

>
> You could also do
>
> if (getuid() != 0) {
>     errx(1, "Cluebat -- you might not be able to read the usb devices
> if you're not root");
> }

Yes, but you are allowed to give non-root users access to USB aswell. So that 
would also be misleading.

Would something like counting the number of devices you don't have access to 
be Ok?

usbconfig
ugenX.Y....
There are xxx USB devices not listed which require root access.

>
> or...
>
> struct stat usb_s;
>
> int fd = open(..., O_RDONLY /* blah, blah... */);
>
> if (fd == -1) {
>     errx(1, "Does the file -- %s -- exist?", file);
> }
>
> if (fstat(fd, &usb_s) == -1) {
>     errx(1, "Couldn't stat the file: %s", file);
> }
>
> if (!S_IRUSR(usb_s.st_mode) && !S_IRGRP(usb_s.st_mode) &&
> !S_IROTH(usb_s.st_mode)) {
>     errx(1, "File not readable (do you have read permissions?)");
> }
>
> /* Continue on merry way reading devices; maybe use strerror(3) for
> more intuitive error messages? */
>
> Thoughts?

It has to fit into libusb20 ... That's all.

--HPS


More information about the freebsd-bugs mailing list