2020-01-24 16:52:39 +01:00
|
|
|
# -*- encoding: utf-8 -*-
|
2017-06-12 12:22:39 +02:00
|
|
|
#
|
|
|
|
# The Qubes OS Project, http://www.qubes-os.org
|
|
|
|
#
|
|
|
|
# Copyright (C) 2017 Marek Marczykowski-Górecki
|
|
|
|
# <marmarek@invisiblethingslab.com>
|
|
|
|
#
|
2017-10-12 00:11:50 +02:00
|
|
|
# This library is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2.1 of the License, or (at your option) any later version.
|
2017-06-12 12:22:39 +02:00
|
|
|
#
|
2017-10-12 00:11:50 +02:00
|
|
|
# This library is distributed in the hope that it will be useful,
|
2017-06-12 12:22:39 +02:00
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2017-10-12 00:11:50 +02:00
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# Lesser General Public License for more details.
|
2017-06-12 12:22:39 +02:00
|
|
|
#
|
2017-10-12 00:11:50 +02:00
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
|
|
# License along with this library; if not, see <https://www.gnu.org/licenses/>.
|
2018-11-11 07:50:36 +01:00
|
|
|
import asyncio
|
2017-06-12 12:22:39 +02:00
|
|
|
|
|
|
|
import qubes.ext
|
|
|
|
|
|
|
|
class CoreFeatures(qubes.ext.Extension):
|
|
|
|
# pylint: disable=too-few-public-methods
|
|
|
|
@qubes.ext.handler('features-request')
|
2018-11-11 07:50:36 +01:00
|
|
|
@asyncio.coroutine
|
2017-06-12 12:22:39 +02:00
|
|
|
def qubes_features_request(self, vm, event, untrusted_features):
|
|
|
|
'''Handle features provided by qubes-core-agent and qubes-gui-agent'''
|
|
|
|
# pylint: disable=no-self-use,unused-argument
|
|
|
|
if getattr(vm, 'template', None):
|
|
|
|
vm.log.warning(
|
|
|
|
'Ignoring qubes.NotifyTools for template-based VM')
|
|
|
|
return
|
|
|
|
|
|
|
|
requested_features = {}
|
2020-01-24 16:52:39 +01:00
|
|
|
for feature in (
|
|
|
|
'qrexec', 'gui', 'gui-emulated', 'qubes-firewall', 'vmexec'):
|
2017-06-12 12:22:39 +02:00
|
|
|
untrusted_value = untrusted_features.get(feature, None)
|
|
|
|
if untrusted_value in ('1', '0'):
|
|
|
|
requested_features[feature] = bool(int(untrusted_value))
|
|
|
|
del untrusted_features
|
|
|
|
|
|
|
|
# default user for qvm-run etc
|
|
|
|
# starting with Qubes 4.x ignored
|
|
|
|
# qrexec agent presence (0 or 1)
|
|
|
|
# gui agent presence (0 or 1)
|
|
|
|
|
|
|
|
qrexec_before = vm.features.get('qrexec', False)
|
2018-07-09 19:42:18 +02:00
|
|
|
for feature in ('qrexec', 'gui', 'gui-emulated'):
|
2017-06-12 12:22:39 +02:00
|
|
|
# do not allow (Template)VM to override setting if already set
|
|
|
|
# some other way
|
|
|
|
if feature in requested_features and feature not in vm.features:
|
|
|
|
vm.features[feature] = requested_features[feature]
|
|
|
|
|
2017-07-30 18:34:43 +02:00
|
|
|
# those features can be freely enabled or disabled by template
|
2020-01-24 16:52:39 +01:00
|
|
|
for feature in ('qubes-firewall', 'vmexec'):
|
2017-07-30 18:34:43 +02:00
|
|
|
if feature in requested_features:
|
|
|
|
vm.features[feature] = requested_features[feature]
|
|
|
|
|
2017-06-12 12:22:39 +02:00
|
|
|
if not qrexec_before and vm.features.get('qrexec', False):
|
|
|
|
# if this is the first time qrexec was advertised, now can finish
|
|
|
|
# template setup
|
2018-11-11 07:50:36 +01:00
|
|
|
yield from vm.fire_event_async('template-postinstall')
|
2020-05-05 17:01:38 +02:00
|
|
|
|
|
|
|
# pylint: disable=no-self-use
|
|
|
|
def set_servicevm_feature(self, subject):
|
|
|
|
if getattr(subject, 'provides_network', False):
|
|
|
|
subject.features['servicevm'] = 1
|
2020-05-21 05:03:25 +02:00
|
|
|
# icon is calculated based on this feature
|
|
|
|
subject.fire_event('property-reset:icon', name='icon')
|
2020-05-05 17:01:38 +02:00
|
|
|
elif 'servicevm' in subject.features:
|
|
|
|
del subject.features['servicevm']
|
2020-05-21 05:03:25 +02:00
|
|
|
# icon is calculated based on this feature
|
|
|
|
subject.fire_event('property-reset:icon', name='icon')
|
2020-05-05 17:01:38 +02:00
|
|
|
|
|
|
|
@qubes.ext.handler('property-set:provides_network')
|
|
|
|
def on_property_set(self, subject, event, name, newvalue, oldvalue=None):
|
|
|
|
# pylint: disable=unused-argument
|
|
|
|
self.set_servicevm_feature(subject)
|
|
|
|
|
2020-05-21 04:48:02 +02:00
|
|
|
@qubes.ext.handler('property-reset:provides_network')
|
|
|
|
def on_property_reset(self, subject, event, name):
|
2020-05-05 17:01:38 +02:00
|
|
|
# pylint: disable=unused-argument
|
|
|
|
self.set_servicevm_feature(subject)
|
|
|
|
|
|
|
|
@qubes.ext.handler('domain-load')
|
|
|
|
def on_domain_load(self, subject, event):
|
|
|
|
# pylint: disable=unused-argument
|
|
|
|
self.set_servicevm_feature(subject)
|