From cddc5077881b85e55a4b294dc4b6844ab459ab6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Wed, 10 May 2017 14:29:19 +0200 Subject: [PATCH] mgmt: factor out filtering by mgmt-permission:... events Split actual filtering done by mgmt-permission: events into calling an event and applying returned filters. This way filtering done in mgmt.Events handler could reuse the same function. --- qubes/mgmt.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) 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':