diff --git a/qubes/ext/services.py b/qubes/ext/services.py index 857e155b..080fc59c 100644 --- a/qubes/ext/services.py +++ b/qubes/ext/services.py @@ -98,8 +98,11 @@ class ServicesExtension(qubes.ext.Extension): vm.untrusted_qdb.write('/qubes-service/{}'.format(service), str(int(bool(value)))) - if vm.name == "dom0" and str(int(bool(value))) == "1": - self.add_dom0_service(vm, service) + if vm.name == "dom0": + if str(int(bool(value))) == "1": + self.add_dom0_service(vm, service) + else: + self.remove_dom0_service(vm, service) @qubes.ext.handler('domain-feature-delete:*') def on_domain_feature_delete(self, vm, event, feature): @@ -136,6 +139,8 @@ class ServicesExtension(qubes.ext.Extension): service = feature[len('service.'):] if str(int(bool(value))) == "1": self.add_dom0_service(vm, service) + else: + self.remove_dom0_service(vm, service) @qubes.ext.handler('features-request') def supported_services(self, vm, event, untrusted_features): diff --git a/qubes/tests/ext.py b/qubes/tests/ext.py index 308670ee..8767dfef 100644 --- a/qubes/tests/ext.py +++ b/qubes/tests/ext.py @@ -336,6 +336,7 @@ class TC_20_Services(qubes.tests.QubesTestCase): self.base_dir_patch = mock.patch.dict( qubes.config.system_path, {'dom0_services_dir': self.test_base_dir}) self.base_dir_patch.start() + self.addCleanup(self.base_dir_patch.stop) service = 'guivm-gui-agent' service_path = self.test_base_dir + '/' + service @@ -343,7 +344,6 @@ class TC_20_Services(qubes.tests.QubesTestCase): self.dom0, 'feature-set:service.service.guivm-gui-agent', 'service.guivm-gui-agent', '1') - self.assertEqual(os.path.exists(service_path), True) def test_014_feature_delete_dom0(self): @@ -351,6 +351,7 @@ class TC_20_Services(qubes.tests.QubesTestCase): self.base_dir_patch = mock.patch.dict( qubes.config.system_path, {'dom0_services_dir': self.test_base_dir}) self.base_dir_patch.start() + self.addCleanup(self.base_dir_patch.stop) service = 'guivm-gui-agent' service_path = self.test_base_dir + '/' + service @@ -364,4 +365,20 @@ class TC_20_Services(qubes.tests.QubesTestCase): 'feature-delete:service.service.guivm-gui-agent', 'service.guivm-gui-agent') - self.assertEqual(os.path.exists(service_path), False) \ No newline at end of file + self.assertEqual(os.path.exists(service_path), False) + + def test_014_feature_set_empty_value_dom0(self): + self.test_base_dir = '/tmp/qubes-test-dir' + self.base_dir_patch = mock.patch.dict( + qubes.config.system_path, {'dom0_services_dir': self.test_base_dir}) + self.base_dir_patch.start() + self.addCleanup(self.base_dir_patch.stop) + service = 'guivm-gui-agent' + service_path = self.test_base_dir + '/' + service + + self.ext.on_domain_feature_set( + self.dom0, + 'feature-set:service.service.guivm-gui-agent', + 'service.guivm-gui-agent', '') + + self.assertEqual(os.path.exists(service_path), False)