1 /*tests cac_RegQueryValue()*/
6 #define MAX_KEYS_PER_ENUM 3
8 int main(int argc, char **argv) {
9 CacServerHandle *hnd = NULL;
10 TALLOC_CTX *mem_ctx = NULL;
16 mem_ctx = talloc_init("regqueryval");
18 hnd = cac_NewServerHandle(True);
20 cac_SetAuthDataFn(hnd, cactest_GetAuthDataFn);
22 cac_parse_cmd_line(argc, argv, hnd);
24 printf("Enter key to open: ");
25 fscanf(stdin, "%s", key_name);
27 printf("Enter value to query: ");
28 fscanf(stdin, "%s", val_name);
30 if(!cac_Connect(hnd, NULL)) {
31 fprintf(stderr, "Could not connect to server.\n Error: %s.\n errno: %s\n", nt_errstr(hnd->status), strerror(errno));
36 printf("trying to open key %s...\n", key_name);
38 struct RegOpenKey rok;
41 rok.in.parent_key = NULL;
42 rok.in.name = key_name;
43 rok.in.access = REG_KEY_ALL;
45 if(!cac_RegOpenKey(hnd, mem_ctx, &rok)) {
46 fprintf(stderr, "Could not open key %s\n Error: %s\n", rok.in.name, nt_errstr(hnd->status));
50 struct RegQueryValue rqv;
53 rqv.in.key = rok.out.key;
54 rqv.in.val_name = talloc_strdup(mem_ctx, val_name);
56 printf("querying value %s...\n", rqv.in.val_name);
57 if(!cac_RegQueryValue(hnd, mem_ctx, &rqv)) {
58 fprintf(stderr, "Could not query value. Error: %s\n", nt_errstr(hnd->status));
61 printf("Queried value %s\n", rqv.in.val_name);
62 print_value(rqv.out.type, rqv.out.data);
66 printf("closing key %s...\n", key_name);
68 if(!cac_RegClose(hnd, mem_ctx, rok.out.key)) {
69 fprintf(stderr, "Could not close handle %s\n", nt_errstr(hnd->status));
75 talloc_destroy(mem_ctx);