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