Univention Bugzilla – Bug 50697
wrong timezone for dhcp fallback address
Last modified: 2020-01-08 16:33:05 CET
dhclient.conf generates a fallback lease, which is supposed to be valid for 6 hours, but fails to take the timezone into account: /etc/univention/templates/files/etc/dhcp/dhclient.conf > d = datetime.fromtimestamp(time.time() + (6*3600)) # expire in six hours ... > print ' expire %d %d/%d/%d %s:%s:%s;' % ( > d.weekday(), d.year, d.month, d.day, > str(d.hour).zfill(2), str(d.minute).zfill(2), str(d.second).zfill(2)) Reading <https://docs.python.org/2/library/datetime.html#datetime.datetime.fromtimestamp>: > Return the *local* date and time corresponding to the POSIX timestamp. > If optional argument tz is None or not specified, the timestamp is converted to the platform’s *local* date and time, and the returned datetime object is naive. Reading <man:dhclient.conf(5)>: > The db-time-format option determines which of two output methods are used for printing times in leases files. > The default format provides day-and-time in *UTC*, whereas local uses a seconds-since-epoch to store the time value, and helpfully places a local timezone time in a comment on the same line. > The formats are described in detail in this manpage, within the LEASE DECLARATIONS section. So in time-zones UTC-6..UTC-12 the lease is already expired when created. Use datetime.datetime.utcfromtimestamp() instead. > d = datetime.utcnow() + timedelta(hours=6) # expire in six hours ... > print ' expire %d %d/%d/%d %02d:%02d:%02d;' % ( > d.weekday(), d.year, d.month, d.day, > d.hour, d.minute, d.second) or > print(' expire {:%w %Y/%m/%d %H:%M:%S};'.format(d))