1 | /*tests deleting a key or value*/
|
---|
2 |
|
---|
3 | #include "libmsrpc.h"
|
---|
4 | #include "test_util.h"
|
---|
5 |
|
---|
6 | int main(int argc, char **argv) {
|
---|
7 | CacServerHandle *hnd = NULL;
|
---|
8 | TALLOC_CTX *mem_ctx = NULL;
|
---|
9 |
|
---|
10 | fstring tmp;
|
---|
11 | char input = 'v';
|
---|
12 |
|
---|
13 | mem_ctx = talloc_init("regdelete");
|
---|
14 |
|
---|
15 | hnd = cac_NewServerHandle(True);
|
---|
16 |
|
---|
17 | cac_SetAuthDataFn(hnd, cactest_GetAuthDataFn);
|
---|
18 |
|
---|
19 | cac_parse_cmd_line(argc, argv, hnd);
|
---|
20 |
|
---|
21 | if(!cac_Connect(hnd, NULL)) {
|
---|
22 | fprintf(stderr, "Could not connect to server %s. Error: %s\n", hnd->server, nt_errstr(hnd->status));
|
---|
23 | exit(-1);
|
---|
24 | }
|
---|
25 |
|
---|
26 | printf("enter key to open: \n");
|
---|
27 | cactest_readline(stdin, tmp);
|
---|
28 |
|
---|
29 | struct RegOpenKey rok;
|
---|
30 | ZERO_STRUCT(rok);
|
---|
31 |
|
---|
32 | rok.in.name = talloc_strdup(mem_ctx, tmp);
|
---|
33 | rok.in.access = REG_KEY_ALL;
|
---|
34 |
|
---|
35 | if(!cac_RegOpenKey(hnd, mem_ctx, &rok)) {
|
---|
36 | fprintf(stderr, "Could not open key %s. Error %s\n", rok.in.name, nt_errstr(hnd->status));
|
---|
37 | exit(-1);
|
---|
38 | }
|
---|
39 |
|
---|
40 | printf("getting version (just for testing\n");
|
---|
41 |
|
---|
42 | struct RegGetVersion rgv;
|
---|
43 | ZERO_STRUCT(rgv);
|
---|
44 |
|
---|
45 | rgv.in.key = rok.out.key;
|
---|
46 |
|
---|
47 | if(!cac_RegGetVersion(hnd, mem_ctx, &rgv))
|
---|
48 | fprintf(stderr, "Could not get version. Error: %s\n", nt_errstr(hnd->status));
|
---|
49 | else
|
---|
50 | printf("Version: %d\n", rgv.out.version);
|
---|
51 |
|
---|
52 |
|
---|
53 | while(input == 'v' || input == 'k') {
|
---|
54 | printf("Delete [v]alue [k]ey or [q]uit: ");
|
---|
55 | scanf("%c", &input);
|
---|
56 |
|
---|
57 | switch(input) {
|
---|
58 | case 'v':
|
---|
59 | printf("Value to delete: ");
|
---|
60 | cactest_readline(stdin, tmp);
|
---|
61 |
|
---|
62 | struct RegDeleteValue rdv;
|
---|
63 | ZERO_STRUCT(rdv);
|
---|
64 |
|
---|
65 | rdv.in.parent_key = rok.out.key;
|
---|
66 | rdv.in.name = talloc_strdup(mem_ctx, tmp);
|
---|
67 |
|
---|
68 | if(!cac_RegDeleteValue(hnd, mem_ctx, &rdv))
|
---|
69 | fprintf(stderr, "Could not delete value %s. Error: %s\n", rdv.in.name, nt_errstr(hnd->status));
|
---|
70 |
|
---|
71 | break;
|
---|
72 | case 'k':
|
---|
73 | printf("Key to delete: ");
|
---|
74 | cactest_readline(stdin, tmp);
|
---|
75 |
|
---|
76 | struct RegDeleteKey rdk;
|
---|
77 | ZERO_STRUCT(rdk);
|
---|
78 |
|
---|
79 | rdk.in.parent_key = rok.out.key;
|
---|
80 | rdk.in.name = talloc_strdup(mem_ctx, tmp);
|
---|
81 |
|
---|
82 | printf("delete recursively? [y/n]: ");
|
---|
83 | cactest_readline(stdin, tmp);
|
---|
84 |
|
---|
85 | rdk.in.recursive = (tmp[0] == 'y') ? True : False;
|
---|
86 |
|
---|
87 | if(!cac_RegDeleteKey(hnd, mem_ctx, &rdk))
|
---|
88 | fprintf(stderr, "Could not delete key %s. Error %s\n", rdk.in.name, nt_errstr(hnd->status));
|
---|
89 |
|
---|
90 | break;
|
---|
91 | }
|
---|
92 | }
|
---|
93 | cac_RegClose(hnd, mem_ctx, rok.out.key);
|
---|
94 |
|
---|
95 | cac_FreeHandle(hnd);
|
---|
96 |
|
---|
97 | talloc_destroy(mem_ctx);
|
---|
98 |
|
---|
99 | return 0;
|
---|
100 | }
|
---|
101 |
|
---|
102 |
|
---|