Browse Source

Improved device detection: use storage device instead of usb device

master
Andrea Luzzardi 17 years ago
parent
commit
40aad41b43
3 changed files with 31 additions and 31 deletions
  1. +17
    -7
      pam_usb/src/device.c
  2. +3
    -3
      pam_usb/tools/pamusb-agent
  3. +11
    -21
      pam_usb/tools/pamusb-conf

+ 17
- 7
pam_usb/src/device.c View File

@ -32,15 +32,25 @@ static int pusb_device_connected(t_pusb_options *opts, LibHalContext *ctx)
log_debug("Searching for \"%s\" in the hardware database...\n",
opts->device.name);
udi = pusb_hal_find_item(ctx,
"usb_device.serial", opts->device.serial,
"usb_device.vendor", opts->device.vendor,
"info.product", opts->device.model,
NULL);
"storage.serial", opts->device.serial,
"storage.vendor", opts->device.vendor,
"info.product", opts->device.model);
if (!udi)
{
log_error("Device \"%s\" is not connected.\n",
opts->device.name);
return (0);
/* Backward compatibility with older versions (0.4.1) */
udi = pusb_hal_find_item(ctx,
"usb_device.serial", opts->device.serial,
"usb_device.vendor", opts->device.vendor,
"info.product", opts->device.model,
NULL);
if (!udi)
{
log_error("Device \"%s\" is not connected.\n",
opts->device.name);
return (0);
}
log_error("Warning: The configuration file has been " \
"generated by an older version of pamusb-conf\n");
}
libhal_free_string(udi);
log_info("Device \"%s\" is connected (good).\n", opts->device.name);


+ 3
- 3
pam_usb/tools/pamusb-agent View File

@ -56,7 +56,7 @@ class HotPlugDevice:
halService = self.__bus.get_object('org.freedesktop.Hal',
'/org/freedesktop/Hal/Manager')
halManager = dbus.Interface(halService, 'org.freedesktop.Hal.Manager')
for udi in halManager.FindDeviceStringMatch('info.bus', 'usb_device'):
for udi in halManager.FindDeviceByCapability('storage'):
self.__deviceAdded(udi)
def __registerSignals(self):
@ -75,9 +75,9 @@ class HotPlugDevice:
udi)
deviceProperties = deviceObj.GetAllProperties(
dbus_interface = 'org.freedesktop.Hal.Device')
if not deviceProperties.has_key('usb_device.serial'):
if not deviceProperties.has_key('storage.serial'):
return
if deviceProperties['usb_device.serial'] != self.__serial:
if deviceProperties['storage.serial'] != self.__serial:
return
self.__udi = udi
if self.__running:


+ 11
- 21
pam_usb/tools/pamusb-conf View File

@ -28,27 +28,14 @@ class Device:
udi)
deviceProperties = deviceObj.GetAllProperties(
dbus_interface = 'org.freedesktop.Hal.Device')
self.vendor = deviceProperties['usb_device.vendor']
self.product = deviceProperties['info.product']
self.serialNumber = deviceProperties['usb_device.serial']
if deviceProperties['storage.removable'] != 1:
raise Exception, 'Not a removable device'
self.vendor = deviceProperties['info.vendor']
self.product = deviceProperties['storage.model']
self.serialNumber = deviceProperties['storage.serial']
if len(self.volumes()) < 1:
raise Exception, 'Device does not contain any volume'
def __isChildOfDevice(self, udi):
obj = bus.get_object('org.freedesktop.Hal', udi)
properties = obj.GetAllProperties(
dbus_interface = 'org.freedesktop.Hal.Device')
if not properties.has_key('info.parent'):
return False
if properties.has_key('info.bus') and properties['info.bus'] == 'usb_device':
return False
if properties['info.parent'] == self.__udi:
return True
return self.__isChildOfDevice(properties['info.parent'])
def __repr__(self):
return "%s %s (%s)" % (self.vendor, self.product, self.serialNumber)
def volumes(self):
vols = []
for volume in halManager.FindDeviceByCapability('volume'):
@ -56,14 +43,17 @@ class Device:
volume)
deviceProperties = deviceObj.GetAllProperties(
dbus_interface = 'org.freedesktop.Hal.Device')
if deviceProperties['block.major'] != 8:
if deviceProperties['info.parent'] != self.__udi:
continue
if not self.__isChildOfDevice(volume):
if deviceProperties['volume.is_partition'] != True:
continue
vols.append({'uuid' : deviceProperties['volume.uuid'],
'device' : deviceProperties['block.device']})
return vols
def __repr__(self):
return "%s %s (%s)" % (self.vendor, self.product, self.serialNumber)
def listOptions(question, options, autodetect = True):
if autodetect == True and len(options) == 1:
print question
@ -151,7 +141,7 @@ def addUser(options):
def addDevice(options):
devices = []
for udi in halManager.FindDeviceStringMatch('info.bus', 'usb_device'):
for udi in halManager.FindDeviceByCapability('storage'):
try:
if options['verbose']:
print 'Inspecting %s' % udi


Loading…
Cancel
Save