]>
git.saurik.com Git - apple/xnu.git/blob - tools/cred_dump_creds.c
1 /* quick and dirty hack to grab all credentials in the cred hash table
2 * from kernel via sysctl.
3 * sysctl is only defined if xnu is built with DEBUG_CRED defined.
14 #include <sys/types.h>
15 #include <sys/sysctl.h>
16 #include <bsm/audit.h>
18 /* bad! this is replicated in kern_credential.c. make sure they stay in sync!
19 * Or better yet have commone header file?
23 uint32_t cr_ref
; /* reference count */
24 uid_t cr_uid
; /* effective user id */
25 uid_t cr_ruid
; /* real user id */
26 uid_t cr_svuid
; /* saved user id */
27 short cr_ngroups
; /* number of groups in advisory list */
28 gid_t cr_groups
[NGROUPS
]; /* advisory group list */
29 gid_t cr_rgid
; /* real group id */
30 gid_t cr_svgid
; /* saved group id */
31 uid_t cr_gmuid
; /* UID for group membership purposes */
32 struct auditinfo_addr cr_audit
; /* user auditing data */
33 uint32_t cr_label
; /* MACF label */
34 int cr_flags
; /* flags on credential */
36 typedef struct debug_ucred debug_ucred
;
38 void dump_cred_hash_table( debug_ucred
* credp
, size_t buf_size
);
39 void dump_cred( debug_ucred
* credp
);
42 main( int argc
, char *argv
[] )
46 char *my_bufferp
= NULL
;
48 /* get size of buffer we will need */
50 err
= sysctlbyname( "kern.dump_creds", NULL
, &len
, NULL
, 0 );
52 printf( "sysctl failed \n" );
53 printf( "\terrno %d - \"%s\" \n", errno
, strerror( errno
));
57 /* get a buffer for our credentials. need some spare room since table could have grown */
58 my_bufferp
= malloc( len
);
59 if (my_bufferp
== NULL
) {
60 printf( "malloc error %d - \"%s\" \n", errno
, strerror( errno
));
63 err
= sysctlbyname( "kern.dump_creds", my_bufferp
, &len
, NULL
, 0 );
65 printf( "sysctl 2 failed \n" );
66 printf( "\terrno %d - \"%s\" \n", errno
, strerror( errno
));
69 dump_cred_hash_table((debug_ucred
*)my_bufferp
, len
);
75 dump_cred_hash_table( debug_ucred
* credp
, size_t buf_size
)
77 int i
, my_count
= (buf_size
/ sizeof(debug_ucred
));
79 printf("\n\t dumping credential hash table - total creds %d \n",
81 for (i
= 0; i
< my_count
; i
++) {
90 dump_cred( debug_ucred
* credp
)
93 printf("%p ", credp
->credp
);
94 printf("%lu ", credp
->cr_ref
);
95 printf("%d ", credp
->cr_uid
);
96 printf("%d ", credp
->cr_ruid
);
97 printf("%d ", credp
->cr_svuid
);
98 printf("%d g[", credp
->cr_ngroups
);
99 for (i
= 0; i
< credp
->cr_ngroups
; i
++) {
100 printf("%d", credp
->cr_groups
[i
]);
101 if ((i
+ 1) < credp
->cr_ngroups
) {
105 printf("] %d ", credp
->cr_rgid
);
106 printf("%d ", credp
->cr_svgid
);
107 printf("%d ", credp
->cr_gmuid
);
108 printf("a[%d ", credp
->cr_audit
.ai_auid
);
109 printf("%d ", credp
->cr_audit
.ai_mask
.am_success
);
110 printf("%d ", credp
->cr_audit
.ai_mask
.am_failure
);
111 printf("%d ", credp
->cr_audit
.ai_termid
.at_port
);
112 printf("%d ", credp
->cr_audit
.ai_termid
.at_addr
[0]);
113 printf("%d ", credp
->cr_audit
.ai_asid
);
115 printf("%p ", credp
->cr_label
);
116 printf("0x%08x \n", credp
->cr_flags
);