r25598: Add missing become_root/unbecome_root around calls of add_aliases.
[Samba/gebeck_regimport.git] / examples / libmsrpc / test / lsa / lsaenumprivs.c
blob8b5c9deca6ba849b602f7eeadb034f6e19ad9eb3
1 /*enumerates privileges*/
3 #include "libmsrpc.h"
4 #include "includes.h"
6 #define MAX_STRING_LEN 50;
8 int main() {
9 CacServerHandle *hnd = NULL;
10 TALLOC_CTX *mem_ctx = NULL;
11 POLICY_HND *lsa_pol = NULL;
13 int i;
15 mem_ctx = talloc_init("lsatrust");
17 hnd = cac_NewServerHandle(True);
19 printf("Server: ");
20 fscanf(stdin, "%s", hnd->server);
22 printf("Connecting to server....\n");
24 if(!cac_Connect(hnd, NULL)) {
25 fprintf(stderr, "Could not connect to server.\n Error: %s\n errno %s\n", nt_errstr(hnd->status), strerror(errno));
26 cac_FreeHandle(hnd);
27 exit(-1);
30 printf("Connected to server\n");
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 lsa_pol = lop.out.pol;
47 printf("Enumerating Privileges\n");
49 struct LsaEnumPrivileges ep;
50 ZERO_STRUCT(ep);
52 ep.in.pol = lsa_pol;
53 ep.in.pref_max_privs = 50;
55 while(cac_LsaEnumPrivileges(hnd, mem_ctx, &ep)) {
56 printf(" Enumerated %d privileges\n", ep.out.num_privs);
58 for(i = 0; i < ep.out.num_privs; i++) {
59 printf("\"%s\"\n", ep.out.priv_names[i]);
62 printf("\n");
65 if(CAC_OP_FAILED(hnd->status)) {
66 fprintf(stderr, "Error while enumerating privileges.\n Error: %s\n", nt_errstr(hnd->status));
67 goto done;
70 done:
71 if(!cac_LsaClosePolicy(hnd, mem_ctx, lsa_pol)) {
72 fprintf(stderr, "Could not close policy handle.\n Error: %s\n", nt_errstr(hnd->status));
75 cac_FreeHandle(hnd);
76 talloc_destroy(mem_ctx);
78 return 0;