#include "libmsrpc.h"#include "includes.h"Go to the source code of this file.
Functions | |
| int | main (int argc, char **argv) |
|
||||||||||||
|
Definition at line 6 of file lsaenum.c. References cac_Connect(), cac_FreeHandle(), cac_LsaClosePolicy(), cac_LsaEnumSids(), cac_LsaGetNamesFromSids(), cac_LsaOpenPolicy(), cac_NewServerHandle(), errno, fprintf(), LsaGetNamesFromSids::in, LsaEnumSids::in, LsaOpenPolicy::in, nt_errstr(), LsaGetNamesFromSids::out, LsaEnumSids::out, LsaOpenPolicy::out, pol, printf(), SEC_RIGHT_MAXIMUM_ALLOWED, _CACSERVERHANDLE::server, sid_string_static(), _CACSERVERHANDLE::status, strerror, talloc_destroy, talloc_free(), talloc_init(), True, and ZERO_STRUCT. 00006 { 00007 00008 CacServerHandle *hnd = NULL; 00009 TALLOC_CTX *mem_ctx = NULL; 00010 00011 POLICY_HND *pol = NULL; 00012 00013 int i; 00014 int max_sids; 00015 00016 mem_ctx = talloc_init("lsaenum"); 00017 00018 hnd = cac_NewServerHandle(True); 00019 00020 printf("Enter server to connect to: "); 00021 fscanf(stdin, "%s", hnd->server); 00022 00023 if(!cac_Connect(hnd, NULL)) { 00024 fprintf(stderr, "Could not connect to server.\n Error: %s.\n errno: %s\n", nt_errstr(hnd->status), strerror(errno)); 00025 cac_FreeHandle(hnd); 00026 exit(-1); 00027 } 00028 00029 printf("How many sids do you want to grab at a time? "); 00030 fscanf(stdin, "%d", &max_sids); 00031 00032 struct LsaOpenPolicy lop; 00033 ZERO_STRUCT(lop); 00034 00035 lop.in.access = SEC_RIGHT_MAXIMUM_ALLOWED; 00036 lop.in.security_qos = True; 00037 00038 00039 if(!cac_LsaOpenPolicy(hnd, mem_ctx, &lop)) { 00040 fprintf(stderr, "Could not open policy handle.\n Error: %s\n", nt_errstr(hnd->status)); 00041 cac_FreeHandle(hnd); 00042 exit(-1); 00043 } 00044 00045 pol = lop.out.pol; 00046 00047 00048 struct LsaEnumSids esop; 00049 ZERO_STRUCT(esop); 00050 esop.in.pol = pol; 00051 /*grab a couple at a time to demonstrate multiple calls*/ 00052 esop.in.pref_max_sids = max_sids; 00053 00054 printf("Attempting to fetch SIDs %d at a time\n", esop.in.pref_max_sids); 00055 00056 while(cac_LsaEnumSids(hnd, mem_ctx, &esop)) { 00057 00058 printf("\nEnumerated %d sids: \n", esop.out.num_sids); 00059 for(i = 0; i < esop.out.num_sids; i++) { 00060 printf(" SID: %s\n", sid_string_static(&esop.out.sids[i])); 00061 } 00062 00063 printf("Resolving names\n"); 00064 00065 struct LsaGetNamesFromSids gnop; 00066 ZERO_STRUCT(gnop); 00067 00068 gnop.in.pol = pol; 00069 gnop.in.sids = esop.out.sids; 00070 gnop.in.num_sids = esop.out.num_sids; 00071 00072 if(!cac_LsaGetNamesFromSids(hnd, mem_ctx, &gnop)) { 00073 fprintf(stderr, "Could not resolve names.\n Error: %s\n", nt_errstr(hnd->status)); 00074 goto done; 00075 } 00076 00077 printf("\nResolved %d names: \n", gnop.out.num_found); 00078 for(i = 0; i < gnop.out.num_found; i++) { 00079 printf(" SID: %s\n", sid_string_static(&gnop.out.sids[i].sid)); 00080 printf(" Name: %s\n", gnop.out.sids[i].name); 00081 } 00082 00083 /*clean up a little*/ 00084 talloc_free(gnop.out.sids); 00085 } 00086 00087 done: 00088 if(!cac_LsaClosePolicy(hnd, mem_ctx, pol)) { 00089 fprintf(stderr, "Could not close policy handle.\n Error: %s\n", nt_errstr(hnd->status)); 00090 } 00091 00092 cac_FreeHandle(hnd); 00093 talloc_destroy(mem_ctx); 00094 00095 return 0; 00096 }
|