1 /*tests deleting a key or value*/
6 int main(int argc, char **argv) {
7 CacServerHandle *hnd = NULL;
8 TALLOC_CTX *mem_ctx = NULL;
13 mem_ctx = talloc_init("regdelete");
15 hnd = cac_NewServerHandle(True);
17 cac_SetAuthDataFn(hnd, cactest_GetAuthDataFn);
19 cac_parse_cmd_line(argc, argv, hnd);
21 if(!cac_Connect(hnd, NULL)) {
22 fprintf(stderr, "Could not connect to server %s. Error: %s\n", hnd->server, nt_errstr(hnd->status));
26 printf("enter key to open: \n");
27 cactest_readline(stdin, tmp);
29 struct RegOpenKey rok;
32 rok.in.name = talloc_strdup(mem_ctx, tmp);
33 rok.in.access = REG_KEY_ALL;
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));
40 printf("getting version (just for testing\n");
42 struct RegGetVersion rgv;
45 rgv.in.key = rok.out.key;
47 if(!cac_RegGetVersion(hnd, mem_ctx, &rgv))
48 fprintf(stderr, "Could not get version. Error: %s\n", nt_errstr(hnd->status));
50 printf("Version: %d\n", rgv.out.version);
53 while(input == 'v' || input == 'k') {
54 printf("Delete [v]alue [k]ey or [q]uit: ");
59 printf("Value to delete: ");
60 cactest_readline(stdin, tmp);
62 struct RegDeleteValue rdv;
65 rdv.in.parent_key = rok.out.key;
66 rdv.in.name = talloc_strdup(mem_ctx, tmp);
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));
73 printf("Key to delete: ");
74 cactest_readline(stdin, tmp);
76 struct RegDeleteKey rdk;
79 rdk.in.parent_key = rok.out.key;
80 rdk.in.name = talloc_strdup(mem_ctx, tmp);
82 printf("delete recursively? [y/n]: ");
83 cactest_readline(stdin, tmp);
85 rdk.in.recursive = (tmp[0] == 'y') ? True : False;
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));
93 cac_RegClose(hnd, mem_ctx, rok.out.key);
97 talloc_destroy(mem_ctx);