r25598: Add missing become_root/unbecome_root around calls of add_aliases.
[Samba/gebeck_regimport.git] / examples / libmsrpc / test / reg / regvalenum.c
blob9778f4e2b3c253e838d1974cd417b83fee01a227
1 /*tests enumerating registry values*/
3 #include "libmsrpc.h"
4 #include "test_util.h"
6 #define MAX_KEYS_PER_ENUM 3
9 int main(int argc, char **argv) {
10 CacServerHandle *hnd = NULL;
11 TALLOC_CTX *mem_ctx = NULL;
13 int num_keys;
15 int max_enum;
17 fstring *key_names;
19 int i;
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));
31 cac_FreeHandle(hnd);
32 exit(-1);
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);
42 if(!key_names) {
43 fprintf(stderr, "No memory\n");
44 exit(-1);
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;
56 ZERO_STRUCT(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));
64 continue;
67 /**enumerate all the subkeys*/
68 printf("Enumerating all values:\n");
70 struct RegEnumValues rev;
71 ZERO_STRUCT(rev);
73 rev.in.key = rok.out.key;
74 rev.in.max_values = max_enum;
76 while(cac_RegEnumValues(hnd, mem_ctx, &rev)) {
77 int j;
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));
87 continue;
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));
97 cac_FreeHandle(hnd);
99 talloc_destroy(mem_ctx);
101 return 0;