1 | /*enumerates privileges*/
|
---|
2 |
|
---|
3 | #include "libmsrpc.h"
|
---|
4 | #include "includes.h"
|
---|
5 |
|
---|
6 | #define MAX_STRING_LEN 50;
|
---|
7 |
|
---|
8 | int main() {
|
---|
9 | CacServerHandle *hnd = NULL;
|
---|
10 | TALLOC_CTX *mem_ctx = NULL;
|
---|
11 | POLICY_HND *lsa_pol = NULL;
|
---|
12 |
|
---|
13 | int i;
|
---|
14 |
|
---|
15 | mem_ctx = talloc_init("lsatrust");
|
---|
16 |
|
---|
17 | hnd = cac_NewServerHandle(True);
|
---|
18 |
|
---|
19 | printf("Server: ");
|
---|
20 | fscanf(stdin, "%s", hnd->server);
|
---|
21 |
|
---|
22 | printf("Connecting to server....\n");
|
---|
23 |
|
---|
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);
|
---|
28 | }
|
---|
29 |
|
---|
30 | printf("Connected to server\n");
|
---|
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 | lsa_pol = lop.out.pol;
|
---|
46 |
|
---|
47 | printf("Enumerating Privileges\n");
|
---|
48 |
|
---|
49 | struct LsaEnumPrivileges ep;
|
---|
50 | ZERO_STRUCT(ep);
|
---|
51 |
|
---|
52 | ep.in.pol = lsa_pol;
|
---|
53 | ep.in.pref_max_privs = 50;
|
---|
54 |
|
---|
55 | while(cac_LsaEnumPrivileges(hnd, mem_ctx, &ep)) {
|
---|
56 | printf(" Enumerated %d privileges\n", ep.out.num_privs);
|
---|
57 |
|
---|
58 | for(i = 0; i < ep.out.num_privs; i++) {
|
---|
59 | printf("\"%s\"\n", ep.out.priv_names[i]);
|
---|
60 | }
|
---|
61 |
|
---|
62 | printf("\n");
|
---|
63 | }
|
---|
64 |
|
---|
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;
|
---|
68 | }
|
---|
69 |
|
---|
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));
|
---|
73 | }
|
---|
74 |
|
---|
75 | cac_FreeHandle(hnd);
|
---|
76 | talloc_destroy(mem_ctx);
|
---|
77 |
|
---|
78 | return 0;
|
---|
79 | }
|
---|