qvm-sync-clock 1.5 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 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. #
  21. #
  22. import sys
  23. import re
  24. import subprocess
  25. from qubesadmin import Qubes
  26. def main():
  27. app = Qubes()
  28. clockvm = app.clockvm
  29. p = clockvm.run_service('qubes.GetDate')
  30. untrusted_date_out = p.stdout.read(25).decode('ascii', errors='strict')
  31. untrusted_date_out = untrusted_date_out.strip()
  32. if not re.match(r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\+00:?00$', untrusted_date_out):
  33. sys.stderr.write('Invalid date received, aborting!\n')
  34. sys.exit(1)
  35. date_out = untrusted_date_out
  36. subprocess.check_call(['date', '-u', '-Iseconds', '-s', date_out],
  37. stdout=subprocess.DEVNULL)
  38. subprocess.check_call(['hwclock', '--systohc'],
  39. stdout=subprocess.DEVNULL)
  40. if __name__ == '__main__':
  41. main()