From owner-freebsd-bugs@FreeBSD.ORG Tue Jan 6 19:21:25 2009 Return-Path: Delivered-To: freebsd-bugs@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 80D271065676; Tue, 6 Jan 2009 19:21:25 +0000 (UTC) (envelope-from yanefbsd@gmail.com) Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.171]) by mx1.freebsd.org (Postfix) with ESMTP id D25F48FC13; Tue, 6 Jan 2009 19:21:24 +0000 (UTC) (envelope-from yanefbsd@gmail.com) Received: by ug-out-1314.google.com with SMTP id 30so1352836ugs.39 for ; Tue, 06 Jan 2009 11:21:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:cc:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=v1L03b++FmeTOswSQuI+MFQPeTdmitGDEpfhOyyUOZ4=; b=n1sI2RmFAo2zsMaay1AiFaNgg12JzlLH4X1hXb5mPaa+9wBwkuVx4ZHHe9C0R2Rgwm a3i3M8WwkkI1PHv208IgdfTqeIKo6q8FJNO1feV9AfwTjfpZw6iFGl7tU+PwzyvqiKUY 9qKdpHFPIFDpx392xnky+10RRQgmZX3925PSY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=LxcQddV41ECrahnpIt0OAvdc5PK/VPV78kfyKmJzl0wg5HDGnhosaVC4CyFwMxZtSq +hdMnwqQUIihIptUMivecGTsH6y8LPGqVg9x0RCx2iVT2MF8dBjSyYW6mY1k31lRzk5b hsV4GH18LorqX/m4BWgGiCrWc4ZLrQsSXGMCc= Received: by 10.67.115.16 with SMTP id s16mr13472658ugm.47.1231269683507; Tue, 06 Jan 2009 11:21:23 -0800 (PST) Received: by 10.67.88.9 with HTTP; Tue, 6 Jan 2009 11:21:23 -0800 (PST) Message-ID: <7d6fde3d0901061121q7b04c199mc0ba7228b148840b@mail.gmail.com> Date: Tue, 6 Jan 2009 11:21:23 -0800 From: "Garrett Cooper" To: "M. Warner Losh" In-Reply-To: <20090106.121521.2007157328.imp@bsdimp.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <495FAFDD.2050206@vwsoft.com> <200901061932.54448.hselasky@c2i.net> <7d6fde3d0901061110r79333a07jf4eb134224a94747@mail.gmail.com> <20090106.121521.2007157328.imp@bsdimp.com> Cc: volker@vwsoft.com, freebsd-bugs@freebsd.org, freebsd-usb@freebsd.org, hselasky@c2i.net Subject: Re: bin/129963: [newusb] usbconfig(8) fails with misleading error when run as a normal user X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Jan 2009 19:21:26 -0000 On Tue, Jan 6, 2009 at 11:15 AM, M. Warner Losh wrote: > In message: <7d6fde3d0901061110r79333a07jf4eb134224a94747@mail.gmail.com> > "Garrett Cooper" writes: > : On Tue, Jan 6, 2009 at 10:32 AM, Hans Petter Selasky wrote: > : > On Saturday 03 January 2009, Volker wrote: > : >> On 01/03/09 01:35, Hans Petter Selasky wrote: > : >> > On Wednesday 31 December 2008, vwe@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. > : > : 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"); > : } > : > : 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? > > Do you really have to be root to find the devices, if so, that's bad. > Very bad. xsane refuses to run as root. I have: > > [localrules=10] > add path 'uscanner*' mode 0660 > > to make it work. /dev/usb* in old usb allow listing w/o privs... > > Warner Hence that's why I provided another hacked solution. I hate `can't run this app unless root' because it doesn't accurately solve the problem, but it makes the issue more straightforward than `no devices' :). Personally I think using errno and strerror when trying to open / read devices would be a lot cleaner. Let me see what I can quickly grok from libusb(3) either tonight or tomorrow that might be an improvement.. -Garrett