Uniformly handle QubesVMNotFoundError when accessing a property

If domain was just removed, it the qrexec call may result in a
QubesVMNotFoundError exception. If it was removed earlier, and the
caller is in connecting via qrexec, the call will be rejected at the
policy level. Treat both situations uniformely - with
QubesPropertyAccessError. This allows using convenient `getattr()` to
define placeholder value (if appropriate), or try/except with a single
exception instead of two.

QubesOS/qubes-issues#5105
This commit is contained in:
Marek Marczykowski-Górecki 2021-05-22 13:15:43 +02:00
parent 638dbf6143
commit 5cf08b5b03
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724

View File

@ -157,7 +157,8 @@ class PropertyHolder(object):
self._method_prefix + 'Get',
item,
None)
except qubesadmin.exc.QubesDaemonAccessError:
except (qubesadmin.exc.QubesDaemonAccessError,
qubesadmin.exc.QubesVMNotFoundError):
raise qubesadmin.exc.QubesPropertyAccessError(item)
is_default, value = self._deserialize_property(property_str)
if self.app.cache_enabled:
@ -179,7 +180,8 @@ class PropertyHolder(object):
self._method_prefix + 'GetDefault',
item,
None)
except qubesadmin.exc.QubesDaemonAccessError:
except (qubesadmin.exc.QubesDaemonAccessError,
qubesadmin.exc.QubesVMNotFoundError):
raise qubesadmin.exc.QubesPropertyAccessError(item)
if not property_str:
raise AttributeError(item + ' has no default')
@ -224,7 +226,8 @@ class PropertyHolder(object):
self._method_prefix + 'Get',
item,
None)
except qubesadmin.exc.QubesDaemonNoResponseError:
except (qubesadmin.exc.QubesDaemonNoResponseError,
qubesadmin.exc.QubesVMNotFoundError):
raise qubesadmin.exc.QubesPropertyAccessError(item)
is_default, value = self._deserialize_property(property_str)
if self.app.cache_enabled:
@ -353,7 +356,8 @@ class PropertyHolder(object):
self._method_prefix + 'Reset',
key,
None)
except qubesadmin.exc.QubesDaemonNoResponseError:
except (qubesadmin.exc.QubesDaemonNoResponseError,
qubesadmin.exc.QubesVMNotFoundError):
raise qubesadmin.exc.QubesPropertyAccessError(key)
else:
if isinstance(value, qubesadmin.vm.QubesVM):
@ -366,7 +370,8 @@ class PropertyHolder(object):
self._method_prefix + 'Set',
key,
str(value).encode('utf-8'))
except qubesadmin.exc.QubesDaemonNoResponseError:
except (qubesadmin.exc.QubesDaemonNoResponseError,
qubesadmin.exc.QubesVMNotFoundError):
raise qubesadmin.exc.QubesPropertyAccessError(key)
def __delattr__(self, name):
@ -378,7 +383,8 @@ class PropertyHolder(object):
self._method_prefix + 'Reset',
name
)
except qubesadmin.exc.QubesDaemonNoResponseError:
except (qubesadmin.exc.QubesDaemonNoResponseError,
qubesadmin.exc.QubesVMNotFoundError):
raise qubesadmin.exc.QubesPropertyAccessError(name)