windows.py 2.7 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. import qubes.utils
  23. class WindowsFeatures(qubes.ext.Extension):
  24. # pylint: disable=too-few-public-methods
  25. @qubes.ext.handler('features-request')
  26. def qubes_features_request(self, vm, event, untrusted_features):
  27. '''Handle features provided requested by Qubes Windows Tools'''
  28. # pylint: disable=no-self-use,unused-argument
  29. if getattr(vm, 'template', None):
  30. vm.log.warning(
  31. 'Ignoring qubes.NotifyTools for template-based VM')
  32. return
  33. guest_os = None
  34. if 'os' in untrusted_features:
  35. if untrusted_features['os'] in ['Windows', 'Linux']:
  36. guest_os = untrusted_features['os']
  37. qrexec = None
  38. if 'qrexec' in untrusted_features:
  39. if untrusted_features['qrexec'] == '1':
  40. # qrexec feature is set by CoreFeatures extension
  41. qrexec = True
  42. del untrusted_features
  43. if guest_os:
  44. vm.features['os'] = guest_os
  45. if guest_os == 'Windows' and qrexec:
  46. vm.features['rpc-clipboard'] = True
  47. @qubes.ext.handler('domain-create-on-disk')
  48. @asyncio.coroutine
  49. def on_domain_create_on_disk(self, vm, _event, **kwargs):
  50. # pylint: disable=no-self-use,unused-argument
  51. if getattr(vm, 'template', None) is None:
  52. # handle only template-based vms
  53. return
  54. template = vm.template
  55. if template.features.check_with_template('os', None) != 'Windows':
  56. # ignore non-windows templates
  57. return
  58. if vm.volumes['private'].save_on_stop:
  59. # until windows tools get ability to prepare private.img on its own,
  60. # copy one from the template
  61. vm.log.info('Windows template - cloning private volume')
  62. yield from qubes.utils.coro_maybe(
  63. vm.volumes['private'].import_volume(
  64. template.volumes['private']))