From 5cf08b5b03502c5d28375c29fc6c62f0cc8ec9cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Sat, 22 May 2021 13:15:43 +0200 Subject: [PATCH] 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 --- qubesadmin/base.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/qubesadmin/base.py b/qubesadmin/base.py index c4c3b7b..b758b8b 100644 --- a/qubesadmin/base.py +++ b/qubesadmin/base.py @@ -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)