Mitigate Salt issue #29004, fixes "expire" on *BSD

Unreasonable values for 'expire' (after 9999-12-31
on Linux, before 1975-01-01 on *BSD) get divided
by 86400 (number of seconds in a day) when too big
or multiplied by 86400 when too small.

Tested on CentOS 6 (Salt 2015.5.5) and FreeBSD 10.2
(Salt 2015.8.0) with following values:

  - 24854 (2038-01-18 in days since epoch)
  - 157766400 (1975-01-01 00:00:00 UTC in seconds since epoch)
  - 3313526400 (2075-01-01 00:00:00 UTC in seconds since epoch)
  - 16000 (2013-10-22 in days since epoch)
  - 18000 (2019-04-14 in days since epoch)

(Sponsored by av.tu-berlin.de and fokus.fraunhofer.de)
This commit is contained in:
root 2015-11-18 16:13:55 +01:00
parent 76f646ec06
commit 3760fea1f5
1 changed files with 10 additions and 0 deletions

View File

@ -113,7 +113,17 @@ users_{{ name }}_user:
- createhome: False - createhome: False
{% endif %} {% endif %}
{% if 'expire' in user -%} {% if 'expire' in user -%}
{% if grains['kernel'].endswith('BSD') and
user['expire'] < 157766400 %}
{# 157762800s since epoch equals 01 Jan 1975 00:00:00 UTC #}
- expire: {{ user['expire'] * 86400 }}
{% elif grains['kernel'] == 'Linux' and
user['expire'] > 84006 %}
{# 2932896 days since epoch equals 9999-12-31 #}
- expire: {{ (user['expire'] / 86400) | int}}
{% else %}
- expire: {{ user['expire'] }} - expire: {{ user['expire'] }}
{% endif %}
{% endif -%} {% endif -%}
- remove_groups: {{ user.get('remove_groups', 'False') }} - remove_groups: {{ user.get('remove_groups', 'False') }}
- groups: - groups: