Bug 47197 - wrong value of unixtime in users/user causes traceback
wrong value of unixtime in users/user causes traceback
Status: RESOLVED DUPLICATE of bug 47170
Product: UCS
Classification: Unclassified
Component: UMC - Users
UCS 4.3
Other Linux
: P5 normal (vote)
: ---
Assigned To: UMC maintainers
UMC maintainers
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2018-06-14 17:19 CEST by Nico Stöckigt
Modified: 2018-06-15 11:15 CEST (History)
3 users (show)

See Also:
What kind of report is it?: Bug Report
What type of bug is this?: 5: Major Usability: Impairs usability in key scenarios
Who will be affected by this bug?: 2: Will only affect a few installed domains
How will those affected feel about the bug?: 5: Blocking further progress on the daily work
User Pain: 0.286
Enterprise Customer affected?: Yes
School Customer affected?:
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number: 2018061421001416
Bug group (optional):
Max CVSS v3 score:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nico Stöckigt univentionstaff 2018-06-14 17:19:38 CEST
When trying to create a Group-Report the following error occurs:

----------------------------------------------------------------------
"/usr/lib/pymodules/python2.7/univention/admin/handlers/users/user.py",
line 1434, in unmapWindowsFiletime
    return time.strftime('%Y%m%d%H%M%SZ', time.gmtime(unixtime))
ValueError: year out of range
----------------------------------------------------------------------

According to Py/Doc the '%' before the 'Z' (timezone) is missing. While grep-ing through git I found:

----------------------------------------------------------------------
base/univention-pam/lock-user:          HOME=/ python -m univention.lib.account lock --dn "$user_dn" --lock-time "$(date --utc '+%Y%m%d%H%M%SZ')"
management/univention-directory-logger/directory_logger.py:             timestruct = time.strptime(timestamp, "%Y%m%d%H%M%SZ")
management/univention-directory-manager-modules/modules/univention/admin/handlers/users/user.py:                unixtime = time.strptime(old, '%Y%m%d%H%M%SZ')
management/univention-directory-manager-modules/modules/univention/admin/handlers/users/user.py:                return time.strftime('%Y%m%d%H%M%SZ', time.gmtime(unixtime))
management/univention-directory-manager-modules/modules/univention/admin/handlers/users/user.py:                
                locked_unixtime = long(calendar.timegm(time.strptime(locked_timestamp, '%Y%m%d%H%M%SZ')))
management/univention-directory-manager-modules/python-lib/account.py:          python -m univention.lib.account lock --dn "$user_dn" --lock-time "$(date --utc '+%Y%m%d%H%M%SZ')"
management/univention-directory-manager-modules/univention-migrate-users-to-ucs4.3:                             
        expiration_date = time.strftime("%Y%m%d%H%M%SZ", user['krb5ValidEnd'][0])
management/univention-management-console-module-diagnostic/umc/python/diagnostic/plugins/02_certificate_check.py:
                       11: '%Y%m%d%HZ', 13: '%Y%m%d%H%MZ', 15: '%Y%m%d%H%M%SZ',
services/univention-support-info/univention-support-info:timeString = time.strftime('%Y-%m-%d_%H-%M-%SZ', time.gmtime())
test/ucs-test/tests/01_base/47faillog-ssh-smb-krb:python -m univention.lib.account lock --dn "$(user_dn "$NAME")" --lock-time "$(date --utc '+%Y%m%d%H%M%SZ')" || fail_test 110 "Could not manually lock user account!"
test/ucs-test/tests/61_udm-users/100_test_users.py:             locktime = time.strftime("%Y%m%d%H%M%SZ", time.gmtime())
test/ucs-test/tests/61_udm-users/25_script_lock_expired_accounts:                               locktime = time.strftime("%Y%m%d%H%M%SZ", time.gmtime())
test/ucs-test/tests/61_udm-users/37_user_modification_set_deactivation_and_locked:                      locktime = time.strftime("%Y%m%d%H%M%SZ", time.gmtime())
test/ucs-test/tests/61_udm-users/37_user_modification_set_deactivation_and_locked:                      locktime = time.strftime("%Y%m%d%H%M%SZ", time.gmtime())
virtualization/univention-virtual-machine-manager-daemon/src/univention/uvmm/node.py:   now = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())
----------------------------------------------------------------------
Comment 1 Arvid Requate univentionstaff 2018-06-14 19:19:18 CEST
The Z is an actual "Z", not a template macro for time.strftime. Like so:

