|
27 | 27 | import argparse
|
28 | 28 | import os
|
29 | 29 | import sys
|
| 30 | +from typing import Protocol |
30 | 31 |
|
31 | 32 | import qubesadmin
|
32 | 33 | import qubesadmin.exc
|
33 | 34 | import qubesadmin.tools
|
34 | 35 | import qubesadmin.device_protocol
|
35 | 36 | from qubesadmin.device_protocol import (Port, DeviceInfo, UnknownDevice,
|
36 | 37 | DeviceAssignment, VirtualDevice,
|
37 |
| - DeviceInterface) |
| 38 | + DeviceInterface, ProtocolError) |
38 | 39 | from qubesadmin.devices import DEVICE_DENY_LIST
|
39 | 40 |
|
40 | 41 |
|
@@ -178,7 +179,23 @@ def attach_device(args):
|
178 | 179 | options['read-only'] = 'yes'
|
179 | 180 | parse_ro_option_as_read_only(options)
|
180 | 181 | assignment.options = options
|
| 182 | + |
181 | 183 | try:
|
| 184 | + try: |
| 185 | + dev = assignment.device |
| 186 | + except ProtocolError as exc: |
| 187 | + raise qubesadmin.exc.QubesException(str(exc)) |
| 188 | + |
| 189 | + if not assignment.matches(dev): |
| 190 | + raise qubesadmin.exc.QubesException( |
| 191 | + "Unrecognized identity, skipping attachment of device " |
| 192 | + f"from the port {assignment}") |
| 193 | + |
| 194 | + if isinstance(dev, UnknownDevice): |
| 195 | + raise qubesadmin.exc.QubesException( |
| 196 | + f"{device.devclass} device not recognized " |
| 197 | + f"at {device.port_id} port.") |
| 198 | + |
182 | 199 | vm.devices[args.devclass].attach(assignment)
|
183 | 200 | except qubesadmin.exc.QubesException as exc:
|
184 | 201 | # backward compatibility
|
|
0 commit comments