diff --git a/qubes/mgmt.py b/qubes/mgmt.py index 5231e6ec..65b486e9 100644 --- a/qubes/mgmt.py +++ b/qubes/mgmt.py @@ -81,6 +81,14 @@ def api(name, *, no_payload=False): return decorator + +def apply_filters(iterable, filters): + '''Apply filters returned by mgmt-permission:... event''' + for selector in filters: + iterable = filter(selector, iterable) + return iterable + + class AbstractQubesMgmt(object): '''Common code for Qubes Management Protocol handling @@ -167,9 +175,8 @@ class AbstractQubesMgmt(object): def fire_event_for_filter(self, iterable, **kwargs): '''Fire an event on the source qube to filter for permission''' - for selector in self.fire_event_for_permission(**kwargs): - iterable = filter(selector, iterable) - return iterable + return apply_filters(iterable, + self.fire_event_for_permission(**kwargs)) class QubesMgmt(AbstractQubesMgmt): @@ -588,9 +595,9 @@ class QubesMgmt(AbstractQubesMgmt): return if event.startswith('mgmt-permission:'): return - for selector in event_filters: - if not selector((subject, event, kwargs)): - return + if not list(apply_filters([(subject, event, kwargs)], + event_filters)): + return self.send_event(subject, event, **kwargs) if self.dest.name == 'dom0':