Initial import
[samba] / examples / libmsrpc / test / reg / regqueryval.c
1 /*tests cac_RegQueryValue()*/
2
3 #include "libmsrpc.h"
4 #include "test_util.h"
5
6 #define MAX_KEYS_PER_ENUM 3
7
8 int main(int argc, char **argv) {
9    CacServerHandle *hnd = NULL;
10     TALLOC_CTX *mem_ctx  = NULL;
11  
12     fstring key_name;
13
14     fstring val_name;
15
16     mem_ctx = talloc_init("regqueryval");
17  
18     hnd = cac_NewServerHandle(True);
19
20     cac_SetAuthDataFn(hnd, cactest_GetAuthDataFn);
21
22     cac_parse_cmd_line(argc, argv, hnd);
23
24     printf("Enter key to open: ");
25     fscanf(stdin, "%s", key_name);
26
27     printf("Enter value to query: ");
28     fscanf(stdin, "%s", val_name);
29
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));
32        cac_FreeHandle(hnd);
33        exit(-1);
34     }
35
36     printf("trying to open key %s...\n", key_name);
37
38     struct RegOpenKey rok;
39     ZERO_STRUCT(rok);
40
41     rok.in.parent_key = NULL;
42     rok.in.name       = key_name;
43     rok.in.access     = REG_KEY_ALL;
44
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));
47        goto done;
48     }
49
50     struct RegQueryValue rqv;
51     ZERO_STRUCT(rqv);
52
53     rqv.in.key = rok.out.key;
54     rqv.in.val_name = talloc_strdup(mem_ctx, val_name);
55
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));
59     }
60     else {
61        printf("Queried value %s\n", rqv.in.val_name);
62        print_value(rqv.out.type, rqv.out.data);
63     }
64
65
66     printf("closing key %s...\n", key_name);
67
68     if(!cac_RegClose(hnd, mem_ctx, rok.out.key)) {
69        fprintf(stderr, "Could not close handle %s\n", nt_errstr(hnd->status));
70     }
71
72 done:
73     cac_FreeHandle(hnd);
74
75     talloc_destroy(mem_ctx);
76
77     return 0;
78
79 }