Revert back to using reg to get timezone

Reverts PR 51095
Checks for null characters
This commit is contained in:
twangboy 2019-03-07 16:16:13 -07:00
parent 892cdaeaa7
commit 59b1d4f767
No known key found for this signature in database
GPG key ID: 93FF3BDEB278C9EB

View file

@ -205,22 +205,23 @@ def get_zone():
Returns:
str: Timezone in unix format
Raises:
CommandExecutionError: If timezone could not be gathered
CLI Example:
.. code-block:: bash
salt '*' timezone.get_zone
'''
cmd = ['tzutil', '/g']
res = __salt__['cmd.run_all'](cmd, python_shell=False)
if res['retcode'] or not res['stdout']:
raise CommandExecutionError('tzutil encountered an error getting '
'timezone',
info=res)
return mapper.get_unix(res['stdout'].lower(), 'Unknown')
win_zone = __utils__['reg.read_value'](
hive='HKLM',
key='SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation',
vname='TimeZoneKeyName')['vdata']
# Some data may have null characters. We only need the first portion up to
# the first null character. See the following:
# https://github.com/saltstack/salt/issues/51940
# https://stackoverflow.com/questions/27716746/hklm-system-currentcontrolset-control-timezoneinformation-timezonekeyname-corrup
if '\0' in win_zone:
win_zone = win_zone.split('\0')[0]
return mapper.get_unix(win_zone.lower(), 'Unknown')
def get_offset():