From: Julien Cristau Date: Wed, 8 Jun 2016 21:41:32 +0000 (+0200) Subject: mail-big-homedirs: turns out 32 vs 64bit time_t is not the right criterion X-Git-Url: https://git.adam-barratt.org.uk/?a=commitdiff_plain;h=3ff980f9e77c0427741acd2499e3e64117886dd5;p=mirror%2Fdsa-puppet.git mail-big-homedirs: turns out 32 vs 64bit time_t is not the right criterion Some 64bit archs define __WORDSIZE_TIME64_COMPAT32 in glibc to get the same struct lastlog layout as their 32bit brethren. As far as I can tell, of the Debian architectures only ia64, arm64 and s390x don't do that. Signed-off-by: Julien Cristau --- diff --git a/modules/porterbox/files/mail-big-homedirs b/modules/porterbox/files/mail-big-homedirs index cbf49b062..9f86801f9 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,17 +123,20 @@ 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 ('ia64', '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)) try: