source: branches/samba-3.0/examples/libmsrpc/test/reg/regvalenum.c

Last change on this file was 1, checked in by Paul Smedley, 18 years ago

Initial code import

File size: 2.4 KB
Line 
1/*tests enumerating registry values*/
2
3#include "libmsrpc.h"
4#include "test_util.h"
5
6#define MAX_KEYS_PER_ENUM 3
7
8
9int main(int argc, char **argv) {
10 CacServerHandle *hnd = NULL;
11 TALLOC_CTX *mem_ctx = NULL;
12
13 int num_keys;
14
15 int max_enum;
16
17 fstring *key_names;
18
19 int i;
20
21 mem_ctx = talloc_init("regvalenum");
22
23 hnd = cac_NewServerHandle(True);
24
25 cac_parse_cmd_line(argc, argv, hnd);
26
27 cac_SetAuthDataFn(hnd, cactest_GetAuthDataFn);
28
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);
33 }
34
35 printf("How many keys do you want to open?: ");
36 fscanf(stdin, "%d", &num_keys);
37
38 printf("How many values per enum?: ");
39 fscanf(stdin, "%d", &max_enum);
40
41 key_names = TALLOC_ARRAY(mem_ctx, fstring , num_keys);
42 if(!key_names) {
43 fprintf(stderr, "No memory\n");
44 exit(-1);
45 }
46
47 for(i = 0; i < num_keys; i++) {
48 printf("Enter key to open: ");
49 fscanf(stdin, "%s", key_names[i]);
50 }
51
52 for(i = 0; i < num_keys; i++) {
53 printf("trying to open key %s...\n", key_names[i]);
54
55 struct RegOpenKey rok;
56 ZERO_STRUCT(rok);
57
58 rok.in.parent_key = NULL;
59 rok.in.name = key_names[i];
60 rok.in.access = REG_KEY_ALL;
61
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;
65 }
66
67 /**enumerate all the subkeys*/
68 printf("Enumerating all values:\n");
69
70 struct RegEnumValues rev;
71 ZERO_STRUCT(rev);
72
73 rev.in.key = rok.out.key;
74 rev.in.max_values = max_enum;
75
76 while(cac_RegEnumValues(hnd, mem_ctx, &rev)) {
77 int j;
78
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]);
82 }
83 }
84
85 if(CAC_OP_FAILED(hnd->status)) {
86 fprintf(stderr, "Could not enumerate values: %s\n", nt_errstr(hnd->status));
87 continue;
88 }
89
90 printf("closing key %s...\n", key_names[i]);
91
92 if(!cac_RegClose(hnd, mem_ctx, rok.out.key)) {
93 fprintf(stderr, "Could not close handle %s\n", nt_errstr(hnd->status));
94 }
95 }
96
97 cac_FreeHandle(hnd);
98
99 talloc_destroy(mem_ctx);
100
101 return 0;
102
103}
Note: See TracBrowser for help on using the repository browser.