Hi -

I've been arguing with my 1-Wire USB controller once again and
hopefully I'll win this time ;-)

I generally run OW code from a non-root account to help prevent run
away problems crashing or corrupting the system. Unfortunately,
whenever a 1-Wire USB controller is connected to the system, root is
the only account with read and write access. So I use the Linux
Hotplug subsystem to fix that.

I've written up a preliminary guide to extending the hotplug subsystem
to automatically change the file owner and permissions on 1-Wire
controller. It's attached here for review by the rest of the
developers and community. I'd like to get some feedback and see if we
can figure out a good place for this to live. Hopefully it'll provide
some help to people setting up 1-Wire USB controllers on a Linux based
system.

Comments? Thought?

- Peter
Overview
========

There are times when access to the 1-Wire USB controller has to be
modified to allow a user other than root to have write access. This
article presents a simple way to use the Linux Hotplug subsystem to
change the file ownership and permissions on the file associated with
a 1-Wire controller.


Linux Hotplug Subsystem
-----------------------

The notes presented here are specific to the Linux Hotplug subsystem
and it must be installed for it to work. To install it on a Debian
based system:

    apt-get install hotplug

If you're running a version of Linux other than Debian, see the
documentation for that version Linux for more details on how to
install the Hotplug subsystem.


USB Vendor and Product IDs
--------------------------

The USB vendor and product ids are used by the Hotplug subsystem to
identify which program is to be run when the device is plugged in.

If you don't know the vendor and product ids for the 1-Wire USB
controller you'll be using, you can use the lsusb program to find
them. If lsusb isn't installed (typically in /usr/sbin) you'll need to
install the appropiate package for your Linux distribution. On Debian
systems, that means installing the usbutils package.

    apt-get install usbutils

Once installed, run lsusb with the 1-Wire USB controlled plugged in:

    $ /usr/sbin/lsusb
    Bus 003 Device 001: ID 0000:0000  
    Bus 002 Device 013: ID 04fa:2490 Dallas Semiconductor DS1490F 2-in-1 Fob, 
1-Wire adapter
    Bus 002 Device 001: ID 0000:0000  
    Bus 001 Device 001: ID 0000:0000  
    $

The 04fa is the vendor id and 2490 is the product id.

Unplug the 1-Wire USB controller.


Customize Hotplug
-----------------

With the vendor and product ids in hand, the Hotplug subsystem can be
modified to change the file permissions and file ownership.

Create a new file called /etc/hotplug/usb/ow.usermap. This will
contain the mapping of vendor / product id and the program to run. The
file should contain a single line that looks like:

    ow        0x03 0x04fa 0x2490 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 
0x00000000

Change the 0x04fa to the vendor id and 0x2490 to the product id for
your 1-Wire USB controller.

Create a new shell program called /etc/hotplug/usb/ow. This will be
the program that is run. Here's a simple example of changing the file
group to ow and giving the group read and write access.


    #! /bin/sh

    if [ "$DEVICE" != "" ]; then
        # we have a device so setup security
        chgrp ow $DEVICE && chmod g+rw $DEVICE && logger "ow hotplug: group set 
to ow and permission g+rw on $DEVICE"
    else
        logger "ow hotplug: error - no device"
    fi


The file has to be made executable via 

    chmod +x /etc/hotplug/usb/ow

otherwise it will not be excuted by the Hotplug subsystem.

Also, don't forget to add a group called ow and add users to the group.

Once this is setup, you can plug the 1-Wire USB controller into the
computer. After a bit, you should see a message in the system log file
that looks like:

    Nov 29 10:06:27 kuro2 logger: ow hotplug: group set to ow and permission 
g+rw on /proc/bus/usb/002/013

and that can be verified by

    $ ls -l /proc/bus/usb/002/013 
    -rw-rw-r-- 1 root ow 147 Nov 29 10:06 /proc/bus/usb/002/013
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Owfs-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/owfs-developers

Reply via email to