1 /*tests enumerating keys or values*/
5 #define MAX_KEYS_PER_ENUM 3
8 CacServerHandle
*hnd
= NULL
;
9 TALLOC_CTX
*mem_ctx
= NULL
;
19 mem_ctx
= talloc_init("regkeyenum");
21 hnd
= cac_NewServerHandle(True
);
23 printf("Enter server to connect to: ");
24 fscanf(stdin
, "%s", hnd
->server
);
26 printf("How many keys do you want to open?: ");
27 fscanf(stdin
, "%d", &num_keys
);
29 printf("How many keys per enum?: ");
30 fscanf(stdin
, "%d", &max_enum
);
32 key_names
= TALLOC_ARRAY(mem_ctx
, fstring
, num_keys
);
34 fprintf(stderr
, "No memory\n");
38 for(i
= 0; i
< num_keys
; i
++) {
39 printf("Enter key to open: ");
40 fscanf(stdin
, "%s", key_names
[i
]);
43 if(!cac_Connect(hnd
, NULL
)) {
44 fprintf(stderr
, "Could not connect to server.\n Error: %s.\n errno: %s\n", nt_errstr(hnd
->status
), strerror(errno
));
49 for(i
= 0; i
< num_keys
; i
++) {
50 printf("trying to open key %s...\n", key_names
[i
]);
52 struct RegOpenKey rok
;
55 rok
.in
.parent_key
= NULL
;
56 rok
.in
.name
= key_names
[i
];
57 rok
.in
.access
= REG_KEY_ALL
;
59 if(!cac_RegOpenKey(hnd
, mem_ctx
, &rok
)) {
60 fprintf(stderr
, "Could not open key %s\n Error: %s\n", rok
.in
.name
, nt_errstr(hnd
->status
));
64 /**enumerate all the subkeys*/
65 printf("Enumerating all subkeys:\n");
67 struct RegEnumKeys ek
;
70 ek
.in
.key
= rok
.out
.key
;
71 ek
.in
.max_keys
= max_enum
;
73 while(cac_RegEnumKeys(hnd
, mem_ctx
, &ek
)) {
76 for(j
= 0; j
< ek
.out
.num_keys
; j
++) {
77 printf(" Key name: %s\n", ek
.out
.key_names
[j
]);
81 if(CAC_OP_FAILED(hnd
->status
)) {
82 fprintf(stderr
, "Could not enumerate keys: %s\n", nt_errstr(hnd
->status
));
86 printf("closing key %s...\n", key_names
[i
]);
88 if(!cac_RegClose(hnd
, mem_ctx
, rok
.out
.key
)) {
89 fprintf(stderr
, "Could not close handle %s\n", nt_errstr(hnd
->status
));
95 talloc_destroy(mem_ctx
);