'Parse wtmp and extract the last logon time.'

def ParseWtmp(self):

    users = {}
    wtmp_struct_size = UtmpStruct.GetSize()
    for filename in sorted(os.listdir('/var/log')):
        if filename.startswith('wtmp'):
            try:
                wtmp = open(os.path.join('/var/log', filename), 'rb').read()
            except IOError:
                continue
            for offset in xrange(0, len(wtmp), wtmp_struct_size):
                try:
                    record = UtmpStruct(wtmp[offset:(offset + wtmp_struct_size)])
                except RuntimeError:
                    break
                if (record.ut_type != 7):
                    continue
                try:
                    if (users[record.ut_user] < record.tv_sec):
                        users[record.ut_user] = record.tv_sec
                except KeyError:
                    users[record.ut_user] = record.tv_sec
    return users
