1 /*opens and closes a key*/
6 CacServerHandle
*hnd
= NULL
;
7 TALLOC_CTX
*mem_ctx
= NULL
;
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
));
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
));
46 printf("trying to open key %s...\n", key
);
49 struct RegOpenKey rok
;
52 rok
.in
.parent_key
= rc
.out
.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
));
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
));
72 talloc_destroy(mem_ctx
);