This file is indexed.

/usr/share/checkbox/scripts/hal_resource is in checkbox 0.13.7.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
#!/usr/bin/python
#
# This file is part of Checkbox.
#
# Copyright 2009 Canonical Ltd.
#
# Checkbox is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Checkbox is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Checkbox.  If not, see <http://www.gnu.org/licenses/>.
#
import re
import sys
import dbus
import string
import posixpath

from checkbox.lib.pci import Pci
from checkbox.lib.usb import Usb


class UnknownName(object):
    def __init__(self, function):
        self._function = function

    def __get__(self, instance, cls=None):
        self._instance = instance
        return self

    def __call__(self, *args, **kwargs):
        name = self._function(self._instance, *args, **kwargs)
        if name and name.startswith("Unknown ("):
            name = None

        return name


class DeviceResource(object):
    __slots__ = ("_properties")

    def __init__(self, properties):
        self._properties = properties

    @property
    def bus(self):
        return self._properties.get("linux.subsystem")

    @property
    def category(self):
        if "system.hardware.vendor" in self._properties:
            return "SYSTEM"

        if "net.interface" in self._properties:
            return "NETWORK"

        if "pci.device_class" in self._properties:
            class_id = self._properties["pci.device_class"]
            subclass_id = self._properties["pci.device_subclass"]

            if class_id == Pci.BASE_CLASS_NETWORK:
                return "NETWORK"

            if class_id == Pci.BASE_CLASS_DISPLAY:
                return "VIDEO"

            if class_id == Pci.BASE_CLASS_SERIAL \
               and subclass_id == Pci.CLASS_SERIAL_USB:
                return "USB"

            if class_id == Pci.BASE_CLASS_STORAGE:
                if subclass_id == Pci.CLASS_STORAGE_SCSI:
                    return "SCSI"

                if subclass_id == Pci.CLASS_STORAGE_IDE:
                    return "IDE"

                if subclass_id == Pci.CLASS_STORAGE_FLOPPY:
                    return "FLOPPY"

                if subclass_id == Pci.CLASS_STORAGE_RAID:
                    return "RAID"

            if class_id == Pci.BASE_CLASS_COMMUNICATION \
               and subclass_id == Pci.CLASS_COMMUNICATION_MODEM:
                return "MODEM"

            if class_id == Pci.BASE_CLASS_INPUT \
               and subclass_id == Pci.CLASS_INPUT_SCANNER:
                return "SCANNER"

            if class_id == Pci.BASE_CLASS_MULTIMEDIA:
                if subclass_id == Pci.CLASS_MULTIMEDIA_VIDEO:
                    return "CAPTURE"

                if subclass_id == Pci.CLASS_MULTIMEDIA_AUDIO \
                   or subclass_id == Pci.CLASS_MULTIMEDIA_AUDIO_DEVICE: \
                    return "AUDIO"

            if class_id == Pci.BASE_CLASS_SERIAL \
               and subclass_id == Pci.CLASS_SERIAL_FIREWIRE:
                return "FIREWIRE"

            if class_id == Pci.BASE_CLASS_BRIDGE \
               and (subclass_id == Pci.CLASS_BRIDGE_PCMCIA \
                    or subclass_id == Pci.CLASS_BRIDGE_CARDBUS):
                return "SOCKET"

        if "usb.interface.class" in self._properties:
            interface_class = self._properties["usb.interface.class"]
            interface_subclass = self._properties["usb.interface.subclass"]

            if interface_class == Usb.BASE_CLASS_AUDIO:
                return "AUDIO"

            if interface_class == Usb.BASE_CLASS_PRINTER:
                return "PRINTER"

            if interface_class == Usb.BASE_CLASS_STORAGE:
                if interface_subclass == Usb.CLASS_STORAGE_FLOPPY:
                    return "FLOPPY"

                if interface_subclass == Usb.CLASS_STORAGE_SCSI:
                    return "SCSI"

            if interface_class == Usb.BASE_CLASS_VIDEO:
                return "VIDEO"

            if interface_class == Usb.BASE_CLASS_WIRELESS:
                return "NETWORK"

        if "info.capabilities" in self._properties:
            capabilities = self._properties["info.capabilities"]
            if "input.keyboard" in capabilities:
                return "KEYBOARD"

            if "input.mouse" in capabilities:
                return "MOUSE"

        if "storage.drive_type" in self._properties:
            drive_type = self._properties["storage.drive_type"]
            if drive_type == "cdrom":
                return "CDROM"

            if drive_type == "disk":
                return "DISK"

            if drive_type == "floppy":
                return "FLOPPY"

        if "scsi.type" in self._properties:
            type = self._properties["scsi.type"]
            if type == "disk":
                return "DISK"

            if type == "tape":
                return "TAPE"

            if type == "printer":
                return "PRINTER"

            if type == "cdrom":
                return "CDROM"

            if type == "scanner":
                return "SCANNER"

            if type == "raid":
                return "RAID"

        if self.product_id:
            return "OTHER"

        return None

    @property
    def driver(self):
        return self._properties.get("info.linux.driver")

    @property
    def path(self):
        return self._properties.get("linux.sysfs_path", "").replace("/sys", "")

    @property
    def product_id(self):
        if "info.subsystem" in self._properties:
            product_id = "%s.product_id" % self._properties["info.subsystem"]
            if product_id in self._properties:
                return self._properties[product_id]

        # pnp
        if "pnp.id" in self._properties:
            match = re.match(r"^(?P<vendor_name>.*)(?P<product_id>[%s]{4})$"
                % string.hexdigits, self._properties["pnp.id"])
            if match:
                return int(match.group("product_id"), 16)

        return None

    @property
    def vendor_id(self):
        if "info.subsystem" in self._properties:
            vendor_id = "%s.vendor_id" % self._properties["info.subsystem"]
            if vendor_id in self._properties:
                return self._properties[vendor_id]

        return None

    @property
    def subproduct_id(self):
        return self._properties.get("pci.subsys_product_id")

    @property
    def subvendor_id(self):
        return self._properties.get("pci.subsys_vendor_id")

    @property
    def product(self):
        return self._get_product()

    @UnknownName
    def _get_product(self):
        bus = self.bus

        # Ignore subsystems using parent or generated names
        if bus in ("drm", "net", "pci", "pnp", "scsi_generic",
                   "scsi_host", "tty", "usb", "video4linux"):
            return None

        # Treat the floppy device specifically
        if bus == "platform":
            if self.driver == "floppy":
                return "Platform Device"
            else:
                return None

        if "usb.interface.number" in self._properties:
            return None

        if self._properties.get("info.category") == "ac_adapter":
            return None

        for property in ("alsa.device_id",
                         "alsa.card_id",
                         "sound.card_id",
                         "battery.model",
                         "ieee1394.product",
                         "killswitch.name",
                         "oss.device_id",
                         "scsi.model",
                         "system.hardware.product",
                         "info.product"):
            if property in self._properties:
                return self._properties[property]

        return None

    @property
    def vendor(self):
        return self._get_vendor()

    @UnknownName
    def _get_vendor(self):
        bus = self.bus

        # Ignore subsystems using parent or generated names
        if bus in ("drm", "pci", "rfkill", "usb"):
            return None

        # pnp
        if "pnp.id" in self._properties:
            match = re.match(r"^(?P<vendor_name>.*)(?P<product_id>[%s]{4})$"
                % string.hexdigits, self._properties["pnp.id"])
            if match:
                return match.group("vendor_name")

        for property in ("battery.vendor",
                         "ieee1394.vendor",
                         "scsi.vendor",
                         "system.hardware.vendor",
                         "info.vendor"):
            if property in self._properties:
                return self._properties[property]

        return None


