1 | /*opens and closes a key*/
|
---|
2 |
|
---|
3 | #include "libmsrpc.h"
|
---|
4 |
|
---|
5 | int main() {
|
---|
6 | CacServerHandle *hnd = NULL;
|
---|
7 | TALLOC_CTX *mem_ctx = NULL;
|
---|
8 |
|
---|
9 | fstring key;
|
---|
10 |
|
---|
11 | mem_ctx = talloc_init("regkey");
|
---|
12 |
|
---|
13 | hnd = cac_NewServerHandle(False);
|
---|
14 |
|
---|
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));
|
---|
20 |
|
---|
21 | hnd->server = SMB_MALLOC_ARRAY(char, sizeof(fstring));
|
---|
22 |
|
---|
23 | printf("Enter server to connect to: ");
|
---|
24 | fscanf(stdin, "%s", hnd->server);
|
---|
25 |
|
---|
26 | printf("Enter key to open: ");
|
---|
27 | fscanf(stdin, "%s", key);
|
---|
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 | struct RegConnect rc;
|
---|
36 | ZERO_STRUCT(rc);
|
---|
37 |
|
---|
38 | rc.in.access = REG_KEY_ALL;
|
---|
39 | rc.in.root = HKEY_LOCAL_MACHINE;
|
---|
40 |
|
---|
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;
|
---|
44 | }
|
---|
45 |
|
---|
46 | printf("trying to open key %s...\n", key);
|
---|
47 |
|
---|
48 |
|
---|
49 | struct RegOpenKey rok;
|
---|
50 | ZERO_STRUCT(rok);
|
---|
51 |
|
---|
52 | rok.in.parent_key = rc.out.key;
|
---|
53 | rok.in.name = key;
|
---|
54 | rok.in.access = REG_KEY_ALL;
|
---|
55 |
|
---|
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;
|
---|
59 | }
|
---|
60 |
|
---|
61 | if(!cac_RegClose(hnd, mem_ctx, rok.out.key)) {
|
---|
62 | fprintf(stderr, "Could not close handle %s\n", nt_errstr(hnd->status));
|
---|
63 | }
|
---|
64 |
|
---|
65 | if(!cac_RegClose(hnd, mem_ctx, rc.out.key)) {
|
---|
66 | fprintf(stderr, " Could not close handle. %s\n", nt_errstr(hnd->status));
|
---|
67 | }
|
---|
68 |
|
---|
69 | done:
|
---|
70 | cac_FreeHandle(hnd);
|
---|
71 |
|
---|
72 | talloc_destroy(mem_ctx);
|
---|
73 |
|
---|
74 | return 0;
|
---|
75 |
|
---|
76 | }
|
---|