r25598: Add missing become_root/unbecome_root around calls of add_aliases.
[Samba/gebeck_regimport.git] / examples / libmsrpc / test / reg / regkey.c
bloba90d06c6efe3886f3f7e948b2a40fea23f8c70b7
1 /*opens and closes a key*/
3 #include "libmsrpc.h"
5 int main() {
6 CacServerHandle *hnd = NULL;
7 TALLOC_CTX *mem_ctx = NULL;
9 fstring key;
11 mem_ctx = talloc_init("regkey");
13 hnd = cac_NewServerHandle(False);
15 /*allocate some memory so get_auth_data_fn can do it's magic*/
16 hnd->username = SMB_MALLOC_ARRAY(char, sizeof(fstring));
17 hnd->domain = SMB_MALLOC_ARRAY(char, sizeof(fstring));
18 hnd->netbios_name = SMB_MALLOC_ARRAY(char, sizeof(fstring));
19 hnd->password = SMB_MALLOC_ARRAY(char, sizeof(fstring));
21 hnd->server = SMB_MALLOC_ARRAY(char, sizeof(fstring));
23 printf("Enter server to connect to: ");
24 fscanf(stdin, "%s", hnd->server);
26 printf("Enter key to open: ");
27 fscanf(stdin, "%s", key);
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 struct RegConnect rc;
36 ZERO_STRUCT(rc);
38 rc.in.access = REG_KEY_ALL;
39 rc.in.root = HKEY_LOCAL_MACHINE;
41 if(!cac_RegConnect(hnd, mem_ctx, &rc)) {
42 fprintf(stderr, " Could not connect to registry. %s\n", nt_errstr(hnd->status));
43 goto done;
46 printf("trying to open key %s...\n", key);
49 struct RegOpenKey rok;
50 ZERO_STRUCT(rok);
52 rok.in.parent_key = rc.out.key;
53 rok.in.name = key;
54 rok.in.access = REG_KEY_ALL;
56 if(!cac_RegOpenKey(hnd, mem_ctx, &rok)) {
57 fprintf(stderr, "Could not open key %s\n Error: %s\n", rok.in.name, nt_errstr(hnd->status));
58 goto done;
61 if(!cac_RegClose(hnd, mem_ctx, rok.out.key)) {
62 fprintf(stderr, "Could not close handle %s\n", nt_errstr(hnd->status));
65 if(!cac_RegClose(hnd, mem_ctx, rc.out.key)) {
66 fprintf(stderr, " Could not close handle. %s\n", nt_errstr(hnd->status));
69 done:
70 cac_FreeHandle(hnd);
72 talloc_destroy(mem_ctx);
74 return 0;