From daac099b3cb707d74821fd43286985401e0b79ab Mon Sep 17 00:00:00 2001 From: Piotr Bartman Date: Thu, 1 Feb 2024 19:20:19 +0100 Subject: [PATCH] q-dev: frontend_device -> attachment --- qubesusbproxy/core3ext.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/qubesusbproxy/core3ext.py b/qubesusbproxy/core3ext.py index 17e273a..3a2fb57 100644 --- a/qubesusbproxy/core3ext.py +++ b/qubesusbproxy/core3ext.py @@ -44,6 +44,7 @@ usb_connected_to_re = re.compile(br"^[a-zA-Z][a-zA-Z0-9_.-]*$") usb_device_hw_ident_re = re.compile(r'^[0-9a-f]{4}:[0-9a-f]{4} ') +HWDATA_PATH = '/usr/share/hwdata' class USBDevice(qubes.devices.DeviceInfo): # pylint: disable=too-few-public-methods @@ -228,7 +229,7 @@ def _sanitize( ) @property - def frontend_domain(self): + def attachment(self): if not self.backend_domain.is_running(): return None untrusted_connected_to = self.backend_domain.untrusted_qdb.read( @@ -283,8 +284,8 @@ def _load_usb_known_devices() -> Dict[str, Dict[str, Tuple[str, str]]]: # subclass subclass_name <-- single tab # prog-if prog-if_name <-- two tabs result = {} - with open('/usr/share/hwdata/usb.ids', - encoding='utf-8', errors='ignore') as usb_ids: # TODO debian etc. + with open(HWDATA_PATH + '/usb.ids', + encoding='utf-8', errors='ignore') as usb_ids: for line in usb_ids.readlines(): line = line.rstrip() if line.startswith('#'): @@ -394,7 +395,7 @@ def on_domain_init_load(self, vm, event): # avoid building a cache on domain-init, as it isn't fully set yet, # and definitely isn't running yet current_devices = { - dev.ident: dev.frontend_domain + dev.ident: dev.attachment for dev in self.on_device_list_usb(vm, None) } self.devices_cache[vm.name] = current_devices @@ -416,7 +417,7 @@ def on_qdb_change(self, vm, event, path): """A change in QubesDB means a change in device list.""" # pylint: disable=unused-argument,no-self-use vm.fire_event('device-list-change:usb') - current_devices = dict((dev.ident, dev.frontend_domain) + current_devices = dict((dev.ident, dev.attachment) for dev in self.on_device_list_usb(vm, None)) # send events about devices detached/attached outside by themselves @@ -535,7 +536,7 @@ def on_device_list_attached(self, vm, event, **kwargs): return for dev in self.get_all_devices(vm.app): - if dev.frontend_domain == vm: + if dev.attachment == vm: yield (dev, {'identity': dev.full_identity}) @qubes.ext.handler('device-pre-attach:usb') @@ -567,10 +568,10 @@ async def on_device_attach_usb(self, vm, event, device, options): # file=sys.stderr) return - if device.frontend_domain: + if device.attachment: raise qubes.devices.DeviceAlreadyAttached( 'Device {!s} already attached to {!s}'.format( - device, device.frontend_domain) + device, device.attachment) ) stubdom_qrexec = ( @@ -622,7 +623,7 @@ async def on_device_detach_usb(self, vm, event, device): if not isinstance(device, USBDevice): return - connected_to = device.frontend_domain + connected_to = device.attachment # detect race conditions; there is still race here, but much smaller if connected_to is None or connected_to.qid != vm.qid: raise QubesUSBException(