qvm-sync-clock 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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!')
  35. sys.exit(1)
  36. subprocess.check_call(['date', '-u', '-Iseconds', '-s', untrusted_date_out],
  37. stdout=subprocess.DEVNULL)
  38. subprocess.check_call(['hwclock', '--systohc'],
  39. stdout=subprocess.DEVNULL)
  40. if __name__ == '__main__':
  41. main()