Skip to content

Commit d7302f3

Browse files
committed
q-dev: check identity
1 parent a5a7fdb commit d7302f3

File tree

4 files changed

+36
-22
lines changed

4 files changed

+36
-22
lines changed

qubes/device_protocol.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -857,14 +857,15 @@ def clone(self, **kwargs):
857857
def device(self) -> DeviceInfo:
858858
"""Get DeviceInfo object corresponding to this DeviceAssignment"""
859859
dev = self.backend_domain.devices[self.devclass][self.ident]
860-
if (self.device_identity is not None
861-
and self.device_identity != dev.self_identity):
860+
# TODO: device identity could not match
861+
# if (self.device_identity is not None
862+
# and self.device_identity != dev.self_identity):
862863
# raise ProtocolError(
863864
# "Device identity does not match, expected "
864865
# f"'{self.device_identity}' got '{dev.self_identity}'")
865866
# TODO
866-
return UnknownDevice(
867-
self.backend_domain, self.ident, devclass=self.devclass)
867+
# return UnknownDevice(
868+
# self.backend_domain, self.ident, devclass=self.devclass)
868869
return dev
869870

870871
@property

qubes/ext/block.py

+22-16
Original file line numberDiff line numberDiff line change
@@ -502,15 +502,6 @@ def pre_attachment_internal(
502502
raise qubes.exc.QubesValueError(
503503
'Unsupported option {}'.format(option))
504504

505-
# identity = value # TODO!
506-
# if identity not in ('any', device.self_identity):
507-
# print("Unrecognized identity, skipping attachment of"
508-
# f" {device}", file=sys.stderr)
509-
# raise qubes.devices.UnrecognizedDevice(
510-
# f"Device presented identity {device.self_identity} "
511-
# f"does not match expected {identity}"
512-
# )
513-
514505
if 'read-only' not in options:
515506
options['read-only'] = 'yes' if device.mode == 'r' else 'no'
516507
if options.get('read-only', 'no') == 'no' and device.mode == 'r':
@@ -550,19 +541,34 @@ def pre_attachment_internal(
550541
async def on_domain_start(self, vm, _event, **_kwargs):
551542
# pylint: disable=unused-argument
552543
for assignment in vm.devices['block'].get_assigned_devices():
553-
self.notify_auto_attached(
554-
vm, assignment.device, assignment.options)
544+
if assignment.mode == qubes.device_protocol.AssignmentMode.ASK:
545+
pass
546+
self.notify_auto_attached(vm, assignment)
547+
548+
def notify_auto_attached(self, vm, assignment):
549+
identity = assignment.device_ientity
550+
device = assignment.device
551+
if identity not in ('any', device.self_identity):
552+
print("Unrecognized identity, skipping attachment of device in port"
553+
f" {assignment}", file=sys.stderr)
554+
raise qubes.devices.UnrecognizedDevice(
555+
f"Device presented identity {device.self_identity} "
556+
f"does not match expected {identity}"
557+
)
555558

556-
def notify_auto_attached(self, vm, device, options):
557559
self.pre_attachment_internal(
558-
vm, device, options, expected_attachment=vm)
560+
vm, device, assignment.options, expected_attachment=vm)
561+
559562
asyncio.ensure_future(vm.fire_event_async(
560-
'device-attach:block', device=device, options=options))
563+
'device-attach:block',
564+
device=device,
565+
options=assignment.options,
566+
))
561567

562-
async def attach_and_notify(self, vm, device, options):
568+
async def attach_and_notify(self, vm, assignment):
563569
# bypass DeviceCollection logic preventing double attach
564570
# we expected that these devices are already attached to this vm
565-
self.notify_auto_attached(vm, device, options)
571+
self.notify_auto_attached(vm, assignment)
566572

567573
@qubes.ext.handler('domain-shutdown')
568574
async def on_domain_shutdown(self, vm, event, **_kwargs):

qubes/ext/utils.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ def device_list_change(
100100
else:
101101
target = tuple(frontends.keys())[0]
102102
assignment = frontends[target]
103-
asyncio.ensure_future(ext.attach_and_notify(
104-
target, assignment.device, assignment.options))
103+
asyncio.ensure_future(ext.attach_and_notify(target, assignment))
105104

106105

107106
def compare_device_cache(vm, devices_cache, current_devices):

qubes/vm/__init__.py

+8
Original file line numberDiff line numberDiff line change
@@ -285,31 +285,39 @@ def load_extras(self):
285285
options[option.get('name')] = str(option.text)
286286

287287
try:
288+
import sys # TODO
289+
print(f'{self.name=}', file=sys.stderr) # TODO
288290
# backward compatibility: persistent~>required=True
289291
legacy_required = node.get('required', 'absent')
292+
print(f'{legacy_required=}', file=sys.stderr) # TODO
290293
if legacy_required == 'absent':
291294
mode_str = node.get('mode', 'required')
292295
try:
293296
mode = (qubes.device_protocol.
294297
AssignmentMode(mode_str))
298+
print(f'{mode=}', file=sys.stderr) # TODO
295299
except ValueError:
296300
self.log.error(
297301
"Unrecognized assignment mode, ignoring.")
298302
continue
299303
else:
300304
required = qubes.property.bool(
301305
None, None, legacy_required)
306+
print(f'{required=}', file=sys.stderr) # TODO
302307
if required:
303308
mode = (qubes.device_protocol.
304309
AssignmentMode.REQUIRED)
310+
print(f'{mode=}', file=sys.stderr) # TODO
305311
else:
306312
mode = (qubes.device_protocol.
307313
AssignmentMode.AUTO)
314+
print(f'{mode=}', file=sys.stderr) # TODO
308315
if 'identity' in options:
309316
identity = options.get('identity')
310317
del options['identity']
311318
else:
312319
identity = node.get('identity', 'any')
320+
print(mode.value, file=sys.stderr) # TODO
313321
device_assignment = qubes.device_protocol.DeviceAssignment(
314322
qubes.device_protocol.Port(
315323
backend_domain=self.app.domains[

0 commit comments

Comments
 (0)