class DmiDeviceResource(DeviceResource):

    _category_to_property = {
        "BIOS": "system.firmware",
        "BOARD": "system.board",
        "CHASSIS": "system.chassis"}

    def __init__(self, properties, category):
        super(DmiDeviceResource, self).__init__(properties)
        if category not in self._category_to_property:
            raise Exception, "Unsupported category: %s" % category

        self._category = category

    @property
    def _property(self):
        return self._category_to_property[self._category]

    @property
    def category(self):
        return self._category

    @property
    def path(self):
        path = super(DmiDeviceResource, self).path
        return posixpath.join(path, self._category.lower())

    @property
    def product(self):
        for subproperty in "product", "type", "version":
            property = "%s.%s" % (self._property, subproperty)
            product = self._properties.get(property)
            if product and product != "Not Available":
                return product

        return None

    @property
    def vendor(self):
        for subproperty in "vendor", "manufacturer":
            property = "%s.%s" % (self._property, subproperty)
            if property in self._properties:
                return self._properties[property]

        return None


class HalResource(object):
    """Resource for HAL information.

    Each item contained in this resource consists of the udi as key and
    the corresponding device resource as value.
    """

    # See also section "Deprecated Properties" of the "HAL 0.5.10 Specification",
    # available from http://people.freedesktop.org/~david/hal-spec/hal-spec.html
    _deprecated_expressions = (
        (r"info\.bus",                             "info.subsystem"),
        (r"([^\.]+)\.physical_device",             "\1.originating_device"),
        (r"power_management\.can_suspend_to_ram",  "power_management.can_suspend"),
        (r"power_management\.can_suspend_to_disk", "power_management.can_hibernate"),
        (r"smbios\.system\.manufacturer",          "system.hardware.vendor"),
        (r"smbios\.system\.product",               "system.hardware.product"),
        (r"smbios\.system\.version",               "system.hardware.version"),
        (r"smbios\.system\.serial",                "system.hardware.serial"),
        (r"smbios\.system\.uuid",                  "system.hardware.uuid"),
        (r"smbios\.bios\.vendor",                  "system.firmware.vendor"),
        (r"smbios\.bios\.version",                 "system.firmware.version"),
        (r"smbios\.bios\.release_date",            "system.firmware.release_date"),
        (r"smbios\.chassis\.manufacturer",         "system.chassis.manufacturer"),
        (r"smbios\.chassis\.type",                 "system.chassis.type"),
        (r"system\.vendor",                        "system.hardware.vendor"),
        (r"usb_device\.speed_bcd",                 "usb_device.speed"),
        (r"usb_device\.version_bcd",               "usb_device.version"))

    _conversion_types = {
        dbus.Boolean: bool,
        dbus.Int16: int,
        dbus.UInt16: int,
        dbus.Int32: int,
        dbus.UInt32: int,
        dbus.Int64: int,
        dbus.UInt64: int,
        dbus.Double: float,
        dbus.Array: list,
        dbus.Dictionary: dict,
        dbus.String: str,
        dbus.UTF8String: unicode}

    def __init__(self, *args, **kwargs):
        super(HalResource, self).__init__(*args, **kwargs)
        self._deprecated_patterns = ((re.compile("^%s$" % a), b)
            for (a, b) in self._deprecated_expressions)

    def _get_key(self, key):
        key = str(key)
        for (old, new) in self._deprecated_patterns:
            key = old.sub(new, key)

        return key

    def _get_value(self, value):
        return self._conversion_types[type(value)](value)

    def _ignore_device(self, device):
        # Ignore devices without bus information
        if not device.bus:
            return True

        # Ignore devices without product information
        if not device.product and device.product_id is None:
            return True

        # Ignore invalid subsystem information
        if (device.subproduct_id is None and device.subvendor_id is not None) \
           or (device.subproduct_id is not None and device.subvendor_id is None):
            return True

        # Ignore virtual devices except for dmi information
        if device.bus != "dmi" \
           and "virtual" in device.path.split(posixpath.sep):
            return True

        return False

    @property
    def devices(self):
        devices = []
        bus = dbus.SystemBus()
        manager_obj = bus.get_object("org.freedesktop.Hal", "/org/freedesktop/Hal/Manager")
        manager = dbus.Interface(manager_obj, "org.freedesktop.Hal.Manager")
        for udi in manager.GetAllDevices():
            name = udi.split(posixpath.sep)[-1]
            object = bus.get_object("org.freedesktop.Hal", udi)
            interface = dbus.Interface(object, "org.freedesktop.Hal.Device")

            properties = {}
            for key, value in interface.GetAllProperties().iteritems():
                key = self._get_key(key)
                value = self._get_value(value)
                properties[key] = value

            if name == "computer":
                properties["linux.subsystem"] = "dmi"
                properties["linux.sysfs_path"] = "/sys/devices/virtual/dmi/id"

                device = DeviceResource(properties)
                devices.append(device)
                for category in "BIOS", "BOARD", "CHASSIS":
                    device = DmiDeviceResource(properties, category)
                    devices.append(device)
            else:
                device = DeviceResource(properties)
                devices.append(device)

        return [d for d in devices if not self._ignore_device(d)]


def main():
    attributes = ("path", "bus", "category", "driver", "product_id",
        "vendor_id", "subproduct_id", "subvendor_id", "product", "vendor",)

    hal = HalResource()
    for device in hal.devices:
        for attribute in attributes:
            value = getattr(device, attribute)
            if value is not None:
                print "%s: %s" % (attribute, value)

        # Empty line
        print

    return 0


if __name__ == "__main__":
    sys.exit(main())