core_features.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 library is free software; you can redistribute it and/or
  9. # modify it under the terms of the GNU Lesser General Public
  10. # License as published by the Free Software Foundation; either
  11. # version 2.1 of the License, or (at your option) any later version.
  12. #
  13. # This library 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 GNU
  16. # Lesser General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Lesser General Public
  19. # License along with this library; if not, see <https://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. requested_features = {}
  32. for feature in ('qrexec', 'gui', 'qubes-firewall'):
  33. untrusted_value = untrusted_features.get(feature, None)
  34. if untrusted_value in ('1', '0'):
  35. requested_features[feature] = bool(int(untrusted_value))
  36. del untrusted_features
  37. # default user for qvm-run etc
  38. # starting with Qubes 4.x ignored
  39. # qrexec agent presence (0 or 1)
  40. # gui agent presence (0 or 1)
  41. qrexec_before = vm.features.get('qrexec', False)
  42. for feature in ('qrexec', 'gui'):
  43. # do not allow (Template)VM to override setting if already set
  44. # some other way
  45. if feature in requested_features and feature not in vm.features:
  46. vm.features[feature] = requested_features[feature]
  47. # those features can be freely enabled or disabled by template
  48. for feature in ('qubes-firewall',):
  49. if feature in requested_features:
  50. vm.features[feature] = requested_features[feature]
  51. if not qrexec_before and vm.features.get('qrexec', False):
  52. # if this is the first time qrexec was advertised, now can finish
  53. # template setup
  54. vm.fire_event('template-postinstall')