2018-07-09 19:42:18 +02:00
|
|
|
# -*- encoding: utf-8 -*-
|
|
|
|
#
|
|
|
|
# The Qubes OS Project, http://www.qubes-os.org
|
|
|
|
#
|
|
|
|
# Copyright (C) 2017 Marek Marczykowski-Górecki
|
|
|
|
# <marmarek@invisiblethingslab.com>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
# with this program; if not, see <http://www.gnu.org/licenses/>.
|
2018-07-16 22:02:05 +02:00
|
|
|
import asyncio
|
2018-07-09 19:42:18 +02:00
|
|
|
|
|
|
|
import qubes.ext
|
2019-06-28 12:29:24 +02:00
|
|
|
import qubes.utils
|
2018-07-09 19:42:18 +02:00
|
|
|
|
|
|
|
class WindowsFeatures(qubes.ext.Extension):
|
|
|
|
# pylint: disable=too-few-public-methods
|
|
|
|
@qubes.ext.handler('features-request')
|
|
|
|
def qubes_features_request(self, vm, event, untrusted_features):
|
|
|
|
'''Handle features provided requested by Qubes Windows Tools'''
|
|
|
|
# pylint: disable=no-self-use,unused-argument
|
|
|
|
if getattr(vm, 'template', None):
|
|
|
|
vm.log.warning(
|
|
|
|
'Ignoring qubes.NotifyTools for template-based VM')
|
|
|
|
return
|
|
|
|
|
|
|
|
guest_os = None
|
|
|
|
if 'os' in untrusted_features:
|
2018-10-23 23:29:23 +02:00
|
|
|
if untrusted_features['os'] in ['Windows', 'Linux']:
|
2018-07-09 19:42:18 +02:00
|
|
|
guest_os = untrusted_features['os']
|
|
|
|
|
|
|
|
qrexec = None
|
|
|
|
if 'qrexec' in untrusted_features:
|
|
|
|
if untrusted_features['qrexec'] == '1':
|
|
|
|
# qrexec feature is set by CoreFeatures extension
|
|
|
|
qrexec = True
|
|
|
|
|
|
|
|
del untrusted_features
|
|
|
|
|
|
|
|
if guest_os:
|
|
|
|
vm.features['os'] = guest_os
|
|
|
|
if guest_os == 'Windows' and qrexec:
|
|
|
|
vm.features['rpc-clipboard'] = True
|
|
|
|
|
2018-07-16 22:02:05 +02:00
|
|
|
@qubes.ext.handler('domain-create-on-disk')
|
|
|
|
@asyncio.coroutine
|
|
|
|
def on_domain_create_on_disk(self, vm, _event, **kwargs):
|
2018-07-09 19:42:18 +02:00
|
|
|
# pylint: disable=no-self-use,unused-argument
|
|
|
|
if getattr(vm, 'template', None) is None:
|
|
|
|
# handle only template-based vms
|
|
|
|
return
|
|
|
|
|
|
|
|
template = vm.template
|
|
|
|
if template.features.check_with_template('os', None) != 'Windows':
|
|
|
|
# ignore non-windows templates
|
|
|
|
return
|
|
|
|
|
2018-07-16 22:02:05 +02:00
|
|
|
if vm.volumes['private'].save_on_stop:
|
|
|
|
# until windows tools get ability to prepare private.img on its own,
|
|
|
|
# copy one from the template
|
|
|
|
vm.log.info('Windows template - cloning private volume')
|
2019-06-28 12:29:24 +02:00
|
|
|
yield from qubes.utils.coro_maybe(
|
|
|
|
vm.volumes['private'].import_volume(
|
|
|
|
template.volumes['private']))
|