1 /*tests enumerating registry values*/
6 #define MAX_KEYS_PER_ENUM 3
9 int main(int argc
, char **argv
) {
10 CacServerHandle
*hnd
= NULL
;
11 TALLOC_CTX
*mem_ctx
= NULL
;
21 mem_ctx
= talloc_init("regvalenum");
23 hnd
= cac_NewServerHandle(True
);
25 cac_parse_cmd_line(argc
, argv
, hnd
);
27 cac_SetAuthDataFn(hnd
, cactest_GetAuthDataFn
);
29 if(!cac_Connect(hnd
, NULL
)) {
30 fprintf(stderr
, "Could not connect to server.\n Error: %s.\n errno: %s\n", nt_errstr(hnd
->status
), strerror(errno
));
35 printf("How many keys do you want to open?: ");
36 fscanf(stdin
, "%d", &num_keys
);
38 printf("How many values per enum?: ");
39 fscanf(stdin
, "%d", &max_enum
);
41 key_names
= TALLOC_ARRAY(mem_ctx
, fstring
, num_keys
);
43 fprintf(stderr
, "No memory\n");
47 for(i
= 0; i
< num_keys
; i
++) {
48 printf("Enter key to open: ");
49 fscanf(stdin
, "%s", key_names
[i
]);
52 for(i
= 0; i
< num_keys
; i
++) {
53 printf("trying to open key %s...\n", key_names
[i
]);
55 struct RegOpenKey rok
;
58 rok
.in
.parent_key
= NULL
;
59 rok
.in
.name
= key_names
[i
];
60 rok
.in
.access
= REG_KEY_ALL
;
62 if(!cac_RegOpenKey(hnd
, mem_ctx
, &rok
)) {
63 fprintf(stderr
, "Could not open key %s\n Error: %s\n", rok
.in
.name
, nt_errstr(hnd
->status
));
67 /**enumerate all the subkeys*/
68 printf("Enumerating all values:\n");
70 struct RegEnumValues rev
;
73 rev
.in
.key
= rok
.out
.key
;
74 rev
.in
.max_values
= max_enum
;
76 while(cac_RegEnumValues(hnd
, mem_ctx
, &rev
)) {
79 for(j
= 0; j
< rev
.out
.num_values
; j
++) {
80 printf(" Value name: %s\n", rev
.out
.value_names
[j
]);
81 print_value(rev
.out
.types
[j
], rev
.out
.values
[j
]);
85 if(CAC_OP_FAILED(hnd
->status
)) {
86 fprintf(stderr
, "Could not enumerate values: %s\n", nt_errstr(hnd
->status
));
90 printf("closing key %s...\n", key_names
[i
]);
92 if(!cac_RegClose(hnd
, mem_ctx
, rok
.out
.key
)) {
93 fprintf(stderr
, "Could not close handle %s\n", nt_errstr(hnd
->status
));
99 talloc_destroy(mem_ctx
);