X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=modules%2Fporterbox%2Ffiles%2Fmail-big-homedirs;h=f5225b5c8982fc61666aa01d1fb68a50b77ff752;hb=51f0b72b7a31e222dd1fff325e0a0cbe20fad466;hp=b4c36636ec4355b3d9cec02d98d6ae91aac7131b;hpb=c50a0d2e86bcaf645c4011f4dc59b9e7e98a2bd9;p=mirror%2Fdsa-puppet.git diff --git a/modules/porterbox/files/mail-big-homedirs b/modules/porterbox/files/mail-big-homedirs index b4c36636e..f5225b5c8 100755 --- a/modules/porterbox/files/mail-big-homedirs +++ b/modules/porterbox/files/mail-big-homedirs @@ -38,7 +38,6 @@ import pwd import subprocess import struct import time -import sysconfig import StringIO # avoid base64 encoding for utf-8 @@ -124,19 +123,25 @@ class LastlogTimes(dict): def __init__(self): record_size_32 = struct.calcsize(self.LASTLOG_STRUCT_32) record_size_64 = struct.calcsize(self.LASTLOG_STRUCT_64) - if sysconfig.get_config_var('SIZEOF_TIME_T') == 4 - self.LASTLOG_STRUCT = self.LASTLOG_STRUCT_32 - record_size = record_size_32 - elif sysconfig.get_config_var('SIZEOF_TIME_T') == 8: + # some 64bit arches have 32bit-compatible lastlog structures, others don't, + # in apparently incoherent ways, so hardcode a list... + if platform.machine() in ('aarch64', 's390x'): self.LASTLOG_STRUCT = self.LASTLOG_STRUCT_64 record_size = record_size_64 else: - raise RuntimeError('Unknown architecture, sizeof time_t is weird (%d)' % (sysconfig.get_config_var('SIZEOF_TIME_T'),)) + self.LASTLOG_STRUCT = self.LASTLOG_STRUCT_32 + record_size = record_size_32 with open('/var/log/lastlog', 'r') as fp: uid = -1 # there is one record per uid in lastlog for record in iter(lambda: fp.read(record_size), ''): + if len(record) != record_size: + raise RuntimeError('lastlog has unexpected size, read %d instead of %d' + % (len(record), record_size)) uid += 1 # so keep incrementing uid for each record read lastlog_time, _, _ = list(struct.unpack(self.LASTLOG_STRUCT, record)) + if lastlog_time < 0: + raise RuntimeError('unexpected last login time %d for user %s' + % (lastlog_time, pwd.getpwuid(uid).pw_name)) try: self[pwd.getpwuid(uid).pw_name] = lastlog_time except KeyError: