Fix incorrect args passed to timezone.set_hwclock

On Gentoo, we should check the value passed in to timezone.set_hwclock
and only allow 'UTC' or 'localtime' for argument. If incorrect value is
passed in, it could subsequently fry the important config file.

There is another closely related issue on Gentoo. The value to set
'clock' variable in the config file is either 'UTC' or 'local'. In case
of localtime arg, we should convert the value of 'localtime' to 'local'
when setting that 'clock' variable.
This commit is contained in:
Jεan Sacren 2016-06-02 00:30:12 -06:00 committed by rallytime
parent 8a566ff4b9
commit a41146730a

View file

@ -400,6 +400,12 @@ def set_hwclock(clock):
elif clock == 'localtime':
__salt__['file.sed']('/etc/default/rcS', '^UTC=.*', 'UTC=no')
elif 'Gentoo' in __grains__['os_family']:
if clock not in ('UTC', 'localtime'):
raise SaltInvocationError(
'Only \'UTC\' and \'localtime\' are allowed'
)
if clock.__eq__('localtime'):
clock = 'local'
__salt__['file.sed'](
'/etc/conf.d/hwclock', '^clock=.*', 'clock="{0}"'.format(clock))