1/*enumerates SIDs*/ 2 3#include "libmsrpc.h" 4#include "includes.h" 5 6int main(int argc, char **argv) { 7 8 CacServerHandle *hnd = NULL; 9 TALLOC_CTX *mem_ctx = NULL; 10 11 POLICY_HND *pol = NULL; 12 13 int i; 14 int max_sids; 15 16 mem_ctx = talloc_init("lsaenum"); 17 18 hnd = cac_NewServerHandle(True); 19 20 printf("Enter server to connect to: "); 21 fscanf(stdin, "%s", hnd->server); 22 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)); 25 cac_FreeHandle(hnd); 26 exit(-1); 27 } 28 29 printf("How many sids do you want to grab at a time? "); 30 fscanf(stdin, "%d", &max_sids); 31 32 struct LsaOpenPolicy lop; 33 ZERO_STRUCT(lop); 34 35 lop.in.access = SEC_RIGHT_MAXIMUM_ALLOWED; 36 lop.in.security_qos = True; 37 38 39 if(!cac_LsaOpenPolicy(hnd, mem_ctx, &lop)) { 40 fprintf(stderr, "Could not open policy handle.\n Error: %s\n", nt_errstr(hnd->status)); 41 cac_FreeHandle(hnd); 42 exit(-1); 43 } 44 45 pol = lop.out.pol; 46 47 48 struct LsaEnumSids esop; 49 ZERO_STRUCT(esop); 50 esop.in.pol = pol; 51 /*grab a couple at a time to demonstrate multiple calls*/ 52 esop.in.pref_max_sids = max_sids; 53 54 printf("Attempting to fetch SIDs %d at a time\n", esop.in.pref_max_sids); 55 56 while(cac_LsaEnumSids(hnd, mem_ctx, &esop)) { 57 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])); 61 } 62 63 printf("Resolving names\n"); 64 65 struct LsaGetNamesFromSids gnop; 66 ZERO_STRUCT(gnop); 67 68 gnop.in.pol = pol; 69 gnop.in.sids = esop.out.sids; 70 gnop.in.num_sids = esop.out.num_sids; 71 72 if(!cac_LsaGetNamesFromSids(hnd, mem_ctx, &gnop)) { 73 fprintf(stderr, "Could not resolve names.\n Error: %s\n", nt_errstr(hnd->status)); 74 goto done; 75 } 76 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); 81 } 82 83 /*clean up a little*/ 84 talloc_free(gnop.out.sids); 85 } 86 87done: 88 if(!cac_LsaClosePolicy(hnd, mem_ctx, pol)) { 89 fprintf(stderr, "Could not close policy handle.\n Error: %s\n", nt_errstr(hnd->status)); 90 } 91 92 cac_FreeHandle(hnd); 93 talloc_destroy(mem_ctx); 94 95 return 0; 96} 97