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