core_features.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # -*- encoding: utf8 -*-
  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 qubes.ext
  21. class CoreFeatures(qubes.ext.Extension):
  22. # pylint: disable=too-few-public-methods
  23. @qubes.ext.handler('features-request')
  24. def qubes_features_request(self, vm, event, untrusted_features):
  25. '''Handle features provided by qubes-core-agent and qubes-gui-agent'''
  26. # pylint: disable=no-self-use,unused-argument
  27. if getattr(vm, 'template', None):
  28. vm.log.warning(
  29. 'Ignoring qubes.NotifyTools for template-based VM')
  30. return
  31. # for now used only to check for the tools presence
  32. if 'version' in untrusted_features:
  33. # any suspicious string will raise exception here,
  34. # but otherwise ignored
  35. int(untrusted_features['version'])
  36. requested_features = {}
  37. for feature in ('qrexec', 'gui'):
  38. untrusted_value = untrusted_features.get(feature, None)
  39. if untrusted_value in ('1', '0'):
  40. requested_features[feature] = bool(int(untrusted_value))
  41. del untrusted_features
  42. # default user for qvm-run etc
  43. # starting with Qubes 4.x ignored
  44. # qrexec agent presence (0 or 1)
  45. # gui agent presence (0 or 1)
  46. qrexec_before = vm.features.get('qrexec', False)
  47. for feature in ('qrexec', 'gui'):
  48. # do not allow (Template)VM to override setting if already set
  49. # some other way
  50. if feature in requested_features and feature not in vm.features:
  51. vm.features[feature] = requested_features[feature]
  52. if not qrexec_before and vm.features.get('qrexec', False):
  53. # if this is the first time qrexec was advertised, now can finish
  54. # template setup
  55. vm.fire_event('template-postinstall')