xref: /xnu-8019.80.24/tools/lldbmacros/kauth.py (revision a325d9c4a84054e40bbe985afedcb50ab80993ea)
1""" Please make sure you read the README file COMPLETELY BEFORE reading anything below.
2    It is very critical that you read coding guidelines in Section E in README file.
3"""
4
5from xnu import *
6from utils import *
7
8# Macro: walkkauthcache
9@lldb_command('walkkauthcache')
10def WalkKauthCache(cmd_args=None):
11    """ Walks the bins of the kauth credential hash cache and prints out the
12        number of bins and bin usage information.
13    """
14    PrintKauthCache()
15# EndMacro: walkkauthcache
16
17def PrintKauthCache(cmd_args=None):
18    """ Routine to determine the size of the kauth cache, walk the bins
19         and print out usage information.
20    """
21    anchor = unsigned(kern.globals.kauth_cred_table_anchor)
22    table_entries = 128 # KAUTH_CRED_TABLE_SIZE
23    anchor = kern.globals.kauth_cred_table_anchor
24    print "Cred cache has: " + str(table_entries) + " buckets\n"
25    print "Number of items in each bucket ... \n"
26    for i in range(0, table_entries):
27        numinbucket = 0
28        for kauth_cred in IterateListEntry(anchor[i], 'struct ucred_rw *', "crw_link"):
29            numinbucket += 1
30            #print str(kauth_cred.cr_posix)
31            #print str(kauth_cred.cr_ref)
32        print str(numinbucket) + "\n"
33