>>> import time
>>> time.strftime('%Y%m%d%H%M%SZ', time.gmtime(time.time()))
'20180301162009Z'

So my guess is that he value of unixtime is wrong somehow. Like so:

>>> time.strftime('%Y%m%d%H%M%SZ', time.gmtime(-999999999999999))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: year out of range
Comment 2 Arvid Requate univentionstaff 2018-06-14 19:21:56 CEST
The full python traceback would be useful to see in which context this is called and where the value comes from.
Comment 3 Stefan Gohmann univentionstaff 2018-06-15 09:18:58 CEST
I can reproduce it:

root@master431:~# ldapmodify -x -D cn=admin,$(ucr get ldap/base) -y /etc/ldap.secret -f user-set-sambaBadPasswordTime-to-1467969484.ldif 
modifying entry "uid=edl,cn=users,dc=deadlock43,dc=intranet"

root@master431:~# udm users/user list 
Traceback (most recent call last):
  File "/usr/share/univention-directory-manager-tools/univention-cli-server", line 218, in doit
    output = univention.admincli.admin.doit(arglist)
  File "/usr/lib/pymodules/python2.7/univention/admincli/admin.py", line 398, in doit
    out = _doit(arglist)
  File "/usr/lib/pymodules/python2.7/univention/admincli/admin.py", line 987, in _doit
    for object in univention.admin.modules.lookup(module, co, lo, scope='sub', superordinate=superordinate, base=position.getDn(), filter=filter):
  File "/usr/lib/pymodules/python2.7/univention/admin/modules.py", line 732, in lookup
    tmpres = module.lookup(co, lo, filter, base=base, superordinate=superordinate, scope=scope, unique=unique, required=required, timeout=timeout, sizelimit=sizelimit)
  File "/usr/lib/pymodules/python2.7/univention/admin/handlers/__init__.py", line 1404, in lookup
    result.append(cls(co, lo, None, dn=dn, superordinate=superordinate, attributes=attrs))
  File "/usr/lib/pymodules/python2.7/univention/admin/handlers/users/user.py", line 1520, in __init__
    univention.admin.handlers.simpleLdap.__init__(self, co, lo, position, dn, superordinate, attributes=attributes)
  File "/usr/lib/pymodules/python2.7/univention/admin/handlers/__init__.py", line 230, in __init__
    oldinfo = self.mapping.unmapValues(self.oldattr)
  File "/usr/lib/pymodules/python2.7/univention/admin/mapping.py", line 321, in unmapValues
    info = mapDict(self, oldattr)
  File "/usr/lib/pymodules/python2.7/univention/admin/mapping.py", line 377, in mapDict
    v = mapping.unmapValue(key, value)
  File "/usr/lib/pymodules/python2.7/univention/admin/mapping.py", line 317, in unmapValue
    return unmap_value(value) if unmap_value else value
  File "/usr/lib/pymodules/python2.7/univention/admin/handlers/users/user.py", line 1433, in unmapWindowsFiletime
    return time.strftime('%Y%m%d%H%M%SZ', time.gmtime(unixtime))
ValueError: year out of range
root@master431:~# ldapmodify -x -D cn=admin,$(ucr get ldap/base) -y /etc/ldap.secret -f user-set-sambaBadPasswordTime-to-0.ldif 
modifying entry "uid=edl,cn=users,dc=deadlock43,dc=intranet"

root@master431:~# udm users/user list --filter uid=edl | grep -i lock
DN: uid=edl,cn=users,dc=deadlock43,dc=intranet
  groups: cn=Domain Users,cn=groups,dc=deadlock43,dc=intranet
  locked: 0
  lockedTime: 0
  primaryGroup: cn=Domain Users,cn=groups,dc=deadlock43,dc=intranet
  unlock: None
  unlockTime: None
root@master431:~# 

root@master431:~# tail user-set-sambaBadPasswordTime-to-0.ldif 
dn: uid=edl,cn=users,dc=deadlock43,dc=intranet
changetype: modify
replace: sambaBadPasswordTime
sambaBadPasswordTime: 0

root@master431:~# tail user-set-sambaBadPasswordTime-to-1467969484.ldif 
dn: uid=edl,cn=users,dc=deadlock43,dc=intranet
changetype: modify
replace: sambaBadPasswordTime
sambaBadPasswordTime: 1467969484

root@master431:~#
Comment 4 Florian Best univentionstaff 2018-06-15 11:15:41 CEST

*** This bug has been marked as a duplicate of bug 47170 ***