qubes-notify-tools 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/python2
  2. import os
  3. import sys
  4. from qubes.qubes import QubesVmCollection,QubesException,QubesHVm
  5. from qubes.qubes import xs
  6. def main():
  7. source = os.getenv("QREXEC_REMOTE_DOMAIN")
  8. if source is None:
  9. print >> sys.stderr, 'This script must be called as qrexec service!'
  10. exit(1)
  11. qvm_collection = QubesVmCollection()
  12. qvm_collection.lock_db_for_writing()
  13. try:
  14. qvm_collection.load()
  15. source_vm = qvm_collection.get_vm_by_name(source)
  16. if source_vm is None:
  17. raise QubesException('Domain ' + source + ' does not exists (?!)')
  18. if not isinstance(source_vm, QubesHVm):
  19. raise QubesException('Service qubes.ToolsNotify is designed only for HVM domains')
  20. xs_path = "/local/domain/{0}/qubes-tools".format(source_vm.get_xid())
  21. # for now used only to check for the tools presence
  22. untrusted_version = xs.read('', '{0}/version'.format(xs_path))
  23. # reserved for future use
  24. untrusted_os = xs.read('', '{0}/os'.format(xs_path))
  25. # qrexec agent presence (0 or 1)
  26. untrusted_qrexec = xs.read('', '{0}/qrexec'.format(xs_path))
  27. # gui agent presence (0 or 1)
  28. untrusted_gui = xs.read('', '{0}/gui'.format(xs_path))
  29. if untrusted_version is None:
  30. # tools didn't advertised its features; it's strange that this
  31. # service is called, but ignore it
  32. return
  33. # any suspicious string will raise exception here
  34. version = int(untrusted_version)
  35. # untrusted_os - ignore for now
  36. if untrusted_qrexec is None:
  37. qrexec = 0
  38. else:
  39. qrexec = int(untrusted_qrexec)
  40. if untrusted_gui is None:
  41. gui = 0
  42. else:
  43. gui = int(untrusted_gui)
  44. # Let the tools to be able to enable *or disable* each particular component
  45. source_vm.qrexec_installed = qrexec > 0
  46. source_vm.guiagent_installed = gui > 0
  47. qvm_collection.save()
  48. except Exception as e:
  49. print >> sys.stderr, e.message
  50. exit(1)
  51. finally:
  52. qvm_collection.unlock_db()
  53. main()