r25598: Add missing become_root/unbecome_root around calls of add_aliases.
[Samba/gebeck_regimport.git] / examples / libmsrpc / test / lsa / lsaenum.c
blobd4ad4f73aa809941f09368a60ba5cd980d7159df
1 /*enumerates SIDs*/
3 #include "libmsrpc.h"
4 #include "includes.h"
6 int main(int argc, char **argv) {
8 CacServerHandle *hnd = NULL;
9 TALLOC_CTX *mem_ctx = NULL;
11 POLICY_HND *pol = NULL;
13 int i;
14 int max_sids;
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));
25 cac_FreeHandle(hnd);
26 exit(-1);
29 printf("How many sids do you want to grab at a time? ");
30 fscanf(stdin, "%d", &max_sids);
32 struct LsaOpenPolicy lop;
33 ZERO_STRUCT(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));
41 cac_FreeHandle(hnd);
42 exit(-1);
45 pol = lop.out.pol;
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;
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;
66 ZERO_STRUCT(gnop);
68 gnop.in.pol = pol;
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));
74 goto done;
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);
83 /*clean up a little*/
84 talloc_free(gnop.out.sids);
87 done:
88 if(!cac_LsaClosePolicy(hnd, mem_ctx, pol)) {
89 fprintf(stderr, "Could not close policy handle.\n Error: %s\n", nt_errstr(hnd->status));
92 cac_FreeHandle(hnd);
93 talloc_destroy(mem_ctx);
95 return 0;