6 int main(int argc
, char **argv
) {
8 CacServerHandle
*hnd
= NULL
;
9 TALLOC_CTX
*mem_ctx
= NULL
;
11 POLICY_HND
*pol
= NULL
;
16 mem_ctx
= talloc_init("lsaenum");
18 hnd
= cac_NewServerHandle(True
);
20 printf("Enter server to connect to: ");
21 fscanf(stdin
, "%s", hnd
->server
);
23 if(!cac_Connect(hnd
, NULL
)) {
24 fprintf(stderr
, "Could not connect to server.\n Error: %s.\n errno: %s\n", nt_errstr(hnd
->status
), strerror(errno
));
29 printf("How many sids do you want to grab at a time? ");
30 fscanf(stdin
, "%d", &max_sids
);
32 struct LsaOpenPolicy lop
;
35 lop
.in
.access
= SEC_RIGHT_MAXIMUM_ALLOWED
;
36 lop
.in
.security_qos
= True
;
39 if(!cac_LsaOpenPolicy(hnd
, mem_ctx
, &lop
)) {
40 fprintf(stderr
, "Could not open policy handle.\n Error: %s\n", nt_errstr(hnd
->status
));
48 struct LsaEnumSids esop
;
51 /*grab a couple at a time to demonstrate multiple calls*/
52 esop
.in
.pref_max_sids
= max_sids
;
54 printf("Attempting to fetch SIDs %d at a time\n", esop
.in
.pref_max_sids
);
56 while(cac_LsaEnumSids(hnd
, mem_ctx
, &esop
)) {
58 printf("\nEnumerated %d sids: \n", esop
.out
.num_sids
);
59 for(i
= 0; i
< esop
.out
.num_sids
; i
++) {
60 printf(" SID: %s\n", sid_string_static(&esop
.out
.sids
[i
]));
63 printf("Resolving names\n");
65 struct LsaGetNamesFromSids gnop
;
69 gnop
.in
.sids
= esop
.out
.sids
;
70 gnop
.in
.num_sids
= esop
.out
.num_sids
;
72 if(!cac_LsaGetNamesFromSids(hnd
, mem_ctx
, &gnop
)) {
73 fprintf(stderr
, "Could not resolve names.\n Error: %s\n", nt_errstr(hnd
->status
));
77 printf("\nResolved %d names: \n", gnop
.out
.num_found
);
78 for(i
= 0; i
< gnop
.out
.num_found
; i
++) {
79 printf(" SID: %s\n", sid_string_static(&gnop
.out
.sids
[i
].sid
));
80 printf(" Name: %s\n", gnop
.out
.sids
[i
].name
);
84 talloc_free(gnop
.out
.sids
);
88 if(!cac_LsaClosePolicy(hnd
, mem_ctx
, pol
)) {
89 fprintf(stderr
, "Could not close policy handle.\n Error: %s\n", nt_errstr(hnd
->status
));
93 talloc_destroy(mem_ctx
);