1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
/*opens and closes a registry handle*/
#include "libmsrpc.h"
int main() {
CacServerHandle *hnd = NULL;
TALLOC_CTX *mem_ctx = NULL;
POLICY_HND **keys = NULL;
char roots[4][50] = { {CAC_HKCR}, {CAC_HKLM}, {CAC_HKU}, {CAC_HKPD} };
int i;
mem_ctx = talloc_init("regopen");
hnd = cac_NewServerHandle(True);
keys = TALLOC_ARRAY(mem_ctx, POLICY_HND *, 4);
printf("Enter server to connect to: ");
fscanf(stdin, "%s", hnd->server);
if(!cac_Connect(hnd, NULL)) {
fprintf(stderr, "Could not connect to server.\n Error: %s.\n errno: %s\n", nt_errstr(hnd->status), strerror(errno));
cac_FreeHandle(hnd);
exit(-1);
}
struct RegConnect rc;
ZERO_STRUCT(rc);
rc.in.access = SEC_RIGHT_MAXIMUM_ALLOWED;
for(i = 0; i < 4; i++) {
printf("opening: %s\n", roots[i]);
rc.in.root = roots[i];
if(!cac_RegConnect(hnd, mem_ctx, &rc)) {
fprintf(stderr, " Could not connect to registry. %s\n", nt_errstr(hnd->status));
continue;
}
keys[i] = rc.out.key;
}
for(i = 3; i >= 0; i--) {
if(keys[i] == NULL)
continue;
printf("closing: %s\n", roots[i]);
if(!cac_RegClose(hnd, mem_ctx, keys[i])) {
fprintf(stderr, " Could not close handle. %s\n", nt_errstr(hnd->status));
}
}
cac_FreeHandle(hnd);
talloc_destroy(mem_ctx);
return 0;
}
|