xref: /xnu-8020.140.41/tools/lldbmacros/kauth.py (revision 27b03b360a988dfd3dfdf34262bb0042026747cc)
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"""
4from __future__ import absolute_import, print_function
5
6from builtins import range
7
8from xnu import *
9from utils import *
10
11# Macro: walkkauthcache
12@lldb_command('walkkauthcache')
13def WalkKauthCache(cmd_args=None):
14    """ Walks the bins of the kauth credential hash cache and prints out the
15        number of bins and bin usage information.
16    """
17    PrintKauthCache()
18# EndMacro: walkkauthcache
19
20def PrintKauthCache(cmd_args=None):
21    """ Routine to determine the size of the kauth cache, walk the bins
22         and print out usage information.
23    """
24    anchor = unsigned(kern.globals.kauth_cred_table_anchor)
25    table_entries = 128 # KAUTH_CRED_TABLE_SIZE
26    anchor = kern.globals.kauth_cred_table_anchor
27    print("Cred cache has: " + str(table_entries) + " buckets\n")
28    print("Number of items in each bucket ... \n")
29    for i in range(0, table_entries):
30        numinbucket = 0
31        for kauth_cred in IterateListEntry(anchor[i], 'struct ucred_rw *', "crw_link"):
32            numinbucket += 1
33            #print str(kauth_cred.cr_posix)
34            #print str(kauth_cred.cr_ref)
35        print(str(numinbucket) + "\n")
36