1 | /*tests cac_RegOpenKey()*/
|
---|
2 |
|
---|
3 | #include "libmsrpc.h"
|
---|
4 |
|
---|
5 | int main() {
|
---|
6 | CacServerHandle *hnd = NULL;
|
---|
7 | TALLOC_CTX *mem_ctx = NULL;
|
---|
8 |
|
---|
9 | int num_keys;
|
---|
10 | int i;
|
---|
11 |
|
---|
12 | fstring *key_names;
|
---|
13 |
|
---|
14 | mem_ctx = talloc_init("regopenkey");
|
---|
15 |
|
---|
16 | hnd = cac_NewServerHandle(True);
|
---|
17 |
|
---|
18 | printf("Enter server to connect to: ");
|
---|
19 | fscanf(stdin, "%s", hnd->server);
|
---|
20 |
|
---|
21 | printf("How many keys do you want to open?: ");
|
---|
22 | fscanf(stdin, "%d", &num_keys);
|
---|
23 |
|
---|
24 | key_names = TALLOC_ARRAY(mem_ctx, fstring , num_keys);
|
---|
25 | if(!key_names) {
|
---|
26 | fprintf(stderr, "No memory\n");
|
---|
27 | exit(-1);
|
---|
28 | }
|
---|
29 |
|
---|
30 | for(i = 0; i < num_keys; i++) {
|
---|
31 | printf("Enter key to open: ");
|
---|
32 | fscanf(stdin, "%s", key_names[i]);
|
---|
33 | }
|
---|
34 |
|
---|
35 | if(!cac_Connect(hnd, NULL)) {
|
---|
36 | fprintf(stderr, "Could not connect to server.\n Error: %s.\n errno: %s\n", nt_errstr(hnd->status), strerror(errno));
|
---|
37 | cac_FreeHandle(hnd);
|
---|
38 | exit(-1);
|
---|
39 | }
|
---|
40 |
|
---|
41 | for(i = 0; i < num_keys; i++) {
|
---|
42 | printf("trying to open key %s...\n", key_names[i]);
|
---|
43 |
|
---|
44 | struct RegOpenKey rok;
|
---|
45 | ZERO_STRUCT(rok);
|
---|
46 |
|
---|
47 | rok.in.parent_key = NULL;
|
---|
48 | rok.in.name = key_names[i];
|
---|
49 | rok.in.access = REG_KEY_ALL;
|
---|
50 |
|
---|
51 | if(!cac_RegOpenKey(hnd, mem_ctx, &rok)) {
|
---|
52 | fprintf(stderr, "Could not open key %s\n Error: %s\n", rok.in.name, nt_errstr(hnd->status));
|
---|
53 | continue;
|
---|
54 | }
|
---|
55 |
|
---|
56 | printf("closing key %s...\n", key_names[i]);
|
---|
57 |
|
---|
58 | if(!cac_RegClose(hnd, mem_ctx, rok.out.key)) {
|
---|
59 | fprintf(stderr, "Could not close handle %s\n", nt_errstr(hnd->status));
|
---|
60 | }
|
---|
61 | }
|
---|
62 |
|
---|
63 | cac_FreeHandle(hnd);
|
---|
64 |
|
---|
65 | talloc_destroy(mem_ctx);
|
---|
66 |
|
---|
67 | return 0;
|
---|
68 |
|
---|
69 | }
|
---|