Bug 50697 - wrong timezone for dhcp fallback address
wrong timezone for dhcp fallback address
Status: NEW
Product: UCS
Classification: Unclassified
Component: DHCP
UCS 4.4
Other Linux
: P5 normal (vote)
: ---
Assigned To: UCS maintainers
UCS maintainers
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2020-01-08 16:33 CET by Philipp Hahn
Modified: 2020-01-08 16:33 CET (History)
0 users

See Also:
What kind of report is it?: Bug Report
What type of bug is this?: 4: Minor Usability: Impairs usability in secondary scenarios
Who will be affected by this bug?: 1: Will affect a very few installed domains
How will those affected feel about the bug?: 3: A User would likely not purchase the product
User Pain: 0.069
Enterprise Customer affected?:
School Customer affected?:
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number:
Bug group (optional):
Max CVSS v3 score:
hahn: Patch_Available+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Philipp Hahn univentionstaff 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))