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