r25598: Add missing become_root/unbecome_root around calls of add_aliases.
[Samba/gebeck_regimport.git] / examples / libmsrpc / test / reg / regopenkey.c
blob732da17ccf3c80088c335ea9f5f6d8db0c60b9d3
1 /*tests cac_RegOpenKey()*/
3 #include "libmsrpc.h"
5 int main() {
6 CacServerHandle *hnd = NULL;
7 TALLOC_CTX *mem_ctx = NULL;
9 int num_keys;
10 int i;
12 fstring *key_names;
14 mem_ctx = talloc_init("regopenkey");
16 hnd = cac_NewServerHandle(True);
18 printf("Enter server to connect to: ");
19 fscanf(stdin, "%s", hnd->server);
21 printf("How many keys do you want to open?: ");
22 fscanf(stdin, "%d", &num_keys);
24 key_names = TALLOC_ARRAY(mem_ctx, fstring , num_keys);
25 if(!key_names) {
26 fprintf(stderr, "No memory\n");
27 exit(-1);
30 for(i = 0; i < num_keys; i++) {
31 printf("Enter key to open: ");
32 fscanf(stdin, "%s", key_names[i]);
35 if(!cac_Connect(hnd, NULL)) {
36 fprintf(stderr, "Could not connect to server.\n Error: %s.\n errno: %s\n", nt_errstr(hnd->status), strerror(errno));
37 cac_FreeHandle(hnd);
38 exit(-1);
41 for(i = 0; i < num_keys; i++) {
42 printf("trying to open key %s...\n", key_names[i]);
44 struct RegOpenKey rok;
45 ZERO_STRUCT(rok);
47 rok.in.parent_key = NULL;
48 rok.in.name = key_names[i];
49 rok.in.access = REG_KEY_ALL;
51 if(!cac_RegOpenKey(hnd, mem_ctx, &rok)) {
52 fprintf(stderr, "Could not open key %s\n Error: %s\n", rok.in.name, nt_errstr(hnd->status));
53 continue;
56 printf("closing key %s...\n", key_names[i]);
58 if(!cac_RegClose(hnd, mem_ctx, rok.out.key)) {
59 fprintf(stderr, "Could not close handle %s\n", nt_errstr(hnd->status));
63 cac_FreeHandle(hnd);
65 talloc_destroy(mem_ctx);
67 return 0;