windows.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # -*- encoding: utf-8 -*-
  2. #
  3. # The Qubes OS Project, http://www.qubes-os.org
  4. #
  5. # Copyright (C) 2017 Marek Marczykowski-Górecki
  6. # <marmarek@invisiblethingslab.com>
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 2 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License along
  19. # with this program; if not, see <http://www.gnu.org/licenses/>.
  20. import asyncio
  21. import qubes.ext
  22. class WindowsFeatures(qubes.ext.Extension):
  23. # pylint: disable=too-few-public-methods
  24. @qubes.ext.handler('features-request')
  25. def qubes_features_request(self, vm, event, untrusted_features):
  26. '''Handle features provided requested by Qubes Windows Tools'''
  27. # pylint: disable=no-self-use,unused-argument
  28. if getattr(vm, 'template', None):
  29. vm.log.warning(
  30. 'Ignoring qubes.NotifyTools for template-based VM')
  31. return
  32. guest_os = None
  33. if 'os' in untrusted_features:
  34. if untrusted_features['os'] in ['Windows']:
  35. guest_os = untrusted_features['os']
  36. qrexec = None
  37. if 'qrexec' in untrusted_features:
  38. if untrusted_features['qrexec'] == '1':
  39. # qrexec feature is set by CoreFeatures extension
  40. qrexec = True
  41. del untrusted_features
  42. if guest_os:
  43. vm.features['os'] = guest_os
  44. if guest_os == 'Windows' and qrexec:
  45. vm.features['rpc-clipboard'] = True
  46. @qubes.ext.handler('domain-create-on-disk')
  47. @asyncio.coroutine
  48. def on_domain_create_on_disk(self, vm, _event, **kwargs):
  49. # pylint: disable=no-self-use,unused-argument
  50. if getattr(vm, 'template', None) is None:
  51. # handle only template-based vms
  52. return
  53. template = vm.template
  54. if template.features.check_with_template('os', None) != 'Windows':
  55. # ignore non-windows templates
  56. return
  57. if vm.volumes['private'].save_on_stop:
  58. # until windows tools get ability to prepare private.img on its own,
  59. # copy one from the template
  60. vm.log.info('Windows template - cloning private volume')
  61. import_op = vm.volumes['private'].import_volume(
  62. template.volumes['private'])
  63. if asyncio.iscoroutine(import_op):
  64. yield from import_op