r3compatibility.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #!/usr/bin/python2 -O
  2. # vim: fileencoding=utf-8
  3. #
  4. # The Qubes OS Project, https://www.qubes-os.org/
  5. #
  6. # Copyright (C) 2010 Joanna Rutkowska <joanna@invisiblethingslab.com>
  7. # Copyright (C) 2013-2016 Marek Marczykowski-Górecki
  8. # <marmarek@invisiblethingslab.com>
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; either version 2 of the License, or
  13. # (at your option) any later version.
  14. #
  15. # This program is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. # GNU General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU General Public License along
  21. # with this program; if not, write to the Free Software Foundation, Inc.,
  22. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  23. #
  24. import base64
  25. import datetime
  26. import qubes.ext
  27. import qubes.vm.qubesvm
  28. import qubes.vm.appvm
  29. import qubes.vm.templatevm
  30. import qubes.utils
  31. yum_proxy_ip = '10.137.255.254'
  32. yum_proxy_port = '8082'
  33. class R3Compatibility(qubes.ext.Extension):
  34. '''Maintain VM interface compatibility with R3.0 and R3.1.
  35. At lease where possible.
  36. '''
  37. # noinspection PyUnusedLocal
  38. @qubes.ext.handler('qdb-created')
  39. def on_qdb_created(self, vm, event):
  40. """
  41. :param vm: VM on which QubesDB entries were just created
  42. :type vm: qubes.vm.qubesvm.QubesVM
  43. """
  44. # /qubes-vm-type: AppVM, NetVM, ProxyVM, TemplateVM
  45. if isinstance(vm, qubes.vm.templatevm.TemplateVM):
  46. vmtype = 'TemplateVM'
  47. elif vm.netvm is not None and vm.provides_network:
  48. vmtype = 'ProxyVM'
  49. elif vm.netvm is None and vm.provides_network:
  50. vmtype = 'NetVM'
  51. else:
  52. vmtype = 'AppVM'
  53. vm.qdb.write('/qubes-vm-type', vmtype)
  54. # /qubes-vm-updateable
  55. vm.qdb.write('/qubes-vm-updateable', str(vm.updateable))
  56. # /qubes-base-template
  57. try:
  58. if vm.template:
  59. vm.qdb.write('/qubes-base-template', str(vm.template))
  60. else:
  61. vm.qdb.write('/qubes-base-template', '')
  62. except AttributeError:
  63. vm.qdb.write('/qubes-base-template', '')
  64. # /qubes-debug-mode: 0, 1
  65. vm.qdb.write('/qubes-debug-mode', str(int(vm.debug)))
  66. # /qubes-timezone
  67. timezone = vm.qdb.read('/timezone')
  68. if timezone:
  69. vm.qdb.write('/qubes-timezone', timezone)
  70. # /qubes-vm-persistence
  71. persistence = vm.qdb.read('/persistence')
  72. if persistence:
  73. vm.qdb.write('/qubes-vm-persistence', persistence)
  74. # /qubes-random-seed
  75. # write a new one, to make sure it wouldn't be reused/leaked
  76. vm.qdb.write('/qubes-random-seed',
  77. base64.b64encode(qubes.utils.urandom(64)))
  78. # /qubes-keyboard
  79. # not needed for now - the old one is still present
  80. # Networking
  81. if vm.provides_network:
  82. # '/qubes-netvm-network' value is only checked for being non empty
  83. vm.qdb.write('/qubes-netvm-network', vm.gateway)
  84. vm.qdb.write('/qubes-netvm-netmask', vm.netmask)
  85. vm.qdb.write('/qubes-netvm-gateway', vm.gateway)
  86. vm.qdb.write('/qubes-netvm-primary-dns', vm.dns[0])
  87. vm.qdb.write('/qubes-netvm-secondary-dns', vm.dns[1])
  88. if vm.netvm is not None:
  89. vm.qdb.write('/qubes-ip', vm.ip)
  90. vm.qdb.write('/qubes-netmask', vm.netvm.netmask)
  91. vm.qdb.write('/qubes-gateway', vm.netvm.gateway)
  92. vm.qdb.write('/qubes-primary-dns', vm.dns[0])
  93. vm.qdb.write('/qubes-secondary-dns', vm.dns[1])