qvm-sync-clock 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/python3
  2. # -*- encoding: utf8 -*-
  3. #
  4. # The Qubes OS Project, http://www.qubes-os.org
  5. #
  6. # Copyright (C) 2010 Marek Marczykowski <marmarek@invisiblethingslab.com>
  7. #
  8. # This program is free software; you can redistribute it and/or
  9. # modify it under the terms of the GNU General Public License
  10. # as published by the Free Software Foundation; either version 2
  11. # of the License, or (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
  19. # along with this program; if not, write to the Free Software
  20. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  21. #
  22. #
  23. import sys
  24. import re
  25. import subprocess
  26. from qubesadmin import Qubes
  27. def main():
  28. app = Qubes()
  29. clockvm = app.clockvm
  30. p = clockvm.run_service('qubes.GetDate')
  31. untrusted_date_out = p.stdout.read(25).decode('ascii', errors='strict')
  32. untrusted_date_out = untrusted_date_out.strip()
  33. if not re.match(r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\+00:?00$', untrusted_date_out):
  34. sys.stderr.write('Invalid date received, aborting!\n')
  35. sys.exit(1)
  36. date_out = untrusted_date_out
  37. subprocess.check_call(['date', '-u', '-Iseconds', '-s', date_out],
  38. stdout=subprocess.DEVNULL)
  39. subprocess.check_call(['hwclock', '--systohc'],
  40. stdout=subprocess.DEVNULL)
  41. if __name__ == '__main__':
  42. main()